void InputData::makeOutputStream()
{
- if ( ! generateDot ) {
+ if ( ! generateDot && ! generateXML ) {
switch ( hostLang->lang ) {
case HostLang::C:
case HostLang::D:
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;
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 ) {
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
bool wantDupsRemoved = true;
bool printStatistics = false;
-bool frontendOnly = false;
+bool generateXML = false;
bool generateDot = false;
/* Target language and output style. */
break;
case 'x':
- frontendOnly = true;
+ generateXML = true;
break;
/* Output. */
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.
/* 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 ) {
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 )
extern bool printStatistics;
extern bool wantDupsRemoved;
extern bool generateDot;
+extern bool generateXML;
extern RubyImplEnum rubyImpl;
/* Error reporting format. */
Vector<bool> exportContext;
IncludeHistory includeHistory;
+
+ Parser *prev, *next;
};
%% write token_defs;
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";
}
-
-