85 self assert: parser parse: 'c' end: 0. |
85 self assert: parser parse: 'c' end: 0. |
86 |
86 |
87 ! |
87 ! |
88 |
88 |
89 testChoiceOrder |
89 testChoiceOrder |
90 parser := (('a' asParser token , 'b' asParser token) / 'a' asParser token) |
90 parser := compiler compile: (('a' asParser token , 'b' asParser token) / 'a' asParser token). |
91 compileUsingCompiler:compiler. |
91 |
92 |
92 |
93 self assert: parser parse: 'ab'. |
93 self assert: parser parse: 'ab'. |
94 self assert: result first inputValue = 'a'. |
94 self assert: result first inputValue = 'a'. |
95 self assert: result second inputValue = 'b'. |
95 self assert: result second inputValue = 'b'. |
96 |
96 |
97 self assert: parser parse: 'a'. |
97 self assert: parser parse: 'a'. |
98 self assert: result inputValue = 'a'. |
98 self assert: result inputValue = 'a'. |
99 |
99 |
100 self assert: parser fail: '_'. |
100 self assert: parser fail: '_'. |
101 |
101 |
|
102 "Modified: / 07-09-2015 / 12:36:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
102 ! |
103 ! |
103 |
104 |
104 testChoiceOrder2 |
105 testChoiceOrder2 |
105 | p1 p2 | |
106 | p1 p2 | |
106 p1 := 'a' asParser token, 'b' asParser token. |
107 p1 := 'a' asParser token, 'b' asParser token. |
107 p2 := 'b' asParser token / 'a' asParser token. |
108 p2 := 'b' asParser token / 'a' asParser token. |
108 |
109 |
109 parser := p1 / p2 compileUsingCompiler:compiler. |
110 parser := compiler compile: (p1 / p2). |
110 |
111 |
111 self assert: parser parse: 'ab'. |
112 self assert: parser parse: 'ab'. |
112 self assert: result first inputValue = 'a'. |
113 self assert: result first inputValue = 'a'. |
113 self assert: result second inputValue = 'b'. |
114 self assert: result second inputValue = 'b'. |
114 |
115 |
166 self assert: parser fail: 'c'. |
167 self assert: parser fail: 'c'. |
167 |
168 |
168 ! |
169 ! |
169 |
170 |
170 testCompileAnd |
171 testCompileAnd |
171 parser := (('foo' asParser token and) / ('bar' asParser token and)) |
172 parser := compiler compile:(('foo' asParser token and) / ('bar' asParser token and)) |
172 , 'bar' asParser token compileUsingCompiler:compiler. |
173 , 'bar' asParser token. |
173 |
174 |
174 self assert: parser parse: 'bar'. |
175 self assert: parser parse: 'bar'. |
175 self assert: result second inputValue = 'bar'. |
176 self assert: result second inputValue = 'bar'. |
|
177 |
|
178 "Modified: / 07-09-2015 / 12:36:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
176 ! |
179 ! |
177 |
180 |
178 testCompileChoice |
181 testCompileChoice |
179 parser := ('foo' asParser / 'bar' asParser) token |
182 parser := compiler compile: ('foo' asParser / 'bar' asParser) token. |
180 compileUsingCompiler:compiler. |
183 |
181 |
|
182 self assert: parser parse: 'foo'. |
184 self assert: parser parse: 'foo'. |
183 self assert: result inputValue = 'foo'. |
185 self assert: result inputValue = 'foo'. |
184 self assert: parser parse: 'bar'. |
186 self assert: parser parse: 'bar'. |
185 self assert: result inputValue = 'bar'. |
187 self assert: result inputValue = 'bar'. |
186 self assert: parser fail: '_'. |
188 self assert: parser fail: '_'. |
187 |
189 |
|
190 "Modified: / 07-09-2015 / 12:35:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
188 ! |
191 ! |
189 |
192 |
190 testCompileChoice2 |
193 testCompileChoice2 |
191 parser := ('foo' asParser token trim / 'bar' asParser token trim) |
194 parser := compiler compile:('foo' asParser token trim / 'bar' asParser token trim). |
192 compileUsingCompiler:compiler. |
|
193 |
195 |
194 self assert: parser parse: 'foo'. |
196 self assert: parser parse: 'foo'. |
195 self assert: result inputValue = 'foo'. |
197 self assert: result inputValue = 'foo'. |
196 self assert: parser parse: 'bar'. |
198 self assert: parser parse: 'bar'. |
197 self assert: result inputValue = 'bar'. |
199 self assert: result inputValue = 'bar'. |
198 self assert: parser fail: '_'. |
200 self assert: parser fail: '_'. |
199 |
201 |
|
202 "Modified: / 07-09-2015 / 12:36:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
200 ! |
203 ! |
201 |
204 |
202 testCompileComplex1 |
205 testCompileComplex1 |
203 parser := ('foo' asParser token , 'bar' asParser token) |
206 parser := compiler compile: ('foo' asParser token , 'bar' asParser token) |
204 / ('foo' asParser token , 'baz' asParser token) |
207 / ('foo' asParser token , 'baz' asParser token). |
205 compileUsingCompiler:compiler. |
|
206 |
208 |
207 self assert: parser parse: 'foobar'. |
209 self assert: parser parse: 'foobar'. |
208 self assert: result second inputValue = 'bar'. |
210 self assert: result second inputValue = 'bar'. |
209 |
211 |
210 self assert: parser parse: 'foobaz'. |
212 self assert: parser parse: 'foobaz'. |
211 self assert: result second inputValue = 'baz'. |
213 self assert: result second inputValue = 'baz'. |
212 |
214 |
213 self assert: parser fail: 'foobaq'. |
215 self assert: parser fail: 'foobaq'. |
214 |
216 |
|
217 "Modified: / 07-09-2015 / 12:36:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
215 ! |
218 ! |
216 |
219 |
217 testCompileComplex2 |
220 testCompileComplex2 |
218 parser := ('foo' asParser token , 'bar' asParser token) star , 'foo' asParser token |
221 parser := compiler compile:('foo' asParser token , 'bar' asParser token) star , 'foo' asParser token. |
219 compileUsingCompiler:compiler. |
|
220 |
222 |
221 self assert: parser parse: 'foobarfoobarfoo'. |
223 self assert: parser parse: 'foobarfoobarfoo'. |
222 self assert: parser parse: 'foo'. |
224 self assert: parser parse: 'foo'. |
223 |
225 |
224 self assert: parser fail: 'bar'. |
226 self assert: parser fail: 'bar'. |
225 |
227 |
|
228 "Modified: / 07-09-2015 / 12:37:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
226 ! |
229 ! |
227 |
230 |
228 testCompileComplex3 |
231 testCompileComplex3 |
229 parser := (('foo' asParser token , 'bar' asParser token) star , 'foo' asParser token) |
232 parser := compiler compile: (('foo' asParser token , 'bar' asParser token) star , 'foo' asParser token) |
230 / ('foo' asParser token , 'baz' asParser token) |
233 / ('foo' asParser token , 'baz' asParser token). |
231 compileUsingCompiler:compiler. |
234 |
232 |
235 |
233 self assert: parser parse: 'foobarfoobarfoo'. |
236 self assert: parser parse: 'foobarfoobarfoo'. |
234 self assert: parser parse: 'foo'. |
237 self assert: parser parse: 'foo'. |
235 |
238 |
236 self assert: parser fail: 'bar'. |
239 self assert: parser fail: 'bar'. |
237 |
240 |
|
241 "Modified: / 07-09-2015 / 12:37:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
238 ! |
242 ! |
239 |
243 |
240 testCompileEmptytoken |
244 testCompileEmptytoken |
241 | start stop epsilon | |
245 | start stop epsilon | |
242 start := $( asParser token. |
246 start := $( asParser token. |
243 stop := $) asParser token. |
247 stop := $) asParser token. |
244 epsilon := '' asParser token. |
248 epsilon := '' asParser token. |
245 |
249 |
246 self should: [ |
250 self should: [ |
247 (start , epsilon , stop) compileUsingCompiler:compiler. |
251 compiler compile: (start , epsilon , stop) |
248 ] raise: Exception. |
252 ] raise: Exception. |
249 " |
253 " |
250 self assert: parser parse: '()'. |
254 self assert: parser parse: '()'. |
251 self assert: parser fail: '('. |
255 self assert: parser fail: '('. |
252 " |
256 " |
|
257 |
|
258 "Modified: / 07-09-2015 / 12:40:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
253 ! |
259 ! |
254 |
260 |
255 testCompileLiteral |
261 testCompileLiteral |
256 parser := 'foo' asParser token compileUsingCompiler:compiler. |
262 parser := compiler compile: ('foo' asParser token). |
257 |
263 |
258 self assert: parser parse: 'foo'. |
264 self assert: parser parse: 'foo'. |
259 self assert: result inputValue = 'foo'. |
265 self assert: result inputValue = 'foo'. |
260 self assert: parser fail: 'boo'. |
266 self assert: parser fail: 'boo'. |
261 ! |
267 ! |
262 |
268 |
263 testCompileSequence |
269 testCompileSequence |
264 parser := ('foo' asParser token) , ('bar' asParser token) |
270 parser := compiler compile: ('foo' asParser token) , ('bar' asParser token). |
265 compileUsingCompiler:compiler. |
271 |
266 |
272 |
267 self assert: parser parse: 'foobar'. |
273 self assert: parser parse: 'foobar'. |
268 self assert: result first inputValue = 'foo'. |
274 self assert: result first inputValue = 'foo'. |
269 self assert: result second inputValue = 'bar'. |
275 self assert: result second inputValue = 'bar'. |
|
276 |
|
277 "Modified: / 07-09-2015 / 12:40:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
270 ! |
278 ! |
271 |
279 |
272 testCompileSequence2 |
280 testCompileSequence2 |
273 parser := ('foo' asParser trimmingToken) , ('bar' asParser trimmingToken) |
281 parser := compiler compile: ('foo' asParser trimmingToken) , ('bar' asParser trimmingToken). |
274 compileUsingCompiler:compiler. |
282 |
275 |
283 |
276 self assert: parser parse: 'foobar'. |
284 self assert: parser parse: 'foobar'. |
277 self assert: result first inputValue = 'foo'. |
285 self assert: result first inputValue = 'foo'. |
278 self assert: result second inputValue = 'bar'. |
286 self assert: result second inputValue = 'bar'. |
279 |
287 |
282 self assert: result second inputValue = 'bar'. |
290 self assert: result second inputValue = 'bar'. |
283 |
291 |
284 self assert: parser parse: ' foo bar'. |
292 self assert: parser parse: ' foo bar'. |
285 self assert: result first inputValue = 'foo'. |
293 self assert: result first inputValue = 'foo'. |
286 self assert: result second inputValue = 'bar'. |
294 self assert: result second inputValue = 'bar'. |
|
295 |
|
296 "Modified: / 07-09-2015 / 12:40:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
287 ! |
297 ! |
288 |
298 |
289 testCompileSequence3 |
299 testCompileSequence3 |
290 parser := ('foo' asParser trimmingToken) , ('bar' asParser trimmingToken) |
300 parser := compiler compile: ('foo' asParser trimmingToken) , ('bar' asParser trimmingToken) |
291 , ('baz' asParser trimmingToken) compileUsingCompiler:compiler. |
301 , ('baz' asParser trimmingToken). |
292 |
302 |
293 self assert: parser parse: 'foobarbaz'. |
303 self assert: parser parse: 'foobarbaz'. |
294 self assert: result first inputValue = 'foo'. |
304 self assert: result first inputValue = 'foo'. |
295 self assert: result second inputValue = 'bar'. |
305 self assert: result second inputValue = 'bar'. |
296 |
306 |
297 self assert: parser parse: ' foo bar baz '. |
307 self assert: parser parse: ' foo bar baz '. |
298 self assert: result first inputValue = 'foo'. |
308 self assert: result first inputValue = 'foo'. |
299 self assert: result second inputValue = 'bar'. |
309 self assert: result second inputValue = 'bar'. |
300 self assert: result third inputValue = 'baz'. |
310 self assert: result third inputValue = 'baz'. |
|
311 |
|
312 "Modified: / 07-09-2015 / 12:39:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
301 ! |
313 ! |
302 |
314 |
303 testCompileStar |
315 testCompileStar |
304 parser := 'foo' asParser token star compileUsingCompiler:compiler. |
316 parser := compiler compile: ('foo' asParser token star). |
305 |
317 |
306 self assert: parser parse: 'foo'. |
318 self assert: parser parse: 'foo'. |
307 self assert: result first inputValue = 'foo'. |
319 self assert: result first inputValue = 'foo'. |
308 |
320 |
309 self assert: parser parse: 'boo' end: 0. |
321 self assert: parser parse: 'boo' end: 0. |
310 self assert: result isEmpty. |
322 self assert: result isEmpty. |
311 ! |
323 ! |
312 |
324 |
313 testCompileStar2 |
325 testCompileStar2 |
314 parser := ('foo' asParser token , 'bar' asParser token) star |
326 parser := compiler compile: ('foo' asParser token , 'bar' asParser token) star. |
315 compileUsingCompiler:compiler. |
327 |
316 |
328 |
317 self assert: parser parse: 'foobar'. |
329 self assert: parser parse: 'foobar'. |
318 self assert: context tokenReads size = 1. |
330 self assert: context tokenReads size = 1. |
319 |
331 |
320 self assert: parser parse: 'bar' end: 0. |
332 self assert: parser parse: 'bar' end: 0. |
321 self assert: result isEmpty. |
333 self assert: result isEmpty. |
322 self assert: context tokenReads size = 1. |
334 self assert: context tokenReads size = 1. |
323 |
335 |
|
336 "Modified: / 07-09-2015 / 12:39:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
324 ! |
337 ! |
325 |
338 |
326 testCompileStar3 |
339 testCompileStar3 |
327 parser := 'a' asParser trimmingToken star , 'b' asParser trimmingToken |
340 parser := compiler compile: ('a' asParser trimmingToken star , 'b' asParser trimmingToken). |
328 compileUsingCompiler:compiler. |
341 |
329 |
342 |
330 self assert: parser parse: 'ab'. |
343 self assert: parser parse: 'ab'. |
331 self assert: parser parse: 'aaab'. |
344 self assert: parser parse: 'aaab'. |
332 self assert: result size = 2. |
345 self assert: result size = 2. |
333 self assert: result first size = 3. |
346 self assert: result first size = 3. |
334 |
347 |
335 self assert: parser fail: 'ac'. |
348 self assert: parser fail: 'ac'. |
|
349 |
|
350 "Modified: / 07-09-2015 / 12:39:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
336 ! |
351 ! |
337 |
352 |
338 testCompileTokenComplex2 |
353 testCompileTokenComplex2 |
339 | a b optionsWith | |
354 | a b optionsWith | |
340 "based on the PPSmalltlakGrammar>>blockArgumentsWith" |
355 "based on the PPSmalltlakGrammar>>blockArgumentsWith" |