Fixed an inconsistency in the value of p following an error. In the C directly
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Thu, 10 May 2007 01:37:23 +0000 (01:37 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Thu, 10 May 2007 01:37:23 +0000 (01:37 +0000)
executable code (rlgen-cd -G2) p was left at the character where the error
occurred, which is correct. In all other code generators it was left at the
following character. This was fixed. Now in all code generators p is left at
the character where the error occurred.

git-svn-id: http://svn.complang.org/ragel/trunk@225 052ea7fc-9027-0410-9066-f65837a77df0

13 files changed:
ChangeLog
ragel/main.cpp
rlgen-cd/fflatcodegen.cpp
rlgen-cd/fgotocodegen.cpp
rlgen-cd/flatcodegen.cpp
rlgen-cd/ftabcodegen.cpp
rlgen-cd/gotocodegen.cpp
rlgen-cd/tabcodegen.cpp
rlgen-java/javacodegen.cpp
rlgen-ruby/rubycodegen.cpp
test/erract7.rl [new file with mode: 0644]
test/erract8.rl [new file with mode: 0644]
test/erract9.rl [new file with mode: 0644]

index 3e61b5e..d7894aa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,17 @@
 Ragel 5.21 - May 9, 2007
 ========================
+ -Fixed an inconsistency in the value of p following an error. In the C
+  directly executable code (rlgen-cd -G2) p is left at the character where
+  the error occurred, which is correct. In all other code generators it was
+  left at the following character. This was fixed. Now in all code generators
+  p is left at the character where the error occurred.
  -Bug fix: when fhold was used in scanner pattern actions which get executed
   on the last character of the pattern (pattern matches which do not require
   any lookahead), fhold was modifying p instead of tokend. This was fixed and
   the patact.rl test was modified to cover the case.
  -Fixed typos in the guide, improved the state action embedding operator
-  section.
+  section and added subsections on the variable, import, and export
+  statements.
  -Implemented a better solution than the pri hack for resolving the '-'
   ambiguity: force a shortest match of term.
  -Fixed bugs in the binary searching for condition keys in both the Ruby and
index e5f4747..ae70c8b 100644 (file)
@@ -86,7 +86,7 @@ void usage()
 void version()
 {
        cout << "Ragel State Machine Compiler version " VERSION << " " PUBDATE << endl <<
-                       "Copyright (c) 2001-2006 by Adrian Thurston" << endl;
+                       "Copyright (c) 2001-2007 by Adrian Thurston" << endl;
 }
 
 /* Total error count. */
index 813347f..340b344 100644 (file)
@@ -265,8 +265,6 @@ void FFlatCodeGen::writeExec()
                        "               goto _out;\n";
        }
 
-       out << "_resume:\n";
-
        if ( redFsm->errState != 0 ) {
                outLabelUsed = true;
                out << 
@@ -274,6 +272,8 @@ void FFlatCodeGen::writeExec()
                        "               goto _out;\n";
        }
 
+       out << "_resume:\n";
+
        if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       switch ( " << FSA() << "[" << CS() << "] ) {\n";
@@ -319,6 +319,13 @@ void FFlatCodeGen::writeExec()
                        "\n";
        }
 
+       if ( redFsm->errState != 0 ) {
+               outLabelUsed = true;
+               out << 
+                       "       if ( " << CS() << " == " << redFsm->errState->id << " )\n"
+                       "               goto _out;\n";
+       }
+
        if ( hasEnd ) {
                out << 
                        "       if ( ++" << P() << " != " << PE() << " )\n"
index 9c4f039..a6b0d02 100644 (file)
@@ -195,6 +195,13 @@ void FGotoCodeGen::writeExec()
                        "               goto _out;\n";
        }
 
+       if ( redFsm->errState != 0 ) {
+               outLabelUsed = true;
+               out << 
+                       "       if ( " << CS() << " == " << redFsm->errState->id << " )\n"
+                       "               goto _out;\n";
+       }
+
        out << "_resume:\n";
 
        if ( redFsm->anyFromStateActions() ) {
@@ -229,6 +236,13 @@ void FGotoCodeGen::writeExec()
                        "\n";
        }
 
+       if ( redFsm->errState != 0 ) {
+               outLabelUsed = true;
+               out << 
+                       "       if ( " << CS() << " == " << redFsm->errState->id << " )\n"
+                       "               goto _out;\n";
+       }
+
        if ( hasEnd ) {
                out << 
                        "       if ( ++" << P() << " != " << PE() << " )\n"
index 117f379..f2712dd 100644 (file)
@@ -661,8 +661,6 @@ void FlatCodeGen::writeExec()
                        "       if ( " << P() << " == " << PE() << " )\n"
                        "               goto _out;\n";
        }
-       
-       out << "_resume:\n";
 
        if ( redFsm->errState != 0 ) {
                outLabelUsed = true;
@@ -671,6 +669,8 @@ void FlatCodeGen::writeExec()
                        "               goto _out;\n";
        }
 
+       out << "_resume:\n";
+
        if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
@@ -729,6 +729,13 @@ void FlatCodeGen::writeExec()
                        "\n";
        }
 
+       if ( redFsm->errState != 0 ) {
+               outLabelUsed = true;
+               out << 
+                       "       if ( " << CS() << " == " << redFsm->errState->id << " )\n"
+                       "               goto _out;\n";
+       }
+
        if ( hasEnd ) {
                out << 
                        "       if ( ++" << P() << " != " << PE() << " )\n"
index 1d65e71..9e377a3 100644 (file)
@@ -311,8 +311,6 @@ void FTabCodeGen::writeExec()
                        "               goto _out;\n";
        }
 
-       out << "_resume:\n";
-
        if ( redFsm->errState != 0 ) {
                outLabelUsed = true;
                out << 
@@ -320,6 +318,8 @@ void FTabCodeGen::writeExec()
                        "               goto _out;\n";
        }
 
+       out << "_resume:\n";
+
        if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       switch ( " << FSA() << "[" << CS() << "] ) {\n";
@@ -371,6 +371,13 @@ void FTabCodeGen::writeExec()
                        "\n";
        }
 
+       if ( redFsm->errState != 0 ) {
+               outLabelUsed = true;
+               out << 
+                       "       if ( " << CS() << " == " << redFsm->errState->id << " )\n"
+                       "               goto _out;\n";
+       }
+
        if ( hasEnd ) {
                out << 
                        "       if ( ++" << P() << " != " << PE() << " )\n"
index 13be67d..0f5e92f 100644 (file)
@@ -663,6 +663,13 @@ void GotoCodeGen::writeExec()
                        "               goto _out;\n";
        }
 
+       if ( redFsm->errState != 0 ) {
+               outLabelUsed = true;
+               out << 
+                       "       if ( " << CS() << " == " << redFsm->errState->id << " )\n"
+                       "               goto _out;\n";
+       }
+
        out << "_resume:\n";
 
        if ( redFsm->anyFromStateActions() ) {
@@ -705,6 +712,13 @@ void GotoCodeGen::writeExec()
                        "\n";
        }
 
+       if ( redFsm->errState != 0 ) {
+               outLabelUsed = true;
+               out << 
+                       "       if ( " << CS() << " == " << redFsm->errState->id << " )\n"
+                       "               goto _out;\n";
+       }
+
        if ( hasEnd ) {
                out << 
                        "       if ( ++" << P() << " != " << PE() << " )\n"
index 22f0953..8c39825 100644 (file)
@@ -878,8 +878,6 @@ void TabCodeGen::writeExec()
                        "               goto _out;\n";
        }
 
-       out << "_resume:\n";
-
        if ( redFsm->errState != 0 ) {
                outLabelUsed = true;
                out << 
@@ -887,6 +885,8 @@ void TabCodeGen::writeExec()
                        "               goto _out;\n";
        }
 
+       out << "_resume:\n";
+
        if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       _acts = " << ARR_OFF( A(),  FSA() + "[" + CS() + "]" ) << ";\n"
@@ -950,6 +950,13 @@ void TabCodeGen::writeExec()
                        "\n";
        }
 
+       if ( redFsm->errState != 0 ) {
+               outLabelUsed = true;
+               out << 
+                       "       if ( " << CS() << " == " << redFsm->errState->id << " )\n"
+                       "               goto _out;\n";
+       }
+
        if ( hasEnd ) {
                out << 
                        "       if ( ++" << P() << " != " << PE() << " )\n"
index 1a5cee2..bbce5bb 100644 (file)
@@ -941,16 +941,13 @@ void JavaTabCodeGen::writeExec()
        if ( hasEnd )
                out << "        if ( " << P() << " != " << PE() << " ) {\n";
 
+       if ( redFsm->errState != 0 )
+               out << "        if ( " << CS() << " != " << redFsm->errState->id << " ) {\n";
+
        out << "        _resume: while ( true ) {\n";
 
        out << "        _again: do {\n";
 
-       if ( redFsm->errState != 0 ) {
-               out << 
-                       "       if ( " << CS() << " == " << redFsm->errState->id << " )\n"
-                       "               break _resume;\n";
-       }
-
        if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       _acts = " << FSA() << "[" << CS() << "]" << ";\n"
@@ -1009,6 +1006,12 @@ void JavaTabCodeGen::writeExec()
                        "\n";
        }
 
+       if ( redFsm->errState != 0 ) {
+               out << 
+                       "       if ( " << CS() << " == " << redFsm->errState->id << " )\n"
+                       "               break _resume;\n";
+       }
+
        if ( hasEnd ) {
                out << 
                        "       if ( ++" << P() << " == " << PE() << " )\n"
@@ -1022,6 +1025,10 @@ void JavaTabCodeGen::writeExec()
        /* Close the resume loop. */
        out << "        }\n";
 
+       /* The if guarding on the error state. */
+       if ( redFsm->errState != 0 )
+               out << "        }";
+
        /* The if guarding on empty string. */
        if ( hasEnd )
                out << "        }\n";
index 2f38681..bd556b1 100644 (file)
@@ -218,12 +218,12 @@ void RubyCodeGen::writeExec()
        if ( hasEnd ) 
                out << INDENT_S() << "_out.call if " << P() << " == " << PE() ;
 
+       if ( redFsm->errState != 0 ) 
+               out << INDENT_S() << "_out.call if " << CS() << " == " << redFsm->errState->id ;
+
        out << INDENT_S() << "_resume = nil" 
                << INDENT_S() << "callcc { |_cc| _resume = _cc }" ;
 
-       if ( redFsm->errState != 0) 
-               out << INDENT_S() << "_out.call if " << CS() << " == " << redFsm->errState->id ;
-
        if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
                        redFsm->anyActionCalls() || redFsm->anyActionRets() )
                out << INDENT_U() << "callcc do |_again|" ;
@@ -289,6 +289,9 @@ void RubyCodeGen::writeExec()
                        << INDENT_S();
        }
 
+       if ( redFsm->errState != 0 ) 
+               out << INDENT_S() << "_out.call if " << CS() << " == " << redFsm->errState->id ;
+
        out << INDENT_S() << P() << " += 1" ;
 
        if ( hasEnd )
diff --git a/test/erract7.rl b/test/erract7.rl
new file mode 100644 (file)
index 0000000..4b403ef
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * @LANG: c
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+%%{
+       machine foo;
+
+       action on_char  { printf("char: %c\n", *p); }
+       action on_err   { printf("err: %c\n", *p); }
+       action to_state { printf("to state: %c\n", *p); }
+
+       main := 'heXXX' $on_char $err(on_err) $to(to_state);
+}%%
+
+%% write data;
+
+int main()
+{
+       int cs;
+       char *p = "hello", *pe = p + strlen(p);
+       %%{
+               write init;
+               write exec;
+       }%%
+
+       printf( "rest: %s\n", p );
+
+       return 0;
+}
+
+#ifdef _____OUTPUT_____
+char: h
+to state: h
+char: e
+to state: e
+err: l
+rest: llo
+#endif
diff --git a/test/erract8.rl b/test/erract8.rl
new file mode 100644 (file)
index 0000000..c358d23
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * @LANG: java
+ */
+
+class erract8
+{
+       %%{
+               machine erract8;
+
+               action on_char  { System.out.println("char: " + data[p]); }
+               action on_err   { System.out.println("err: " + data[p]); }
+               action to_state { System.out.println("to state: " + data[p]); }
+
+               main := 'heXXX' $on_char $err(on_err) $to(to_state);
+       }%%
+
+       %% write data;
+
+       static void test( char data[] )
+       {
+               int cs, p = 0, pe = data.length;
+               int top;
+
+               %% write init;
+               %% write exec;
+
+               System.out.println("rest: " + data[p] + data[p+1] + data[p+2]);
+       }
+
+       public static void main( String args[] )
+       {
+               test( "hello".toCharArray() );
+       }
+}
+
+/* _____OUTPUT_____
+char: h
+to state: h
+char: e
+to state: e
+err: l
+rest: llo
+*/
diff --git a/test/erract9.rl b/test/erract9.rl
new file mode 100644 (file)
index 0000000..ccd848a
--- /dev/null
@@ -0,0 +1,43 @@
+#
+# @LANG: ruby
+#
+# Test the host language scanning for ruby.
+#
+
+%%{
+       machine erract9;
+
+       action on_char  { print("char: ", data[p..p], "\n"); }
+       action on_err   { print("err: ", data[p..p], "\n"); }
+       action to_state { print("to state: " , data[p..p], "\n"); }
+
+       main := 'heXXX' $on_char $err(on_err) $to(to_state);
+}%%
+
+%% write data;
+
+def run_machine( data )
+       p = 0;
+       pe = data.length
+       cs = 0
+
+       %% write init;
+       %% write exec;
+
+       print("rest: " , data[p..p+2], "\n")
+end
+
+inp = [
+               "hello\n",
+]
+
+inp.each { |str| run_machine(str) }
+
+=begin _____OUTPUT_____
+char: h
+to state: h
+char: e
+to state: e
+err: l
+rest: llo
+=end _____OUTPUT_____