Got XML output working.
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 22 Mar 2009 01:26:32 +0000 (01:26 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 22 Mar 2009 01:26:32 +0000 (01:26 +0000)
git-svn-id: http://svn.complang.org/ragel/trunk@753 052ea7fc-9027-0410-9066-f65837a77df0

ragel/inputdata.cpp
ragel/inputdata.h
ragel/main.cpp
ragel/ragel.h
ragel/rlparse.kh
ragel/xmlcodegen.cpp

index 9e464d3..29d02eb 100644 (file)
@@ -87,7 +87,7 @@ void InputData::csharpDefaultFileName( const char *inputFile )
 
 void InputData::makeOutputStream()
 {
-       if ( ! generateDot ) {
+       if ( ! generateDot && ! generateXML ) {
                switch ( hostLang->lang ) {
                        case HostLang::C:
                        case HostLang::D:
@@ -183,9 +183,8 @@ void InputData::prepareMachineGen()
 
 void InputData::generateReduced()
 {
-       if ( generateDot ) {
+       if ( generateDot )
                dotGenParser->pd->generateReduced( *this );
-       }
        else {
                for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
                        ParseData *pd = parser->value->pd;
@@ -211,9 +210,11 @@ void InputData::terminateAllParsers( )
 
 void InputData::writeOutput()
 {
-       if ( generateDot ) {
-               static_cast<GraphvizDotGen*>(dotGenParser->pd->cgd)->writeDotFile();
+       if ( generateXML ) {
+               writeXML( *outStream );
        }
+       else if ( generateDot )
+               static_cast<GraphvizDotGen*>(dotGenParser->pd->cgd)->writeDotFile();
        else {
                for ( InputItemList::Iter ii = inputItems; ii.lte(); ii++ ) {
                        if ( ii->type == InputItem::Write ) {
index f072bb7..a2c9ae8 100644 (file)
@@ -96,7 +96,7 @@ struct InputData
        void csharpDefaultFileName( const char *inputFile );
 
        void writeLanguage( std::ostream &out );
-       void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName );
+       void writeXML( std::ostream &out );
 };
 
 #endif
index 3a5e3df..28f26c0 100644 (file)
@@ -77,7 +77,7 @@ bool machineSpecFound = false;
 bool wantDupsRemoved = true;
 
 bool printStatistics = false;
-bool frontendOnly = false;
+bool generateXML = false;
 bool generateDot = false;
 
 /* Target language and output style. */
@@ -230,7 +230,7 @@ void processArgs( int argc, const char **argv, InputData &id )
                                break;
 
                        case 'x':
-                               frontendOnly = true;
+                               generateXML = true;
                                break;
 
                        /* Output. */
@@ -476,10 +476,12 @@ void process( InputData &id )
        id.makeOutputStream();
 
        /* Generates the reduced machine, which we use to write output. */
-       id.generateReduced();
+       if ( !generateXML ) {
+               id.generateReduced();
 
-       if ( gblErrorCount > 0 )
-               exit(1);
+               if ( gblErrorCount > 0 )
+                       exit(1);
+       }
        
        /*
         * From this point on we should not be reporting any errors.
@@ -491,10 +493,6 @@ void process( InputData &id )
        /* Close the input and the intermediate file. */
        delete inFile;
 
-       /* Bail on above error. */
-       if ( gblErrorCount > 0 )
-               exit(1);
-
        /* If writing to a file, delete the ostream, causing it to flush.
         * Standard out is flushed automatically. */
        if ( id.outputFileName != 0 ) {
@@ -530,13 +528,6 @@ int main( int argc, const char **argv )
 
        processArgs( argc, argv, id );
 
-       /* If -M or -S are given and we're not generating a dot file then invoke
-        * the frontend. These options are not useful with code generators. */
-       if ( machineName != 0 || machineSpec != 0 ) {
-               if ( !generateDot )
-                       frontendOnly = true;
-       }
-
        /* Require an input file. If we use standard in then we won't have a file
         * name on which to base the output. */
        if ( id.inputFileName == 0 )
index bfcda67..2f4d6ff 100644 (file)
@@ -74,6 +74,7 @@ extern const char *machineSpec, *machineName;
 extern bool printStatistics;
 extern bool wantDupsRemoved;
 extern bool generateDot;
+extern bool generateXML;
 extern RubyImplEnum rubyImpl;
 
 /* Error reporting format. */
index e5ce618..4fbf082 100644 (file)
@@ -132,6 +132,8 @@ struct Parser
 
        Vector<bool> exportContext;
        IncludeHistory includeHistory;
+
+       Parser *prev, *next;
 };
 
 %% write token_defs;
index 91ee3f7..08bfc20 100644 (file)
@@ -1411,67 +1411,17 @@ void InputData::writeLanguage( std::ostream &out )
        out << "\"";
 }
 
-void InputData::writeMachines( std::ostream &out, std::string hostData, const char *inputFileName )
-{
-       if ( machineSpec == 0 && machineName == 0 ) {
-               /* No machine spec or machine name given. Generate everything. */
-               for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
-                       ParseData *pd = parser->value->pd;
-                       if ( pd->instanceList.length() > 0 )
-                               pd->prepareMachineGen( 0 );
-               }
+void InputData::writeXML( std::ostream &out )
+{
+       out << "<ragel version=\"" VERSION "\" filename=\"" << inputFileName << "\"";
+       writeLanguage( out );
+       out << ">\n";
 
-               if ( gblErrorCount == 0 ) {
-                       out << "<ragel version=\"" VERSION "\" filename=\"" << inputFileName << "\"";
-                       writeLanguage( out );
-                       out << ">\n";
-                       for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
-                               ParseData *pd = parser->value->pd;
-                               if ( pd->instanceList.length() > 0 )
-                                       pd->generateXML( out );
-                       }
-                       out << hostData;
-                       out << "</ragel>\n";
-               }
+       for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
+               ParseData *pd = parser->value->pd;
+               if ( pd->instanceList.length() > 0 )
+                       pd->generateXML( *outStream );
        }
-       else if ( parserDict.length() > 0 ) {
-               /* There is either a machine spec or machine name given. */
-               ParseData *parseData = 0;
-               GraphDictEl *graphDictEl = 0;
-
-               /* Traverse the sections, break out when we find a section/machine
-                * that matches the one specified. */
-               for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
-                       ParseData *checkPd = parser->value->pd;
-                       if ( machineSpec == 0 || strcmp( checkPd->sectionName, machineSpec ) == 0 ) {
-                               GraphDictEl *checkGdEl = 0;
-                               if ( machineName == 0 || (checkGdEl = 
-                                               checkPd->graphDict.find( machineName )) != 0 )
-                               {
-                                       /* Have a machine spec and/or machine name that matches
-                                        * the -M/-S options. */
-                                       parseData = checkPd;
-                                       graphDictEl = checkGdEl;
-                                       break;
-                               }
-                       }
-               }
 
-               if ( parseData == 0 )
-                       error() << "could not locate machine specified with -S and/or -M" << endl;
-               else {
-                       /* Section/Machine to emit was found. Prepare and emit it. */
-                       parseData->prepareMachineGen( graphDictEl );
-                       if ( gblErrorCount == 0 ) {
-                               out << "<ragel version=\"" VERSION "\" filename=\"" << inputFileName << "\"";
-                               writeLanguage( out );
-                               out << ">\n";
-                               parseData->generateXML( out );
-                               out << hostData;
-                               out << "</ragel>\n";
-                       }
-               }
-       }
+       out << "</ragel>\n";
 }
-
-