Introcuded the "eof" variable for indicating the end of file. The p variable is
[ragel.git] / test / testcase.txl
blob3369c15fdb4958a56e62206be79e20f064487a68
1 comments
2                 '#
3 end comments
5 tokens
6                 union "\[[(\\\c)#\]]*\]"
7 end tokens
9 compounds
10                 '%% '%%{ '}%% '== ':= '-> '<> '>= '<= '=>
11                 '|* '*|
12                 '>! '<! '$! '%! '@! '<>!
13                 '>/ '</ '$/ '%/ '@/ '<>/
14 end compounds
16 keys
17         'int 'bool 'true 'false 'char 'ptr
18         'if 'else 'printi 'prints 'printb 'print_token
19         'fc 'fpc 'fbreak 'fgoto 'fcall 'fret 'fhold 'fexec
20         'machine 'alphtype 'action
21         'first_token_char
22 end keys
24 define lang_indep
25                 [al_statements]
26                 '%% [NL]
27                 [al_statements]
28                 [ragel_def]
29 end define
31 define ragel_def
32                 '%%{ [NL] [IN]
33                         [ragel_program]
34                 [EX] '}%% [NL]
35 end define
37 define ragel_program
38                 [repeat statement]
39 end define 
41 define statement
42                 [machine_stmt]
43         |       [alphtype_stmt]
44         |       [action_stmt]
45         |       [cond_action_stmt]
46         |       [machine_def]
47         |       [machine_inst]
48 end define 
50 define machine_stmt
51                 'machine [id] '; [NL]
52 end define
54 define alphtype_stmt
55                 'alphtype [repeat id] '; [NL]
56 end define
58 define action_stmt
59                 'action [id] [al_host_block]
60 end define
62 define cond_action_stmt
63                 'action [id] '{ [al_expr] '} [NL]
64 end define
66 define al_statements
67                 [repeat action_lang_stmt]
68 end define
70 define action_lang_stmt
71                 [al_ragel_stmt]
72         |       [al_variable_decl]
73         |       [al_expr_stmt]
74         |       [al_if_stmt]
75         |       [al_print_stmt]
76         |       '{ [al_statements] '}
77 end define
79 define al_print_stmt
80                 [print_cmd] [al_expr] '; [NL]
81         |       'print_token '; [NL]
82 end define
84 define print_cmd
85                 'printi | 'prints | 'printb
86 end define
88 define al_variable_decl
89                 [al_type_decl] [id] [opt union] '; [NL]
90 end define
92 define al_array_decl
93                 '[ [number] ']
94 end define
96 define al_type_decl
97                 'int | 'bool | 'char | 'ptr
98 end define 
100 define al_expr_stmt
101                 [al_expr] '; [NL]
102 end define
104 define al_expr
105                 [al_term] [repeat al_expr_extend]
106 end define
108 define al_expr_extend
109                 [al_expr_op] [al_term]
110 end define
112 define al_expr_op
113                 '= | '+ | '- | '* | '/ | '== | '<= | '>= | '< | '>
114 end define
116 define al_term
117                 [al_term_base] [opt union]
118 end define
120 define al_term_base
121                 [id]
122         |       [SPOFF] [id] '( [SPON] [al_expr] ')
123         |       [opt al_sign] [number]
124         |       [stringlit] 
125         |       [charlit] 
126         |       'fc
127         |       'true
128         |       'false
129         |       '( [al_expr] ')
130         |       'first_token_char
131 end define
133 define al_sign
134                 '- | '+
135 end define
137 define al_if_stmt
138                 'if '( [al_expr] ') [NL] [IN]
139                         [action_lang_stmt] [EX]
140                 [opt al_else]
141 end define
143 define al_else
144                 'else [NL] [IN]
145                         [action_lang_stmt] [EX]
146 end define
148 define al_ragel_stmt
149                 'fbreak '; [NL]
150         |       'fhold '; [NL]
151         |       'fexec [repeat al_expr] '; [NL]
152         |       'fnext [id] '; [NL]
153         |       'fgoto [id] '; [NL]
154         |       'fcall [id] '; [NL]
155         |       'fnext '* [repeat al_expr] '; [NL]
156         |       'fgoto '* [repeat al_expr] '; [NL]
157         |       'fcall '* [repeat al_expr] '; [NL]
158         |       'fret '; [NL]
159 end define
161 define machine_def
162                 [id] '= [machine_expr] '; [NL]
163 end define
165 define machine_inst
166                 [id] ':= [machine_expr] '; [NL]
167 end define
169 define machine_expr
170                 [repeat machine_expr_item]
171 end define
173 define scanner_item
174                 [repeat machine_expr_item] '; [NL]
175 end define
177 define machine_expr_item
178                 [action_embed] [al_host_block]
179         |       '|* [repeat scanner_item] '*|
180         |       [not ';] [not '*|] [token]
181 end define
183 define al_host_block
184                 '{ [NL] [IN] [al_statements] [EX] '} [NL]
185 end define
187 define action_embed
188                 '> | '$ | '@ | '% | 
189                 '$! | '=>
190 end define