update(add) packaging directory and spec file from OBSTF:Private, OBS
[external/ragel.git] / test / langtrans_ruby.txl
index 82d6cc3..265426f 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] ';
@@ -116,10 +121,10 @@ end function
 
 function initDecl5 VarDecl [al_variable_decl]
        deconstruct VarDecl
-               'int Id [id] Union [union] ';
+               Type [al_type_decl] Id [id] Union [union] ';
        replace [repeat ruby_lang_stmt]
        by
-               Id '= '[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ';
+               Id '= '[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ';
 end function
 
 
@@ -135,6 +140,13 @@ function alStmtToRuby1 AlStmt [action_lang_stmt]
                        [initDecl5 VarDecl]
 end function
 
+function alTermToRuby
+       replace [al_term]
+               'first_token_char
+       by
+               'data '[ts]
+end function
+
 function alExprExtendToRuby AlExprExtend [repeat al_expr_extend]
        deconstruct AlExprExtend
                Op [al_expr_op] Term [al_term] Rest [repeat al_expr_extend]
@@ -142,7 +154,7 @@ function alExprExtendToRuby AlExprExtend [repeat al_expr_extend]
                _ [alExprExtendToRuby Rest]
        replace [repeat ruby_expr_extend]
        by
-               Op Term RubyRest
+               Op Term [alTermToRuby] RubyRest
 end function
 
 % Note: this doesn't go into the ( al_expr ) form of al_term.
@@ -152,7 +164,7 @@ function alExprToRuby AlExpr [al_expr]
        construct RubyExprExtend [repeat ruby_expr_extend]
                _ [alExprExtendToRuby AlExprExtend]
        construct Result [opt ruby_expr]
-               ALTerm RubyExprExtend
+               ALTerm [alTermToRuby] RubyExprExtend
        replace [opt ruby_expr]
        by
                Result 
@@ -232,6 +244,24 @@ function alStmtToRuby4b AlStmt [action_lang_stmt]
                'print '( String ') ';
 end function
 
+function alStmtToRuby4c AlStmt [action_lang_stmt]
+       deconstruct AlStmt
+               'printb Id [id] ';
+       replace [repeat ruby_lang_stmt]
+       by
+               '_a = Id '[0..pos-1] ';
+               'print '( '_a '. 'pack '( '"c*" ')  ') ';
+end function
+
+function alStmtToRuby4d AlStmt [action_lang_stmt]
+       deconstruct AlStmt
+               'print_token ';
+       replace [repeat ruby_lang_stmt]
+       by
+               '_m = 'data '[ts..te-1] ';
+               'print '( '_m '. 'pack '( '"c*" ') ') ';
+end function
+
 function alStmtToRuby5 AlStmt [action_lang_stmt]
        deconstruct AlStmt
                '{ AlSubStmts [repeat action_lang_stmt] '}
@@ -276,6 +306,8 @@ function alToRuby AlStmts [repeat action_lang_stmt]
                        [alStmtToRuby3 FirstStmt]
                        [alStmtToRuby4a FirstStmt]
                        [alStmtToRuby4b FirstStmt]
+                       [alStmtToRuby4c FirstStmt]
+                       [alStmtToRuby4d FirstStmt]
                        [alStmtToRuby5 FirstStmt]
                        [alStmtToRuby6 FirstStmt]
                        [fixCharLit]
@@ -295,6 +327,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] ';
@@ -313,7 +356,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