From d9e3d8a5b3a02ead483f40a7726a24bf512fca6e Mon Sep 17 00:00:00 2001 From: thurston Date: Sat, 28 Apr 2007 21:10:32 +0000 Subject: [PATCH] Added a language-independent test case for the negative sense of conditions and the necessary transformation support. git-svn-id: http://svn.complang.org/ragel/trunk@206 052ea7fc-9027-0410-9066-f65837a77df0 --- test/cond7.rl | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ test/langtrans_c.txl | 19 +++++++++++- test/langtrans_java.txl | 19 +++++++++++- test/langtrans_ruby.txl | 18 ++++++++++- test/testcase.txl | 2 +- 5 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 test/cond7.rl diff --git a/test/cond7.rl b/test/cond7.rl new file mode 100644 index 0000000..3951af0 --- /dev/null +++ b/test/cond7.rl @@ -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_____ */ diff --git a/test/langtrans_c.txl b/test/langtrans_c.txl index 681baa2..b292c41 100644 --- a/test/langtrans_c.txl +++ b/test/langtrans_c.txl @@ -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 diff --git a/test/langtrans_java.txl b/test/langtrans_java.txl index 6fcf9c3..f13bcd5 100644 --- a/test/langtrans_java.txl +++ b/test/langtrans_java.txl @@ -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 diff --git a/test/langtrans_ruby.txl b/test/langtrans_ruby.txl index 009baae..5c1ce1a 100644 --- a/test/langtrans_ruby.txl +++ b/test/langtrans_ruby.txl @@ -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 diff --git a/test/testcase.txl b/test/testcase.txl index ff9bf43..4a8e5c4 100644 --- a/test/testcase.txl +++ b/test/testcase.txl @@ -110,7 +110,7 @@ define al_expr_extend end define define al_expr_op - '= | '+ | '- | '* | '/ | '== | '<= | '>= + '= | '+ | '- | '* | '/ | '== | '<= | '>= | '< | '> end define define al_term -- 2.7.4