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