using std::endl;
/* Target ruby impl */
-extern RubyImplEnum rubyImpl;
/* Target language and output style. */
-extern CodeStyleEnum codeStyle;
+extern CodeStyle codeStyle;
/* Io globals. */
extern istream *inStream;
* Callbacks invoked by the XML data parser.
*/
-/* Invoked by the parser when the root element is opened. */
-ostream *rubyOpenOutput( const char *inputFile )
-{
- if ( hostLang->lang != HostLang::Ruby ) {
- error() << "this code generator is for Ruby only" << endl;
- exit(1);
- }
-
- /* If the output format is code and no output file name is given, then
- * make a default. */
- if ( outputFileName == 0 ) {
- const char *ext = findFileExtension( inputFile );
- if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
- outputFileName = fileNameFromStem( inputFile, ".h" );
- else
- outputFileName = fileNameFromStem( inputFile, ".rb" );
- }
-
- /* Make sure we are not writing to the same file as the input file. */
- if ( outputFileName != 0 && strcmp( inputFile, outputFileName ) == 0 ) {
- error() << "output file \"" << outputFileName <<
- "\" is the same as the input file" << endl;
- }
-
- if ( outputFileName != 0 ) {
- /* Create the filter on the output and open it. */
- outFilter = new output_filter( outputFileName );
- outFilter->open( outputFileName, ios::out|ios::trunc );
- if ( !outFilter->is_open() ) {
- error() << "error opening " << outputFileName << " for writing" << endl;
- exit(1);
- }
-
- /* Open the output stream, attaching it to the filter. */
- outStream = new ostream( outFilter );
- }
- else {
- /* Writing out ot std out. */
- outStream = &cout;
- }
- return outStream;
-}
-
-/* Invoked by the parser when a ragel definition is opened. */
-CodeGenData *rubyMakeCodeGen( const char *sourceFileName, const char *fsmName,
- ostream &out, bool wantComplete )
-{
- CodeGenData *codeGen = 0;
- switch ( codeStyle ) {
- case GenTables:
- codeGen = new RubyTabCodeGen(out);
- break;
- case GenFTables:
- codeGen = new RubyFTabCodeGen(out);
- break;
- case GenFlat:
- codeGen = new RubyFlatCodeGen(out);
- break;
- case GenFFlat:
- codeGen = new RubyFFlatCodeGen(out);
- break;
- case GenGoto:
- if ( rubyImpl == Rubinius ) {
- codeGen = new RbxGotoCodeGen(out);
- } else {
- cout << "Goto style is still _very_ experimental "
- "and only supported using Rubinius.\n"
- "You may want to enable the --rbx flag "
- " to give it a try.\n";
- exit(1);
- }
- break;
- default:
- cout << "Invalid code style\n";
- exit(1);
- break;
- }
- codeGen->sourceFileName = sourceFileName;
- codeGen->fsmName = fsmName;
- codeGen->wantComplete = wantComplete;
-
- return codeGen;
-}
-
void rubyLineDirective( ostream &out, const char *fileName, int line )
{
string RubyCodeGen::DATA_PREFIX()
{
- if ( dataPrefix )
+ if ( !noPrefix )
return FSM_NAME() + "_";
return "";
}
if ( redFsm->startState != 0 )
STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
- if ( writeFirstFinal )
+ if ( !noFinal )
STATIC_VAR( "int" , FIRST_FINAL() ) << " = " << FIRST_FINAL_STATE() << ";\n";
- if ( writeErr )
+ if ( !noError )
STATIC_VAR( "int", ERROR() ) << " = " << ERROR_STATE() << ";\n";
out << "\n";
out << " " << P() << " ||= 0\n";
- if ( hasEnd )
+ if ( !noEnd )
out << " " << PE() << " ||= " << DATA() << ".length\n";
- if ( writeCS )
+ if ( !noCS )
out << " " << CS() << " = " << START() << "\n";
/* If there are any calls, then the stack top needs initialization. */
}
}
+void RubyCodeGen::writeStart()
+{
+ out << START_STATE_ID();
+}
+
+void RubyCodeGen::writeFirstFinal()
+{
+ out << FIRST_FINAL_STATE();
+}
+
+void RubyCodeGen::writeError()
+{
+ out << ERROR_STATE();
+}
+
+
/*
* Local Variables:
* mode: c++