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