Bug fix: when fhold was used in scanner pattern actions which get executed on
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Wed, 25 Apr 2007 15:52:18 +0000 (15:52 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Wed, 25 Apr 2007 15:52:18 +0000 (15:52 +0000)
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.

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

ragel/xmlcodegen.cpp
ragel/xmlcodegen.h
test/patact.rl

index ede4d94..eba7e32 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2005, 2006 Adrian Thurston <thurston@cs.queensu.ca>
+ *  Copyright 2005-2007 Adrian Thurston <thurston@cs.queensu.ca>
  */
 
 /*  This file is part of Ragel.
@@ -206,26 +206,20 @@ void XMLCodeGen::writeText( InlineItem *item )
                out << "</text>";
 }
 
+bool isLmItem( InlineItem *context )
+{
+       return context != 0 && (
+               context->type == InlineItem::LmOnLast ||
+               context->type == InlineItem::LmOnNext ||
+               context->type == InlineItem::LmOnLagBehind ||
+               context->type == InlineItem::LmSwitch );
+}
+
 void XMLCodeGen::writeCtrlFlow( InlineItem *item, InlineItem *context )
 {
-       if ( context != 0 ) {
+       if ( isLmItem( context ) ) {
                out << "<sub_action>";
-
-               switch ( context->type ) {
-               case InlineItem::LmOnLast:
-                       out << "<exec><get_tokend></get_tokend></exec>";
-                       break;
-               case InlineItem::LmOnNext:
-                       out << "<exec><get_tokend></get_tokend></exec>";
-                       break;
-               case InlineItem::LmOnLagBehind:
-                       out << "<exec><get_tokend></get_tokend></exec>";
-                       break;
-               case InlineItem::LmSwitch:
-                       out << "<exec><get_tokend></get_tokend></exec>";
-                       break;
-               default: break;
-               }
+               out << "<exec><get_tokend></get_tokend></exec>";
        }
 
        switch ( item->type ) {
@@ -256,16 +250,13 @@ void XMLCodeGen::writeCtrlFlow( InlineItem *item, InlineItem *context )
        default: break;
        }
 
-       if ( context != 0 )
+       if ( isLmItem( context ) )
                out << "</sub_action>";
 }
 
 void XMLCodeGen::writePtrMod( InlineItem *item, InlineItem *context )
 {
-       if ( context != 0 && ( context->type == InlineItem::LmOnNext ||
-                       context->type == InlineItem::LmOnLagBehind ||
-                       context->type == InlineItem::LmSwitch ) )
-       {
+       if ( isLmItem( context ) ) {
                switch ( item->type ) {
                case InlineItem::Hold:
                        out << "<holdte></holdte>";
index 99b9853..6c80ac7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2005, 2006 Adrian Thurston <thurston@cs.queensu.ca>
+ *  Copyright 2005-2007 Adrian Thurston <thurston@cs.queensu.ca>
  */
 
 /*  This file is part of Ragel.
index c15d93d..d523fa5 100644 (file)
@@ -29,6 +29,10 @@ int val;
                '!';# => { prints "immdiate\n"; fgoto exec_test; };
        *|;
 
+       semi := |* 
+               ';' => { prints "in semi\n"; fgoto main; };
+       *|;
+
        main := |* 
                [a-z]+ => { prints "word (w/lbh)\n"; fhold; fgoto other; };
                [a-z]+ ' foil' => { prints "word (c/lbh)\n"; };
@@ -36,6 +40,7 @@ int val;
                '22' => { prints "num (w/switch)\n"; };
                [0-9]+ => { prints "num (w/switch)\n"; fhold; fgoto other;};
                [0-9]+ ' foil' => {prints "num (c/switch)\n"; };
+               ';' => { prints "going to semi\n"; fhold; fgoto semi;};
                '!' => { prints "immdiate\n"; fgoto exec_test; };
        *|;
 }%%
@@ -46,6 +51,7 @@ int val;
 "!abcd foix\n"
 "!abcd\nanother\n"
 "!123 foix\n"
+";"
 _____INPUT_____ */
 /* _____OUTPUT_____
 word (w/lbh)
@@ -87,5 +93,8 @@ space
 word
 space
 ACCEPT
+going to semi
+in semi
+ACCEPT
 _____OUTPUT_____ */