From b28765cd99ddbb5c059338977d5a72e42bc51526 Mon Sep 17 00:00:00 2001 From: thurston Date: Mon, 1 Sep 2008 23:31:52 +0000 Subject: [PATCH] Now supplying the XmlParser to writeMachines. git-svn-id: svn://mambo.cs.queensu.ca/ragel/trunk@468 052ea7fc-9027-0410-9066-f65837a77df0 --- ragel/main.cpp | 52 +++++++++++++++++++++++++--------------------------- ragel/parsedata.cpp | 3 ++- ragel/ragel.h | 5 ++++- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/ragel/main.cpp b/ragel/main.cpp index 5261ff1..1e7ccc0 100644 --- a/ragel/main.cpp +++ b/ragel/main.cpp @@ -443,10 +443,13 @@ void processArgs( int argc, const char **argv, const char *&inputFileName ) void process( const char *inputFileName, const char *intermed ) { + const char *xmlFileName = intermed; + bool wantComplete = true; + bool outputActive = true; + /* Open the input file for reading. */ assert( inputFileName != 0 ); ifstream *inFile = new ifstream( inputFileName ); - istream *inStream = inFile; if ( ! inFile->is_open() ) error() << "could not open " << inputFileName << " for reading" << endp; @@ -456,7 +459,7 @@ void process( const char *inputFileName, const char *intermed ) if ( machineSpec == 0 && machineName == 0 ) hostData << ""; - Scanner scanner( inputFileName, *inStream, hostData, 0, 0, 0, false ); + Scanner scanner( inputFileName, *inFile, hostData, 0, 0, 0, false ); scanner.do_scan(); /* Finished, final check for errors.. */ @@ -476,29 +479,13 @@ void process( const char *inputFileName, const char *intermed ) if ( gblErrorCount > 0 ) exit(1); - ostream *outputFile = new ofstream( intermed ); + /* Open the XML file for writing. */ + ostream *xmlOutFile = new ofstream( xmlFileName ); - /* Write the machines, then the surrounding code. */ - writeMachines( *outputFile, hostData.str(), inputFileName ); - - /* 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; + /* Open the XML file for reading. */ + ifstream *xmlInFile = new ifstream( xmlFileName ); + if ( ! xmlInFile->is_open() ) + error() << "could not open " << xmlFileName << " for reading" << endl; /* Bail on above error. */ if ( gblErrorCount > 0 ) @@ -510,11 +497,22 @@ void process( const char *inputFileName, const char *intermed ) outputActive = false; } - XmlScanner xmlScanner( xmlInputFileName, *inStream ); - XmlParser xmlParser( xmlInputFileName, outputActive, wantComplete ); + XmlScanner xmlScanner( xmlFileName, *xmlInFile ); + XmlParser xmlParser( xmlFileName, outputActive, wantComplete ); xmlParser.init(); - xml_parse( *inStream, xmlInputFileName, + /* Write the machines, then the surrounding code. */ + writeMachines( *xmlOutFile, hostData.str(), inputFileName, xmlParser ); + + /* Close the input and the intermediate file. */ + delete xmlOutFile; + delete inFile; + + /* Bail on above error. */ + if ( gblErrorCount > 0 ) + exit(1); + + xml_parse( *xmlInFile, xmlFileName, outputActive, wantComplete, xmlScanner, xmlParser ); diff --git a/ragel/parsedata.cpp b/ragel/parsedata.cpp index 8d862cd..73f52c6 100644 --- a/ragel/parsedata.cpp +++ b/ragel/parsedata.cpp @@ -1470,7 +1470,8 @@ void writeLanguage( std::ostream &out ) } -void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName ) +void writeMachines( std::ostream &out, std::string hostData, + const char *inputFileName, XmlParser &xmlParser ) { if ( machineSpec == 0 && machineName == 0 ) { /* No machine spec or machine name given. Generate everything. */ diff --git a/ragel/ragel.h b/ragel/ragel.h index 125ceb7..cf5951b 100644 --- a/ragel/ragel.h +++ b/ragel/ragel.h @@ -80,8 +80,11 @@ std::ostream &error(); std::ostream &error( const InputLoc &loc ); std::ostream &warning( const InputLoc &loc ); +struct XmlParser; + void terminateAllParsers( ); -void writeMachines( std::ostream &out, std::string hostData, const char *inputFileName ); +void writeMachines( std::ostream &out, std::string hostData, + const char *inputFileName, XmlParser &xmlParser ); void xmlEscapeHost( std::ostream &out, char *data, long len ); typedef Vector ArgsVector; -- 2.11.4.GIT