Added a language-independent test case for the negative sense of conditions and
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sat, 28 Apr 2007 21:10:32 +0000 (21:10 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sat, 28 Apr 2007 21:10:32 +0000 (21:10 +0000)
the necessary transformation support.

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

test/cond7.rl [new file with mode: 0644]
test/langtrans_c.txl
test/langtrans_java.txl
test/langtrans_ruby.txl
test/testcase.txl

diff --git a/test/cond7.rl b/test/cond7.rl
new file mode 100644 (file)
index 0000000..3951af0
--- /dev/null
@@ -0,0 +1,82 @@
+/* 
+ * @LANG: indep
+ */
+int i;
+int c;
+%%
+
+%%{
+       machine foo;
+
+       action testi {i > 0}
+       action inc {
+               i = i - 1;
+               c = fc;
+               prints "item: ";
+               printi c;
+               prints "\n";
+       }
+
+       count = [0-9] @{ 
+               i = fc - '0'; 
+               prints "count: ";
+               printi i;
+               prints "\n";
+       };
+
+    sub =      
+               count # record the number of digits 
+               ( digit when testi @inc )* outwhen !testi;
+       
+    main := sub sub '\n';
+}%%
+
+/* _____INPUT_____ 
+"00\n"
+"019\n"
+"190\n"
+"1719\n"
+"1040000\n"
+"104000a\n"
+"104000\n"
+_____INPUT_____ */
+/* _____OUTPUT_____
+count: 0
+count: 0
+ACCEPT
+count: 0
+count: 1
+item: 57
+ACCEPT
+count: 1
+item: 57
+count: 0
+ACCEPT
+count: 1
+item: 55
+count: 1
+item: 57
+ACCEPT
+count: 1
+item: 48
+count: 4
+item: 48
+item: 48
+item: 48
+item: 48
+ACCEPT
+count: 1
+item: 48
+count: 4
+item: 48
+item: 48
+item: 48
+FAIL
+count: 1
+item: 48
+count: 4
+item: 48
+item: 48
+item: 48
+FAIL
+_____OUTPUT_____ */
index 681baa2..b292c41 100644 (file)
@@ -74,6 +74,12 @@ redefine al_host_block
        |       '{ [NL] [IN] [c_statements] [EX] '} [NL]
 end define
 
+redefine cond_action_stmt
+               'action [id] '{ [al_expr] '} [NL]
+       |       'action [id] '{ [c_expr] '} [NL]
+end redefine
+
+
 rule boolTypes
        replace [al_type_decl]
                'bool
@@ -277,6 +283,17 @@ rule actionTransC
                '{ CStmts '}
 end rule
 
+rule condTransC
+       replace [cond_action_stmt]
+               'action Id [id] '{ AlExpr [al_expr] '}
+       construct OptCExpr [opt c_expr]
+               _ [alExprToC AlExpr]
+       deconstruct OptCExpr
+               CExpr [c_expr]
+       by
+               'action Id '{ CExpr '}
+end rule
+
 function langTransC
        replace [program]
                Definitions [repeat action_lang_stmt]
@@ -291,7 +308,7 @@ function langTransC
                CDefinitions
                '%%
                CInitializations
-               RagelDef [actionTransC]
+               RagelDef [actionTransC] [condTransC]
 end function
 
 function main
index 6fcf9c3..f13bcd5 100644 (file)
@@ -87,6 +87,12 @@ redefine al_host_block
        |       '{ [NL] [IN] [java_statements] [EX] '} [NL]
 end define
 
+redefine cond_action_stmt
+               'action [id] '{ [al_expr] '} [NL]
+       |       'action [id] '{ [java_expr] '} [NL]
+end redefine
+
+
 function clearUnion Type [java_type_decl] Id [id] 
        replace [opt union]
                Union [union]
@@ -290,6 +296,17 @@ rule actionTransJava
                '{ JavaStmts '}
 end rule
 
+rule condTransJava
+       replace [cond_action_stmt]
+               'action Id [id] '{ AlExpr [al_expr] '}
+       construct OptJavaExpr [opt java_expr]
+               _ [alExprToJava AlExpr]
+       deconstruct OptJavaExpr
+               JavaExpr [java_expr]
+       by
+               'action Id '{ JavaExpr '}
+end rule
+
 rule machineName
        replace $ [machine_stmt]
                'machine _ [id] ';
@@ -312,7 +329,7 @@ function langTransJava
        construct JavaInitializations [repeat java_lang_stmt]
                _ [alToJava Initializations]
        construct NewRagelDef [ragel_def]
-               RagelDef [actionTransJava] [machineName]
+               RagelDef [actionTransJava] [condTransJava] [machineName]
        import ArrayInits [java_statements]
                ArrayInitStmts [repeat java_lang_stmt]
        by
index 009baae..5c1ce1a 100644 (file)
@@ -82,6 +82,11 @@ redefine al_host_block
        |       '{ [NL] [IN] [ruby_statements] [EX] '} [NL]
 end define
 
+redefine cond_action_stmt
+               'action [id] '{ [al_expr] '} [NL]
+       |       'action [id] '{ [ruby_expr] '} [NL]
+end redefine
+
 function initDecl1 VarDecl [al_variable_decl]
        deconstruct VarDecl
                'bool Id [id] ';
@@ -321,6 +326,17 @@ rule actionTransRuby
                '{ RubyStmts '}
 end rule
 
+rule condTransRuby
+       replace [cond_action_stmt]
+               'action Id [id] '{ AlExpr [al_expr] '}
+       construct OptRubyExpr [opt ruby_expr]
+               _ [alExprToRuby AlExpr]
+       deconstruct OptRubyExpr
+               RubyExpr [ruby_expr]
+       by
+               'action Id '{ RubyExpr '}
+end rule
+
 rule lowercaseMachine
        replace $ [machine_stmt]
                'machine Id [id] ';
@@ -339,7 +355,7 @@ function langTransRuby
        construct RubyInitializations [repeat ruby_lang_stmt]
                _ [alToRuby Initializations]
        construct NewRagelDef [ragel_def]
-               RagelDef [actionTransRuby] [lowercaseMachine]
+               RagelDef [actionTransRuby] [condTransRuby] [lowercaseMachine]
        import ArrayInits [ruby_statements]
                ArrayInitStmts [repeat ruby_lang_stmt]
        by
index ff9bf43..4a8e5c4 100644 (file)
@@ -110,7 +110,7 @@ define al_expr_extend
 end define
 
 define al_expr_op
-               '= | '+ | '- | '* | '/ | '== | '<= | '>=
+               '= | '+ | '- | '* | '/ | '== | '<= | '>= | '< | '>
 end define
 
 define al_term