equal
deleted
inserted
replaced
1 "{ Package: 'stx:goodies/petitparser' }" |
1 "{ Package: 'stx:goodies/petitparser' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
2 |
4 |
3 Object subclass:#PPParser |
5 Object subclass:#PPParser |
4 instanceVariableNames:'properties' |
6 instanceVariableNames:'properties' |
5 classVariableNames:'' |
7 classVariableNames:'' |
6 poolDictionaries:'' |
8 poolDictionaries:'' |
16 |
18 |
17 new |
19 new |
18 ^ self basicNew initialize |
20 ^ self basicNew initialize |
19 ! ! |
21 ! ! |
20 |
22 |
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 !PPParser methodsFor:'accessing'! |
23 !PPParser methodsFor:'accessing'! |
31 |
24 |
32 children |
25 children |
33 "Answer a set of child parsers that could follow the receiver." |
26 "Answer a set of child parsers that could follow the receiver." |
34 |
27 |
109 | result | |
102 | result | |
110 context initializeFor: self. |
103 context initializeFor: self. |
111 result := self parseOn: context. |
104 result := self parseOn: context. |
112 |
105 |
113 "Return the furthest failure, it gives better results than the last failure" |
106 "Return the furthest failure, it gives better results than the last failure" |
114 result isPetitFailure ifTrue: [ ^ context furthestFailure ]. |
107 (result isPetitFailure and: [ context furthestFailure notNil]) |
|
108 ifTrue: [ ^ context furthestFailure ]. |
115 ^ result |
109 ^ result |
116 |
110 |
117 ! |
111 ! |
118 |
112 |
119 updateContext: aPPContext |
113 updateContext: aPPContext |
310 Answer a new parser that parses the receiver, if the receiver fails try with aParser (ordered-choice). |
304 Answer a new parser that parses the receiver, if the receiver fails try with aParser (ordered-choice). |
311 If the receiver passes, limit must pass as well. |
305 If the receiver passes, limit must pass as well. |
312 " |
306 " |
313 |
307 |
314 ^ PPLimitedChoiceParser with: self with: aParser |
308 ^ PPLimitedChoiceParser with: self with: aParser |
|
309 ! |
|
310 |
|
311 if: aBlock |
|
312 ^ PPConditionalParser on: self block: aBlock |
315 ! ! |
313 ! ! |
316 |
314 |
317 !PPParser methodsFor:'operators-convenience'! |
315 !PPParser methodsFor:'operators-convenience'! |
318 |
316 |
319 withoutSeparators |
317 withoutSeparators |
382 "Answer a new parser that consumes blanks before and after the receiving parser." |
380 "Answer a new parser that consumes blanks before and after the receiving parser." |
383 |
381 |
384 ^ self trim: #blank asParser |
382 ^ self trim: #blank asParser |
385 ! |
383 ! |
386 |
384 |
|
385 trimLeft |
|
386 "Answer a new parser that consumes spaces before the receiving parser." |
|
387 |
|
388 ^ self trimSpacesLeft |
|
389 ! |
|
390 |
|
391 trimRight |
|
392 "Answer a new parser that consumes spaces after the receiving parser." |
|
393 |
|
394 ^ self trimSpacesRight |
|
395 ! |
|
396 |
387 trimSpaces |
397 trimSpaces |
388 "Answer a new parser that consumes spaces before and after the receiving parser." |
398 "Answer a new parser that consumes spaces before and after the receiving parser." |
389 |
399 |
390 ^ self trim: #space asParser |
400 ^ self trim: #space asParser |
|
401 ! |
|
402 |
|
403 trimSpacesLeft |
|
404 "Answer a new parser that consumes spaces before the receiving parser." |
|
405 |
|
406 ^ (#space asParser star, self) ==> #second |
|
407 ! |
|
408 |
|
409 trimSpacesRight |
|
410 "Answer a new parser that consumes spaces after the receiving parser." |
|
411 |
|
412 ^ (self, #space asParser star) ==> #first |
391 ! ! |
413 ! ! |
392 |
414 |
393 !PPParser methodsFor:'operators-repeating'! |
415 !PPParser methodsFor:'operators-repeating'! |
394 |
416 |
395 max: anInteger |
417 max: anInteger |