new checkpoint
[sbp.git] / tests / regression.tc
1 //testcase {
2 //    input  "x";
3 //    output "a1:{x}";
4 //
5 //    s ::= a        => a1
6 //    a ::= s        => s1
7 //    a ::= ^"x"
8 //}
9 //
10 //testcase {
11 //    input  "x";
12 //    output "x";
13 //    output "s2:{s2:{s0 s0} x}";
14 //    output "s2:{s0 x}";
15 //
16 //
17 //    s ::= s s      => s2
18 //    s ::= ^"x"
19 //    s ::= ()       => s0
20 //}
21
22 tibcase {
23     input 
24 "
25   hello 
26     there
27     how
28       { are }
29 ";
30     output "yep:{are}";
31
32     s        ::= { Hello } => "yep"
33     w        ::= " " | "\n"
34     ws      !::= w**
35     Hello    ::= "hello" ws { "there" "how" { "are" } }
36 }
37
38
39 testcase {
40     input "ab c";
41     output "1:{{a b} {c}}";
42
43     s   ::= ids
44     ids ::= id (" " ids &~ id [~]*) => "1"
45           | id (    ids &~ id [~]*) => "2"
46           | id
47     id  ::= [a-z]++
48 }
49
50 testcase {
51     input "ab c";
52
53     output "2:{{a} 1:{{b} {c}}}";
54     output "1:{{a b} {c}}";
55
56     s   ::= ids
57     ids ::= id " " ids => "1"
58           | id     ids => "2"
59           | id
60     id  ::= [a-z]+
61 }
62
63 testcase {
64     input "aaabbbccc";
65     output "ab";
66
67     s   ::= ab & dc
68     ab  ::= a b       => ab
69     dc  ::= d c       => dc
70     a   ::= "a" a     | ()
71     b   ::= "b" b "c" | ()
72     c   ::= "c" c     | ()
73     d   ::= "a" d "b" | ()
74 }
75
76 testcase {
77     input "aaabbbbccc";
78
79     s   ::= ab & dc
80     ab !::= a b       => ab
81     dc !::= d c       => dc
82     a   ::= "a" a     | ()
83     b   ::= "b" b "c" | ()
84     c   ::= "c" c     | ()
85     d   ::= "a" d "b" | ()
86 }
87
88 testcase {
89     input "12111211";
90     output "ac:{{2 1 2 1}}";
91     //output "a:{{2 1 2 1}}";
92     //output "c:{{c:{1 1} c:{1 1}}}";
93
94     s ::= ab => "ab"
95         | ac => "ac"
96         | bc => "bc"
97         //| a  =>  "a"
98         //| b  =>  "b"
99         //| c  =>  "c"
100     ab ::= a & b
101     ac ::= a & c
102     bc ::= b & c
103     a ::= ("1" x)*
104     b ::= (x "2" => "b")*
105     c ::= (x "2" x "1" => "c")*
106     x ::= [123]
107 }
108
109 testcase {
110     input  "xbambambam";
111     output "bam:{a bam:{a bam:{a x:{x}}}}";
112
113     s ::= a s ^"bam"
114     s ::= ^"x"
115     a ::= ()       => "a"
116 }
117
118 testcase {
119     input  "baaaa";
120     output "s2:{b0 a:{a:{epsilon}}}";
121     output "b:{a:{a:{epsilon}} epsilon}";
122     s ::= b t        => "s2"
123         | ^"b" t b
124     t ::= ^"a" t "a"
125         | ()         => "epsilon"
126     b ::= "b"        => "b0"
127         | ()         => "epsilon"
128 }
129
130 testcase {
131     input  "qaq";
132     output "q:{a:{s1:{epsilon}}}";
133
134     s ::= ^"q" x "q"
135     x ::= ^"a" a
136     x ::= ()        => "epsilon"
137     a ::= x         => "s1"
138 }
139
140 testcase {
141     input "baa";
142     output "s1:{a2:{a2:{a0 b0} b0}}";
143
144     s ::= "b" a     => "s1"
145     a ::= "a" a b   => "a2"
146         | ()        => "a0"
147     b ::= ()        => "b0"
148 }
149
150 testcase {
151     input  "aaa";
152
153     output "s3:{s3:{epsilon a0 epsilon epsilon} epsilon epsilon epsilon}";
154     output "s3:{s3:{epsilon epsilon epsilon epsilon} a0 epsilon epsilon}";
155     output "s3:{s3:{epsilon epsilon a0 epsilon} epsilon epsilon epsilon}";
156     output "s3:{s3:{epsilon epsilon epsilon a0} epsilon epsilon epsilon}";
157     output "s3:{epsilon epsilon a0 a0}";
158     output "s3:{s3:{s3:{epsilon epsilon epsilon epsilon} epsilon epsilon epsilon} epsilon epsilon epsilon}";
159     output "s3:{s3:{epsilon epsilon epsilon epsilon} epsilon epsilon a0}";
160     output "s3:{s3:{epsilon epsilon epsilon epsilon} epsilon a0 epsilon}";
161     output "s3:{epsilon a0 epsilon a0}";
162     output "s3:{epsilon a0 a0 epsilon}";
163
164     s ::= "a" s a a a => "s3"
165         | ()          => "epsilon"
166     a ::= "a"         => "a0"
167         | ()          => "epsilon"
168 }
169
170 testcase {
171     input "aa";
172     output "poo:{poo:{poox poox} poox}";
173     output "poo:{poox poo:{poox poox}}";
174     s ::= s s "a"  => "poo"
175         | ()       => "poox"
176 }
177
178 testcase {
179     input "baa";
180     output "s:{aa:{aa:{a b} b}}";
181     s ::= "b" a      => "s"
182     a ::= "a" a b    => "aa"
183     a ::= ()         => "a"
184     b ::= ()         => "b"
185 }
186
187 testcase {
188     input "aaab";
189     output "sx:{b aa:{aa:{b b} b}}";
190     s ::= b d "a" "b"  => "sx"
191     s ::= "a" d "a" d  => "sy"
192     d ::= "a" a b      => "aa"
193     a ::= "a" b b      => "aa"
194     a ::= ()           => "a"
195     b ::= ()           => "b"
196 }
197
198 testcase {
199     input "a+(b*c)";
200     output "+:{{a} *:{{b} {c}}}";
201
202     s   ::= r
203     r   ::= id
204           | r ^"*" r
205           | r ^"+" r
206           | "(" r ")"
207     id  ::= [a-z]++
208 }
209
210 testcase {
211     input "a+b-d*c";
212     output "plus:{stringify:{{a}} minus:{stringify:{{b}} times:{stringify:{{d}} stringify:{{c}}}}}";
213     output "times:{plus:{stringify:{{a}} minus:{stringify:{{b}} stringify:{{d}}}} stringify:{{c}}}";
214     output "plus:{stringify:{{a}} times:{minus:{stringify:{{b}} stringify:{{d}}} stringify:{{c}}}}";
215     output "times:{minus:{plus:{stringify:{{a}} stringify:{{b}}} stringify:{{d}}} stringify:{{c}}}";
216     output "minus:{plus:{stringify:{{a}} stringify:{{b}}} times:{stringify:{{d}} stringify:{{c}}}}";
217     w  ::= " "
218     l  ::= id
219     s  ::= l "=" q  => "assign"
220          | q
221     q  ::= id
222          | l "=" q       => "assign"
223          | q "-" q       => "minus"
224          | q "+" q       => "plus"
225          | q "*" q       => "times"
226          | "(" q ")"
227     id   ::= idl++       => "stringify"
228     idl  ::= [a-d]
229 }
230
231 testcase {
232     input "a*b*c";
233     output "times:{stringify:{{a}} times:{stringify:{{b}} stringify:{{c}}}}";
234     w  ::= " "
235     l  ::= id
236     s  ::= l "=" r  => "assign"
237          | r
238     r  ::= l
239          | l "=" r       => "assign"
240          | r "+" r       => "plus"
241          | (r) "*" r       => "times"
242          | "(" r ")"
243          | r r           => "times"
244     id   ::= idl++       => "stringify"
245     idl  ::= [a-d]
246 }
247
248 testcase {
249     input "a+b*c";
250     output "plus:{stringify:{{a}} times:{stringify:{{b}} stringify:{{c}}}}";
251     w  ::= " "
252     l  ::= id
253     s  ::= l "=" r  => "assign"
254          | r
255     r  ::= l
256          | l "=" r       => "assign"
257          | r "+" r       => "plus"
258          > r "*" r       => "times"
259          | "(" r ")"
260          | r r           => "times"
261     id   ::= idl++       => "stringify"
262     idl  ::= [a-d]
263 }
264
265 testcase {
266
267     input "
268
269
270  while x>0
271    while y>0
272     foo()
273      bar()
274
275  while x>0
276    while y>0
277     foo()
278    bar()
279
280
281 ";
282     output "smt:{while:{>:{{x} {0}} while:{>:{{y} {0}} sbb:{{f o o} {b a r}}}}}";
283     output "smt:{while:{>:{{x} {0}} sbb:{while:{>:{{y} {0}} {f o o}} {b a r}}}}";
284
285 indent  !::= ww
286 outdent !::= " "  outdent " "
287            | " "  ([~]*)  "\n"
288
289 any      !::= [~]*
290 s         ::= any "\n\n" ww statement ww "\n\n" any => smt
291 ww       !::= sp*
292 ws       !::= sp**
293 sp        ::= " "
294
295 block     ::= "\n" indent  blockBody
296            &~ "\n" outdent [~\ ] [~]*
297
298 blockBody ::= statement
299             > statement blockBody /ws => "sbb"
300
301 statement ::= call
302             | ^"while" expr block /ws
303
304 expr      ::= ident
305             | call
306             | expr ^">" expr   /ws
307             | num
308
309 call      ::= expr "()"        /ws
310
311 num       ::= [0-9]++
312
313 ident     ::= [a-z]++ &~ keyword
314 keyword   ::= "if" | "then" | "else" | "while"
315
316 w         ::= " " | "\n" | "\r"
317 ws        ::= w*
318
319
320 }
321
322 testcase {
323   input "aa bb";
324   output "{q:{{a a}} q:{{b b}}}";
325
326   s  ::= q */ ws
327   ws ::= " "*
328   q  ::= [a-z]++ => "q"
329 }