fix dependencies
[sbp.git] / tests / regression.tc
1 //testcase {
2 //    input  "x";
3 //    output "a:{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  "qxbambambam";
99     output "bam:{a bam:{a bam:{a x}}}";
100
101     s   = "q" z
102     z   = a z ^"bam"
103         | ^"x"
104     a   = a:: ()
105 }
106
107 testcase {
108     input  "baaaa";
109     output "s2:{b0 a:{a:{epsilon}}}";
110     output "b:{a:{a:{epsilon}} epsilon}";
111     s   = s2:: b t
112         | ^"b" t b
113     t   = ^"a" t "a"
114         | epsilon:: ()
115     b   = b0:: "b"
116         | epsilon:: ()
117 }
118
119 testcase {
120     input  "qaq";
121     output "q:{a:{s1:{epsilon}}}";
122
123     s   = ^"q" x "q"
124     x   = ^"a" a
125         | epsilon:: ()
126     a   = s1:: x
127 }
128
129 testcase {
130     input "baa";
131     output "s1:{a2:{a2:{a0 b0} b0}}";
132
133     s   = s1:: "b" a
134     a   = a2:: "a" a b
135         | a0:: ()
136     b   = b0:: ()
137 }
138
139 testcase {
140     input  "aaa";
141
142     output "s3:{s3:{epsilon a0 epsilon epsilon} epsilon epsilon epsilon}";
143     output "s3:{s3:{epsilon epsilon epsilon epsilon} a0 epsilon epsilon}";
144     output "s3:{s3:{epsilon epsilon a0 epsilon} epsilon epsilon epsilon}";
145     output "s3:{s3:{epsilon epsilon epsilon a0} epsilon epsilon epsilon}";
146     output "s3:{epsilon epsilon a0 a0}";
147     output "s3:{s3:{s3:{epsilon epsilon epsilon epsilon} epsilon epsilon epsilon} epsilon epsilon epsilon}";
148     output "s3:{s3:{epsilon epsilon epsilon epsilon} epsilon epsilon a0}";
149     output "s3:{s3:{epsilon epsilon epsilon epsilon} epsilon a0 epsilon}";
150     output "s3:{epsilon a0 epsilon a0}";
151     output "s3:{epsilon a0 a0 epsilon}";
152
153     s   = s3:: "a" s a a a
154         | epsilon:: ()
155     a   = a0:: "a"
156         | epsilon:: ()
157 }
158
159 testcase {
160     input "aa";
161     output "poo:{poo:{poox poox} poox}";
162     output "poo:{poox poo:{poox poox}}";
163     s   = poo::  s s "a"
164         | poox:: ()
165 }
166
167 testcase {
168     input "baa";
169     output "s:{aa:{aa:{a b} b}}";
170     s   = s:: "b" a
171     a   = aa:: "a" a b
172         | a:: ()
173     b   = b:: ()
174 }
175
176 testcase {
177     input "aaab";
178     output "sx:{b aa:{aa:{b b} b}}";
179     s   = sx:: b d "a" "b"
180         | sy:: "a" d "a" d
181     d   = aa:: "a" a b
182     a   = aa:: "a" b b
183         | a::  ()
184     b   = b::  ()
185 }
186
187 testcase {
188     input "a+(b*c)";
189     output "+:{{a} *:{{b} {c}}}";
190
191     s     = r
192     r     = id
193           | r ^"*" r
194           | r ^"+" r
195           | "(" r ")"
196     id    = [a-z]++
197 }
198
199 testcase {
200     input "a+b-d*c";
201     output "plus:{stringify:{{a}} minus:{stringify:{{b}} times:{stringify:{{d}} stringify:{{c}}}}}";
202     output "times:{plus:{stringify:{{a}} minus:{stringify:{{b}} stringify:{{d}}}} stringify:{{c}}}";
203     output "plus:{stringify:{{a}} times:{minus:{stringify:{{b}} stringify:{{d}}} stringify:{{c}}}}";
204     output "times:{minus:{plus:{stringify:{{a}} stringify:{{b}}} stringify:{{d}}} stringify:{{c}}}";
205     output "minus:{plus:{stringify:{{a}} stringify:{{b}}} times:{stringify:{{d}} stringify:{{c}}}}";
206     w    = " "
207     l    = id
208     s    = assign:: l "=" q
209          | q
210     q    = id
211          | assign:: l "=" q
212          | minus:: q "-" q
213          | plus:: q "+" q
214          | times:: q "*" q
215          | "(" q ")"
216     id     = stringify:: idl++
217     idl    = [a-d]
218 }
219
220 //testcase {
221 //    input "a*b*c";
222 //    output "times:{stringify:{{a}} times:{stringify:{{b}} stringify:{{c}}}}";
223 //    w    = " "
224 //    l    = id
225 //    s    = l "=" r  => "assign"
226 //         | r
227 //    r    = l
228 //         | l "=" r       => "assign"
229 //         | r "+" r       => "plus"
230 //         | (r) "*" r       => "times"
231 //         | "(" r ")"
232 //         | r r           => "times"
233 //    id     = idl++       => "stringify"
234 //    idl    = [a-d]
235 //}
236
237 testcase {
238     input "a+b*c";
239     output "plus:{stringify:{{a}} times:{stringify:{{b}} stringify:{{c}}}}";
240     w    = " "
241     l    = id
242     s    = assign:: l "=" r
243          | r
244     r    = l
245          | assign:: l "=" r
246          | plus:: r "+" r
247          > times:: r "*" r
248          | "(" r ")"
249          | times:: r r
250     id     = stringify:: idl++
251     idl    = [a-d]
252 }
253
254 testcase {
255   input "aa bb";
256   output "{q:{{a a}} q:{{b b}}}";
257
258   s    = q */ ws
259   ws   = " "*
260   q    = q:: [a-z]++
261 }
262
263 testcase {
264
265     input "
266
267
268
269  while x>0
270     while y>0
271        foo()
272           bar()
273
274
275  while x>0
276     while y>0
277           foo()
278         bar()
279
280
281
282 ";
283   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}}}}";
284
285 indent    = ww
286 outdent   = " "  outdent " "
287           | " "  ((~[])*)  "\n"
288
289 w          = " " | "\n" | "\r"
290 ws         = w*
291 ww         = sp*
292 sp         = " "
293 any        = (~[])*
294
295 s          = smt:: ws! statement ws! statement ws!
296
297 block       =        "\n"! indent!  blockBody
298            &~        "\n"! (" " outdent! " ") (~[\ ])! ((~[])*)!
299
300 blockBody   =       statement
301             > sbb:: statement ws blockBody
302
303 statement   = call
304             | ^"while" expr block /ws
305
306 expr        = ident
307             | call
308             | expr ^">" expr   /ws
309             | num
310
311 call        = expr "()"        /ws
312
313 num         = [0-9]++
314
315 ident       = [a-z]++ &~ keyword
316 keyword     = "if" | "then" | "else" | "while"
317
318
319
320 }
321
322
323
324 testcase {
325     input "abc                         ";
326
327     s     = s2:: q " "*
328     q     = a3:: [a-z] [a-z] [a-z]
329          &~ (~[])! "b" ((~[])*)!
330 }
331
332 testcase {
333     input "abc                         ";
334     output "s:{a b c}";
335
336     s     = s:: [a-z] [a-z] [a-z] " "*
337 }
338
339 testcase {
340
341     input "a+2";
342     output "Plus:{left:{Foo} right:{{2}}}";
343
344     s       = Expr
345     Expr    = [0-9]++
346             | Plus:: (left::Expra) "+" (right::Expr)
347     Expra   = Foo:: ("a" | "b")
348
349 }
350
351 testcase {
352     input "aaaaa";
353     output "top:{a q:{{a a a}} a}";
354
355     s = top:: z (q::"a"*) z
356     z = a:: "a"
357 }
358
359 testcase {
360     input  "if (x) if (y) z else q";
361     output "if:{ident:{{x}} else:{if:{ident:{{y}} then:{ident:{{z}}}} ident:{{q}}}}";
362
363     s      = Expr
364     Expr   = if::     "if" "(" Expr ")" IfBody     /ws
365            | ident::  [a-z]++
366     IfBody = else::   Expr            "else"  Expr /ws
367            | then::   Expr &~   ((~[])* "else" Expr! /ws)
368     ws     = [ ]**
369 }
370
371
372 testcase {
373     input "12111211";
374     output "ac:{{2 1 2 1}}";
375     //output "a:{{2 1 2 1}}";
376     //output "c:{{c:{1 1} c:{1 1}}}";
377
378     s   = ab:: ab
379         | ac:: ac
380         | bc:: bc
381         //| a  =>  "a"
382         //| b  =>  "b"
383         //| c  =>  "c"
384     ab   = a & b
385     ac   = a & c
386     bc   = b & c
387     a   = ("1" x)*
388     b   = ("b":: x "2")*
389     c   = ("c":: x "2" x "1")*
390     x   = [123]
391 }
392
393
394 //testcase {
395 //    input "ab";
396 //    
397 //    s = a:"a" b:"b"
398 //}
399