Initialize Tizen 2.3
[external/ragel.git] / test / gotocallret1.rl
1 /*
2  * @LANG: indep
3  */
4
5 /*
6  * Demonstrate the use of goto, call and return. This machine expects either a
7  * lower case char or a digit as a command then a space followed by the command
8  * arg. If the command is a char, then the arg must be an a string of chars.
9  * If the command is a digit, then the arg must be a string of digits. This
10  * choice is determined by action code, rather than though transition
11  * desitinations.
12  */
13
14 char comm;
15 int top;
16 int stack[32];
17 %%
18 %%{
19         machine GotoCallRet;
20
21         # A reference to a state in an unused action caused a segfault in 5.8. */
22         action unusedAction { fentry(garble_line); }
23
24         action err_garbling_line { prints "error: garbling line\n"; }
25         action goto_main { fgoto main; }
26         action recovery_failed { prints "error: failed to recover\n"; }
27
28         # Error machine, consumes to end of 
29         # line, then starts the main line over.
30         garble_line := ( (any-'\n')*'\n') 
31                 >err_garbling_line
32                 @goto_main
33                 $/recovery_failed;
34
35         action hold_and_return {fhold; fret;}
36
37         # Look for a string of alphas or of digits, 
38         # on anything else, hold the character and return.
39         alp_comm := alpha+ $!hold_and_return;
40         dig_comm := digit+ $!hold_and_return;
41
42         # Choose which to machine to call into based on the command.
43         action comm_arg {
44                 if ( comm >= 'a' )
45                         fcall alp_comm;
46                 else 
47                         fcall dig_comm;
48         }
49
50         # Specifies command string. Note that the arg is left out.
51         command = (
52                 [a-z0-9] @{comm = fc;} ' ' @comm_arg '\n'
53         ) @{prints "correct command\n";};
54
55         # Any number of commands. If there is an 
56         # error anywhere, garble the line.
57         main := command* $!{fhold;fgoto garble_line;}; 
58 }%%
59 /* _____INPUT_____
60 "lkajsdf\n"
61 "2134\n"
62 "(\n"
63 "\n"
64 "*234234()0909 092 -234aslkf09`1 11\n"
65 "1\n"
66 "909\n"
67 "1 a\n"
68 "11 1\n"
69 "a 1\n"
70 "aa a\n"
71 "1 1\n"
72 "1 123456\n"
73 "a a\n"
74 "a abcdef\n"
75 "h"
76 "a aa1"
77 _____INPUT_____ */
78 /* _____OUTPUT_____
79 error: garbling line
80 ACCEPT
81 error: garbling line
82 ACCEPT
83 error: garbling line
84 ACCEPT
85 error: garbling line
86 ACCEPT
87 error: garbling line
88 ACCEPT
89 error: garbling line
90 ACCEPT
91 error: garbling line
92 ACCEPT
93 error: garbling line
94 ACCEPT
95 error: garbling line
96 ACCEPT
97 error: garbling line
98 ACCEPT
99 error: garbling line
100 ACCEPT
101 correct command
102 ACCEPT
103 correct command
104 ACCEPT
105 correct command
106 ACCEPT
107 correct command
108 ACCEPT
109 error: failed to recover
110 FAIL
111 error: garbling line
112 error: failed to recover
113 FAIL
114 _____OUTPUT_____ */