Updated the help output. Moved some code from InputData:: to main.
[external/ragel.git] / ragel / gendata.cpp
index 14124eb..86e3d0d 100644 (file)
 using std::cerr;
 using std::endl;
 
+CodeGenData *makeCodeGen( const char *sourceFileName, const char *fsmName, 
+               ostream &out, bool wantComplete )
+{
+       CodeGenData *cgd = 0;
+       if ( generateDot )
+               cgd = dotMakeCodeGen( sourceFileName, fsmName, out, wantComplete );
+       else if ( hostLang == &hostLangC )
+               cgd = cdMakeCodeGen( sourceFileName, fsmName, out, wantComplete );
+       else if ( hostLang == &hostLangD )
+               cgd = cdMakeCodeGen( sourceFileName, fsmName, out, wantComplete );
+       else if ( hostLang == &hostLangJava )
+               cgd = javaMakeCodeGen( sourceFileName, fsmName, out, wantComplete );
+       else if ( hostLang == &hostLangRuby )
+               cgd = rubyMakeCodeGen( sourceFileName, fsmName, out, wantComplete );
+       else if ( hostLang == &hostLangCSharp )
+               cgd = csharpMakeCodeGen( sourceFileName, fsmName, out, wantComplete );
+       return cgd;
+}
+
+void lineDirective( ostream &out, const char *fileName, int line )
+{
+       if ( !generateDot ) {
+               if ( hostLang == &hostLangC )
+                       cdLineDirective( out, fileName, line );
+               else if ( hostLang == &hostLangD )
+                       cdLineDirective( out, fileName, line );
+               else if ( hostLang == &hostLangJava )
+                       javaLineDirective( out, fileName, line );
+               else if ( hostLang == &hostLangRuby )
+                       rubyLineDirective( out, fileName, line );
+               else if ( hostLang == &hostLangCSharp )
+                       csharpLineDirective( out, fileName, line );
+       }
+}
+
+void genLineDirective( ostream &out )
+{
+       std::streambuf *sbuf = out.rdbuf();
+       output_filter *filter = static_cast<output_filter*>(sbuf);
+       lineDirective( out, filter->fileName, filter->line + 1 );
+}
+
+
 /* Total error count. */
 /* int gblErrorCount = 0; */
 
@@ -58,11 +101,11 @@ CodeGenData::CodeGenData( ostream &out )
        dataExpr(0),
        wantComplete(0),
        hasLongestMatch(false),
-       hasEnd(true),
-       dataPrefix(true),
-       writeFirstFinal(true),
-       writeErr(true),
-       writeCS(true)
+       noEnd(false),
+       noPrefix(false),
+       noFinal(false),
+       noError(false),
+       noCS(false)
 {}
 
 
@@ -668,59 +711,71 @@ void CodeGenData::analyzeMachine()
        setValueLimits();
 }
 
+void CodeGenData::write_option_error( InputLoc &loc, char *arg )
+{
+       source_warning(loc) << "unrecognized write option \"" << arg << "\"" << endl;
+}
+
 void CodeGenData::writeStatement( InputLoc &loc, int nargs, char **args )
 {
        /* FIXME: This should be moved to the virtual functions in the code
         * generators.
         *
         * Force a newline. */
-       out << "\n";
+       out << '\n';
        genLineDirective( out );
 
        if ( strcmp( args[0], "data" ) == 0 ) {
                for ( int i = 1; i < nargs; i++ ) {
                        if ( strcmp( args[i], "noerror" ) == 0 )
-                               writeErr = false;
+                               noError = true;
                        else if ( strcmp( args[i], "noprefix" ) == 0 )
-                               dataPrefix = false;
+                               noPrefix = true;
                        else if ( strcmp( args[i], "nofinal" ) == 0 )
-                               writeFirstFinal = false;
-                       else {
-                               source_warning(loc) << "unrecognized write option \"" << 
-                                               args[i] << "\"" << endl;
-                       }
+                               noFinal = true;
+                       else
+                               write_option_error( loc, args[i] );
                }
                writeData();
        }
        else if ( strcmp( args[0], "init" ) == 0 ) {
                for ( int i = 1; i < nargs; i++ ) {
                        if ( strcmp( args[i], "nocs" ) == 0 )
-                               writeCS = false;
-                       else {
-                               source_warning(loc) << "unrecognized write option \"" << 
-                                               args[i] << "\"" << endl;
-                       }
+                               noCS = true;
+                       else
+                               write_option_error( loc, args[i] );
                }
                writeInit();
        }
        else if ( strcmp( args[0], "exec" ) == 0 ) {
                for ( int i = 1; i < nargs; i++ ) {
                        if ( strcmp( args[i], "noend" ) == 0 )
-                               hasEnd = false;
-                       else {
-                               source_warning(loc) << "unrecognized write option \"" << 
-                                               args[i] << "\"" << endl;
-                       }
+                               noEnd = true;
+                       else
+                               write_option_error( loc, args[i] );
                }
                writeExec();
        }
        else if ( strcmp( args[0], "exports" ) == 0 ) {
-               for ( int i = 1; i < nargs; i++ ) {
-                       source_warning(loc) << "unrecognized write option \"" << 
-                                       args[i] << "\"" << endl;
-               }
+               for ( int i = 1; i < nargs; i++ )
+                       write_option_error( loc, args[i] );
                writeExports();
        }
+       else if ( strcmp( args[0], "start" ) == 0 ) {
+               for ( int i = 1; i < nargs; i++ )
+                       write_option_error( loc, args[i] );
+               writeStart();
+       }
+       else if ( strcmp( args[0], "first_final" ) == 0 ) {
+               for ( int i = 1; i < nargs; i++ )
+                       write_option_error( loc, args[i] );
+               writeFirstFinal();
+       }
+       else if ( strcmp( args[0], "error" ) == 0 ) {
+               for ( int i = 1; i < nargs; i++ )
+                       write_option_error( loc, args[i] );
+               writeError();
+       }
        else {
                /* EMIT An error here. */
                source_error(loc) << "unrecognized write command \"" <<