GEN_SRC = rlscan.cpp rlparse.h rlparse.cpp
RAGEL_LIBS = ../common/common.a \
+ ../redfsm/redfsm.a \
../rlgen-cd/rlgen-cd.a \
../rlgen-java/rlgen-java.a \
../rlgen-ruby/rlgen-ruby.a \
../rlgen-csharp/rlgen-csharp.a \
- ../rlgen-dot/rlgen-dot.a \
- ../redfsm/redfsm.a
+ ../rlgen-dot/rlgen-dot.a
LIBS = $(RAGEL_LIBS)
MINGW_LIBS = -lpsapi
int numSplitPartitions = 0;
bool noLineDirectives = false;
+
bool displayPrintables = false;
+bool graphvizDone = false;
/* Target ruby impl */
RubyImplEnum rubyImpl = MRI;
ArgsVector includePaths;
+istream *inStream = 0;
+ostream *outStream = 0;
+output_filter *outFilter = 0;
const char *outputFileName = 0;
/* Print a summary of the options. */
exit( status );
}
-int cd_main( const char *xmlInputFileName );
-int java_main( const char *xmlInputFileName );
-int ruby_main( const char *xmlInputFileName );
-int csharp_main( const char *xmlInputFileName );
-int dot_main( const char *xmlInputFileName );
-
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 )
- dot_main( intermed );
- else {
- switch ( hostLang->lang ) {
- case HostLang::C:
- case HostLang::D:
- cd_main( intermed );
- break;
- case HostLang::Java:
- java_main( intermed );
- break;
- case HostLang::Ruby:
- ruby_main( intermed );
- break;
- case HostLang::CSharp:
- csharp_main( intermed );
- break;
- }
+ 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);
}
}
typedef Vector<const char *> ArgsVector;
extern ArgsVector includePaths;
+int xml_parse( std::istream &input, const char *fileName,
+ bool outputActive, bool wantComplete );
+
#endif /* _RAGEL_H */
extern CodeStyleEnum codeStyle;
/* Io globals. */
-istream *inStream = 0;
-ostream *outStream = 0;
-output_filter *outFilter = 0;
+extern istream *inStream;
+extern ostream *outStream;
+extern output_filter *outFilter;
extern const char *outputFileName;
/* Graphviz dot file generation. */
-bool graphvizDone = false;
+extern bool graphvizDone;
extern int numSplitPartitions;
extern bool noLineDirectives;
-/* Print a summary of the options. */
-void cd_usage()
-{
- cout <<
-"usage: " PROGNAME " [options] file\n"
-"general:\n"
-" -h, -H, -?, --help Print this usage and exit\n"
-" -v, --version Print version information and exit\n"
-" -o <file> Write output to <file>\n"
-"code generation options:\n"
-" -L Inhibit writing of #line directives\n"
-"generated code style:\n"
-" -T0 Table driven FSM (default)\n"
-" -T1 Faster table driven FSM\n"
-" -F0 Flat table driven FSM\n"
-" -F1 Faster flat table-driven FSM\n"
-" -G0 Goto-driven FSM\n"
-" -G1 Faster goto-driven FSM\n"
-" -G2 Really fast goto-driven FSM\n"
-" -P<N> N-Way Split really fast goto-driven FSM\n"
- ;
-}
-
-/* Print version information. */
-void cd_version()
-{
- cout << "Ragel Code Generator for C, C++, Objective-C and D" << endl <<
- "Version " VERSION << ", " PUBDATE << endl <<
- "Copyright (c) 2001-2007 by Adrian Thurston" << endl;
-}
-
-ostream &cd_error()
-{
- gblErrorCount += 1;
- cerr << PROGNAME ": ";
- return cerr;
-}
/*
* Callbacks invoked by the XML data parser.
ostream *cdOpenOutput( char *inputFile )
{
if ( hostLang->lang != HostLang::C && hostLang->lang != HostLang::D ) {
- cd_error() << "this code generator is for C and D only" << endl;
+ error() << "this code generator is for C and D only" << endl;
exit(1);
}
/* Make sure we are not writing to the same file as the input file. */
if ( outputFileName != 0 && strcmp( inputFile, outputFileName ) == 0 ) {
- cd_error() << "output file \"" << outputFileName <<
+ error() << "output file \"" << outputFileName <<
"\" is the same as the input file" << endl;
}
outFilter = new output_filter( outputFileName );
outFilter->open( outputFileName, ios::out|ios::trunc );
if ( !outFilter->is_open() ) {
- cd_error() << "error opening " << outputFileName << " for writing" << endl;
+ error() << "error opening " << outputFileName << " for writing" << endl;
exit(1);
}
return codeGen;
}
-/* Main, process args and call yyparse to start scanning input. */
-int cd_main( const char *xmlInputFileName )
-{
- /* Open the input file for reading. */
- ifstream *inFile = new ifstream( xmlInputFileName );
- inStream = inFile;
- if ( ! inFile->is_open() )
- cd_error() << "could not open " << xmlInputFileName << " for reading" << endl;
-
- /* Bail on above errors. */
- if ( gblErrorCount > 0 )
- exit(1);
-
- bool wantComplete = true;
- bool outputActive = true;
-
- /* Parse the input! */
- 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);
- }
- return 0;
-}
return codeGen;
}
-
-/* Main, process args and call yyparse to start scanning input. */
-int csharp_main( const char *xmlInputFileName )
-{
- /* Open the input file for reading. */
- ifstream *inFile = new ifstream( xmlInputFileName );
- inStream = inFile;
- if ( ! inFile->is_open() )
- csharp_error() << "could not open " << xmlInputFileName << " for reading" << endl;
-
- /* Bail on above errors. */
- if ( gblErrorCount > 0 )
- exit(1);
-
- bool wantComplete = true;
- bool outputActive = true;
-
- /* Parse the input! */
- 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);
- }
- return 0;
-}
extern int numSplitPartitions;
/* Print a summary of the options. */
-void dot_usage()
-{
- cout <<
-"usage: " PROGNAME " [options] file\n"
-"general:\n"
-" -h, -H, -?, --help Print this usage and exit\n"
-" -v, --version Print version information and exit\n"
-" -o <file> Write output to <file>\n"
-"output:\n"
-" -p Display printable characters on labels\n"
- ;
-}
-
-/* Print version information. */
-void dot_version()
-{
- cout << "Ragel Code Generator for Graphviz" << endl <<
- "Version " VERSION << ", " PUBDATE << endl <<
- "Copyright (c) 2001-2007 by Adrian Thurston" << endl;
-}
-
-ostream &dot_error()
-{
- gblErrorCount += 1;
- cerr << PROGNAME ": ";
- return cerr;
-}
/*
* Callbacks invoked by the XML data parser.
{
/* Make sure we are not writing to the same file as the input file. */
if ( outputFileName != 0 && strcmp( inputFile, outputFileName ) == 0 ) {
- dot_error() << "output file \"" << outputFileName <<
+ error() << "output file \"" << outputFileName <<
"\" is the same as the input file" << endl;
}
outFilter = new output_filter( outputFileName );
outFilter->open( outputFileName, ios::out|ios::trunc );
if ( !outFilter->is_open() ) {
- dot_error() << "error opening " << outputFileName << " for writing" << endl;
+ error() << "error opening " << outputFileName << " for writing" << endl;
exit(1);
}
return codeGen;
}
-
-
-/* Main, process args and call yyparse to start scanning input. */
-int dot_main( const char *xmlInputFileName )
-{
- /* Open the input file for reading. */
- ifstream *inFile = new ifstream( xmlInputFileName );
- inStream = inFile;
- if ( ! inFile->is_open() )
- dot_error() << "could not open " << xmlInputFileName << " for reading" << endl;
-
- /* Bail on above errors. */
- if ( gblErrorCount > 0 )
- exit(1);
-
- bool wantComplete = false;
- bool outputActive = false;
-
- /* Parse the input! */
- 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);
- }
- return 0;
-}
extern int numSplitPartitions;
-/* Print a summary of the options. */
-void java_usage()
-{
- cout <<
-"usage: " PROGNAME " [options] file\n"
-"general:\n"
-" -h, -H, -?, --help Print this usage and exit\n"
-" -v, --version Print version information and exit\n"
-" -o <file> Write output to <file>\n"
- ;
-}
-
-/* Print version information. */
-void java_version()
-{
- cout << "Ragel Code Generator for Java" << endl <<
- "Version " VERSION << ", " PUBDATE << endl <<
- "Copyright (c) 2001-2007 by Adrian Thurston" << endl;
-}
-
-ostream &java_error()
-{
- gblErrorCount += 1;
- cerr << PROGNAME ": ";
- return cerr;
-}
-
/*
* Callbacks invoked by the XML data parser.
*/
ostream *javaOpenOutput( char *inputFile )
{
if ( hostLang->lang != HostLang::Java ) {
- java_error() << "this code generator is for Java only" << endl;
+ error() << "this code generator is for Java only" << endl;
exit(1);
}
/* Make sure we are not writing to the same file as the input file. */
if ( outputFileName != 0 && strcmp( inputFile, outputFileName ) == 0 ) {
- java_error() << "output file \"" << outputFileName <<
+ error() << "output file \"" << outputFileName <<
"\" is the same as the input file" << endl;
}
outFilter = new output_filter( outputFileName );
outFilter->open( outputFileName, ios::out|ios::trunc );
if ( !outFilter->is_open() ) {
- java_error() << "error opening " << outputFileName << " for writing" << endl;
+ error() << "error opening " << outputFileName << " for writing" << endl;
exit(1);
}
return codeGen;
}
-
-/* Main, process args and call yyparse to start scanning input. */
-int java_main( const char *xmlInputFileName )
-{
- /* Open the input file for reading. */
- ifstream *inFile = new ifstream( xmlInputFileName );
- inStream = inFile;
- if ( ! inFile->is_open() )
- java_error() << "could not open " << xmlInputFileName << " for reading" << endl;
-
- /* Bail on above errors. */
- if ( gblErrorCount > 0 )
- exit(1);
-
- bool wantComplete = true;
- bool outputActive = true;
-
- /* Parse the input! */
- 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);
- }
- return 0;
-}
extern int numSplitPartitions;
-/* Print a summary of the options. */
-void ruby_usage()
-{
- cout <<
-"usage: " PROGNAME " [options] file\n"
-"general:\n"
-" -h, -H, -?, --help Print this usage and exit\n"
-" -v, --version Print version information and exit\n"
-" -o <file> Write output to <file>\n"
-" --rbx Allow to use Rubinius asm features\n"
-"generated code style:\n"
-" -T0 Table driven FSM (default)\n"
-" -T1 Faster table driven FSM\n"
-" -F0 Flat table driven FSM\n"
-" -F1 Faster flat table-driven FSM\n"
-" -G0 Goto-driven FSM\n"
- ;
-}
-
-/* Print version information. */
-void ruby_version()
-{
- cout << "Ragel Code Generator for Ruby" << endl <<
- "Version " VERSION << ", " PUBDATE << endl <<
- "Copyright (c) 2001-2007 by Adrian Thurston" << endl <<
- "Copyright (c) 2007 by Victor Hugo Borja" << endl;
-}
-
-ostream &ruby_error()
-{
- gblErrorCount += 1;
- cerr << PROGNAME ": ";
- return cerr;
-}
-
/*
* Callbacks invoked by the XML data parser.
*/
ostream *rubyOpenOutput( char *inputFile )
{
if ( hostLang->lang != HostLang::Ruby ) {
- ruby_error() << "this code generator is for Ruby only" << endl;
+ error() << "this code generator is for Ruby only" << endl;
exit(1);
}
/* Make sure we are not writing to the same file as the input file. */
if ( outputFileName != 0 && strcmp( inputFile, outputFileName ) == 0 ) {
- ruby_error() << "output file \"" << outputFileName <<
+ error() << "output file \"" << outputFileName <<
"\" is the same as the input file" << endl;
}
outFilter = new output_filter( outputFileName );
outFilter->open( outputFileName, ios::out|ios::trunc );
if ( !outFilter->is_open() ) {
- ruby_error() << "error opening " << outputFileName << " for writing" << endl;
+ error() << "error opening " << outputFileName << " for writing" << endl;
exit(1);
}
return codeGen;
}
-/* Main, process args and call yyparse to start scanning input. */
-int ruby_main( const char *xmlInputFileName )
-{
- /* Open the input file for reading. */
- ifstream *inFile = new ifstream( xmlInputFileName );
- inStream = inFile;
- if ( ! inFile->is_open() )
- ruby_error() << "could not open " << xmlInputFileName << " for reading" << endl;
-
- /* Bail on above errors. */
- if ( gblErrorCount > 0 )
- exit(1);
-
- bool wantComplete = true;
- bool outputActive = true;
-
- /* Parse the input! */
- 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);
- }
- return 0;
-}
-
/*
* Local Variables:
* mode: c++