From 97ce28fa13a34840b5a36e9902d48ae17561d744 Mon Sep 17 00:00:00 2001 From: thurston Date: Sun, 22 Mar 2009 01:26:32 +0000 Subject: [PATCH] Got XML output working. git-svn-id: http://svn.complang.org/ragel/trunk@753 052ea7fc-9027-0410-9066-f65837a77df0 --- ragel/inputdata.cpp | 11 +++++---- ragel/inputdata.h | 2 +- ragel/main.cpp | 23 ++++++----------- ragel/ragel.h | 1 + ragel/rlparse.kh | 2 ++ ragel/xmlcodegen.cpp | 70 ++++++++-------------------------------------------- 6 files changed, 27 insertions(+), 82 deletions(-) diff --git a/ragel/inputdata.cpp b/ragel/inputdata.cpp index 9e464d3..29d02eb 100644 --- a/ragel/inputdata.cpp +++ b/ragel/inputdata.cpp @@ -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(dotGenParser->pd->cgd)->writeDotFile(); + if ( generateXML ) { + writeXML( *outStream ); } + else if ( generateDot ) + static_cast(dotGenParser->pd->cgd)->writeDotFile(); else { for ( InputItemList::Iter ii = inputItems; ii.lte(); ii++ ) { if ( ii->type == InputItem::Write ) { diff --git a/ragel/inputdata.h b/ragel/inputdata.h index f072bb7..a2c9ae8 100644 --- a/ragel/inputdata.h +++ b/ragel/inputdata.h @@ -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 diff --git a/ragel/main.cpp b/ragel/main.cpp index 3a5e3df..28f26c0 100644 --- a/ragel/main.cpp +++ b/ragel/main.cpp @@ -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 ) diff --git a/ragel/ragel.h b/ragel/ragel.h index bfcda67..2f4d6ff 100644 --- a/ragel/ragel.h +++ b/ragel/ragel.h @@ -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. */ diff --git a/ragel/rlparse.kh b/ragel/rlparse.kh index e5ce618..4fbf082 100644 --- a/ragel/rlparse.kh +++ b/ragel/rlparse.kh @@ -132,6 +132,8 @@ struct Parser Vector exportContext; IncludeHistory includeHistory; + + Parser *prev, *next; }; %% write token_defs; diff --git a/ragel/xmlcodegen.cpp b/ragel/xmlcodegen.cpp index 91ee3f7..08bfc20 100644 --- a/ragel/xmlcodegen.cpp +++ b/ragel/xmlcodegen.cpp @@ -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 << "\n"; - if ( gblErrorCount == 0 ) { - 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 << "\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 << "\n"; - parseData->generateXML( out ); - out << hostData; - out << "\n"; - } - } - } + out << "\n"; } - - -- 2.7.4