The XML parser and scanner are now created in ragel/main.cpp. These structures
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Mon, 1 Sep 2008 22:50:27 +0000 (22:50 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Mon, 1 Sep 2008 22:50:27 +0000 (22:50 +0000)
can now be made accessible during the writing of the XML file, allowing
incremental bypassing of the XML file.

git-svn-id: http://svn.complang.org/ragel/trunk@467 052ea7fc-9027-0410-9066-f65837a77df0

ragel/main.cpp
ragel/ragel.h
redfsm/xmlparse.kh
redfsm/xmlscan.rl

index 1e11cef..5261ff1 100644 (file)
@@ -441,7 +441,7 @@ void processArgs( int argc, const char **argv, const char *&inputFileName )
        }
 }
 
-int frontend( const char *inputFileName, const char *intermed )
+void process( const char *inputFileName, const char *intermed )
 {
        /* Open the input file for reading. */
        assert( inputFileName != 0 );
@@ -461,30 +461,77 @@ int frontend( const char *inputFileName, const char *intermed )
 
        /* Finished, final check for errors.. */
        if ( gblErrorCount > 0 )
-               return 1;
+               exit(1);
        
        /* Now send EOF to all parsers. */
        terminateAllParsers();
 
        /* Finished, final check for errors.. */
        if ( gblErrorCount > 0 )
-               return 1;
+               exit(1);
 
        if ( machineSpec == 0 && machineName == 0 )
                hostData << "</host>\n";
 
        if ( gblErrorCount > 0 )
-               return 1;
+               exit(1);
        
        ostream *outputFile = new ofstream( intermed );
 
        /* Write the machines, then the surrounding code. */
        writeMachines( *outputFile, hostData.str(), inputFileName );
 
-       /* Close the intermediate file. */
+       /* Close the input and the intermediate file. */
        delete outputFile;
+       delete inFile;
+
+       /* Bail on above error. */
+       if ( gblErrorCount > 0 )
+               exit(1);
+
+       const char *xmlInputFileName = intermed;
+
+       bool wantComplete = true;
+       bool outputActive = true;
+
+       /* Open the input file for reading. */
+       inFile = new ifstream( xmlInputFileName );
+       inStream = inFile;
+       if ( ! inFile->is_open() )
+               error() << "could not open " << xmlInputFileName << " for reading" << endl;
+
+       /* Bail on above error. */
+       if ( gblErrorCount > 0 )
+               exit(1);
 
-       return gblErrorCount > 0;
+       /* Locate the backend program */
+       if ( generateDot ) {
+               wantComplete = false;
+               outputActive = false;
+       }
+
+       XmlScanner xmlScanner( xmlInputFileName, *inStream );
+       XmlParser xmlParser( xmlInputFileName, outputActive, wantComplete );
+       xmlParser.init();
+
+       xml_parse( *inStream, xmlInputFileName, 
+               outputActive, wantComplete,
+               xmlScanner, xmlParser );
+
+       /* If writing to a file, delete the ostream, causing it to flush.
+        * Standard out is flushed automatically. */
+       if ( outputFileName != 0 ) {
+               delete outStream;
+               delete outFilter;
+       }
+
+       /* Finished, final check for errors.. */
+       if ( gblErrorCount > 0 ) {
+               /* If we opened an output file, remove it. */
+               if ( outputFileName != 0 )
+                       unlink( outputFileName );
+               exit(1);
+       }
 }
 
 char *makeIntermedTemplate( const char *baseFileName )
@@ -554,47 +601,6 @@ void cleanExit( const char *intermed, int status )
        exit( status );
 }
 
-void backend( const char *intermed )
-{
-       const char *xmlInputFileName = intermed;
-
-       bool wantComplete = true;
-       bool outputActive = true;
-
-       /* Open the input file for reading. */
-       ifstream *inFile = new ifstream( xmlInputFileName );
-       inStream = inFile;
-       if ( ! inFile->is_open() )
-               error() << "could not open " << xmlInputFileName << " for reading" << endl;
-
-       /* Bail on above error. */
-       if ( gblErrorCount > 0 )
-               exit(1);
-
-       /* Locate the backend program */
-       if ( generateDot ) {
-               wantComplete = false;
-               outputActive = false;
-       }
-
-       xml_parse( *inStream, xmlInputFileName, outputActive, wantComplete );
-
-       /* If writing to a file, delete the ostream, causing it to flush.
-        * Standard out is flushed automatically. */
-       if ( outputFileName != 0 ) {
-               delete outStream;
-               delete outFilter;
-       }
-
-       /* Finished, final check for errors.. */
-       if ( gblErrorCount > 0 ) {
-               /* If we opened an output file, remove it. */
-               if ( outputFileName != 0 )
-                       unlink( outputFileName );
-               exit(1);
-       }
-}
-
 /* Main, process args and call yyparse to start scanning input. */
 int main( int argc, const char **argv )
 {
@@ -626,8 +632,7 @@ int main( int argc, const char **argv )
        }
 
        const char *intermed = openIntermed( inputFileName, outputFileName );
-       frontend( inputFileName, intermed );
-       backend( intermed );
+       process( inputFileName, intermed );
 
        /* Clean up the intermediate. */
        cleanExit( intermed, 0 );
index d3f0beb..125ceb7 100644 (file)
@@ -87,7 +87,4 @@ void xmlEscapeHost( std::ostream &out, char *data, long len );
 typedef Vector<const char *> ArgsVector;
 extern ArgsVector includePaths;
 
-int xml_parse( std::istream &input, const char *fileName, 
-               bool outputActive, bool wantComplete );
-
 #endif /* _RAGEL_H */
index 8a5aff5..de88f7d 100644 (file)
@@ -198,6 +198,7 @@ struct XmlParser
 %% write token_defs;
 
 int xml_parse( std::istream &input, const char *fileName, 
-               bool outputActive, bool wantComplete );
+               bool outputActive, bool wantComplete, 
+               XmlScanner &scanner, XmlParser &parser );
 
 #endif /* _XMLPARSE_H */
index 23dcaca..721fbd3 100644 (file)
@@ -216,13 +216,9 @@ int XmlScanner::scan( )
 }
 
 int xml_parse( std::istream &input, const char *fileName, 
-               bool outputActive, bool wantComplete )
+               bool outputActive, bool wantComplete, 
+               XmlScanner &scanner, XmlParser &parser )
 {
-       XmlScanner scanner( fileName, input );
-       XmlParser parser( fileName, outputActive, wantComplete );
-
-       parser.init();
-
        while ( 1 ) {
                int token = scanner.scan();
                if ( token == TK_NO_TOKEN ) {