Bug fix: when -S or -M was given the ragel version number was not emitted,
[external/ragel.git] / ragel / parsedata.cpp
index 206ad50..0fe69f7 100644 (file)
@@ -31,6 +31,7 @@
 #include "parsetree.h"
 #include "mergesort.h"
 #include "xmlcodegen.h"
+#include "version.h"
 
 using namespace std;
 
@@ -441,7 +442,6 @@ ParseData::ParseData( char *fileName, char *sectionName,
        fileName(fileName),
        sectionName(sectionName),
        sectionLoc(sectionLoc),
-       errorCount(0),
        curActionOrd(0),
        curPriorOrd(0),
        rootName(0),
@@ -850,38 +850,17 @@ void ParseData::initGraphDict( )
 /* Set the alphabet type. If the types are not valid returns false. */
 bool ParseData::setAlphType( char *s1, char *s2 )
 {
-       bool valid = false;
-       for ( int i = 0; i < hostLang->numHostTypes; i++ ) {
-               if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && 
-                               hostLang->hostTypes[i].data2 != 0 && 
-                               strcmp( s2, hostLang->hostTypes[i].data2 ) == 0 )
-               {
-                       valid = true;
-                       userAlphType = hostLang->hostTypes + i;
-                       break;
-               }
-       }
-
+       userAlphType = findAlphType( s1, s2 );
        alphTypeSet = true;
-       return valid;
+       return userAlphType != 0;
 }
 
 /* Set the alphabet type. If the types are not valid returns false. */
 bool ParseData::setAlphType( char *s1 )
 {
-       bool valid = false;
-       for ( int i = 0; i < hostLang->numHostTypes; i++ ) {
-               if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && 
-                               hostLang->hostTypes[i].data2 == 0 )
-               {
-                       valid = true;
-                       userAlphType = hostLang->hostTypes + i;
-                       break;
-               }
-       }
-
+       userAlphType = findAlphType( s1 );
        alphTypeSet = true;
-       return valid;
+       return userAlphType != 0;
 }
 
 bool ParseData::setVariable( char *var, InlineList *inlineList )
@@ -1460,11 +1439,11 @@ void terminateAllParsers( )
 void writeLanguage( std::ostream &out )
 {
        out << " lang=\"";
-       switch ( hostLangType ) {
-               case CCode:    out << "C"; break;
-               case DCode:    out << "D"; break;
-               case JavaCode: out << "Java"; break;
-               case RubyCode: out << "Ruby"; break;
+       switch ( hostLang->lang ) {
+               case HostLang::C:    out << "C"; break;
+               case HostLang::D:    out << "D"; break;
+               case HostLang::Java: out << "Java"; break;
+               case HostLang::Ruby: out << "Ruby"; break;
        }
        out << "\"";
        
@@ -1481,7 +1460,7 @@ void writeMachines( std::ostream &out, std::string hostData, char *inputFileName
                }
 
                if ( gblErrorCount == 0 ) {
-                       out << "<ragel filename=\"" << inputFileName << "\"";
+                       out << "<ragel version=\"" VERSION "\" filename=\"" << inputFileName << "\"";
                        writeLanguage( out );
                        out << ">\n";
                        for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
@@ -1522,7 +1501,7 @@ void writeMachines( std::ostream &out, std::string hostData, char *inputFileName
                        /* Section/Machine to emit was found. Prepare and emit it. */
                        parseData->prepareMachineGen( graphDictEl );
                        if ( gblErrorCount == 0 ) {
-                               out << "<ragel filename=\"" << inputFileName << "\"";
+                               out << "<ragel version=\"" VERSION "\" filename=\"" << inputFileName << "\"";
                                writeLanguage( out );
                                out << ">\n";
                                parseData->generateXML( out );