Improved graphviz output and got -M and -S working again.
[external/ragel.git] / ragel / rubycodegen.cpp
index ba189be..5b50346 100644 (file)
@@ -54,10 +54,9 @@ using std::cerr;
 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;
@@ -74,90 +73,6 @@ extern int numSplitPartitions;
  * 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 )
 {
@@ -181,7 +96,7 @@ void RubyCodeGen::genLineDirective( ostream &out )
 
 string RubyCodeGen::DATA_PREFIX()
 {
-       if ( dataPrefix )
+       if ( !noPrefix )
                return FSM_NAME() + "_";
        return "";
 }
@@ -513,10 +428,10 @@ void RubyCodeGen::STATE_IDS()
        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";
@@ -867,10 +782,10 @@ void RubyCodeGen::writeInit()
        
        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. */
@@ -898,6 +813,22 @@ void RubyCodeGen::writeExports()
        }
 }
 
+void RubyCodeGen::writeStart()
+{
+       out << START_STATE_ID();
+}
+
+void RubyCodeGen::writeFirstFinal()
+{
+       out << FIRST_FINAL_STATE();
+}
+
+void RubyCodeGen::writeError()
+{
+       out << ERROR_STATE();
+}
+
+
 /*
  * Local Variables:
  * mode: c++