Introcuded the "eof" variable for indicating the end of file. The p variable is
[external/ragel.git] / rlgen-cd / tabcodegen.cpp
index 7dccb4d..78f8a26 100644 (file)
@@ -867,6 +867,7 @@ void TabCodeGen::COND_TRANSLATE()
 
 void TabCodeGen::writeExec()
 {
+       testEofUsed = false;
        outLabelUsed = false;
 
        out <<
@@ -896,10 +897,10 @@ void TabCodeGen::writeExec()
                "\n";
 
        if ( hasEnd ) {
-               outLabelUsed = true;
+               testEofUsed = true;
                out << 
                        "       if ( " << P() << " == " << PE() << " )\n"
-                       "               goto _out;\n";
+                       "               goto _test_eof;\n";
        }
 
        if ( redFsm->errState != 0 ) {
@@ -992,23 +993,18 @@ void TabCodeGen::writeExec()
                        "       goto _resume;\n";
        }
        
-       if ( outLabelUsed )
-               out << "        _out: {}\n";
-
-       out << "        }\n";
-}
-
-
-void TabCodeGen::writeEOF()
-{
+       if ( testEofUsed )
+               out << "        _test_eof: {}\n";
+       
        if ( redFsm->anyEofActions() ) {
                out << 
+                       "       if ( " << P() << " == " << EOFV() << " )\n"
                        "       {\n"
-                       "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts = " << 
-                                       ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
-                       "       " << UINT() << " _nacts = " << CAST(UINT()) << " *_acts++;\n"
-                       "       while ( _nacts-- > 0 ) {\n"
-                       "               switch ( *_acts++ ) {\n";
+                       "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << 
+                                       POINTER() << "__acts = " << ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
+                       "       " << UINT() << " __nacts = " << CAST(UINT()) << " *__acts++;\n"
+                       "       while ( __nacts-- > 0 ) {\n"
+                       "               switch ( *__acts++ ) {\n";
                        EOF_ACTION_SWITCH();
                        SWITCH_DEFAULT() <<
                        "               }\n"
@@ -1016,4 +1012,14 @@ void TabCodeGen::writeEOF()
                        "       }\n"
                        "\n";
        }
+
+       if ( outLabelUsed )
+               out << "        _out: {}\n";
+
+       out << "        }\n";
+}
+
+
+void TabCodeGen::writeEOF()
+{
 }