8 ! |
8 ! |
9 |
9 |
10 |
10 |
11 !PPGreedyRepeatingParser methodsFor:'parsing'! |
11 !PPGreedyRepeatingParser methodsFor:'parsing'! |
12 |
12 |
13 parseOn: aStream |
13 parseOn: aPPContext |
14 | start element elements positions | |
14 | memento element elements positions | |
15 start := aStream position. |
15 memento := aPPContext remember. |
16 elements := OrderedCollection new. |
16 elements := OrderedCollection new. |
17 [ elements size < min ] whileTrue: [ |
17 [ elements size < min ] whileTrue: [ |
18 (element := parser parseOn: aStream) isPetitFailure ifTrue: [ |
18 (element := parser parseOn: aPPContext) isPetitFailure ifTrue: [ |
19 aStream position: start. |
19 aPPContext restore: memento. |
20 ^ element ]. |
20 ^ element ]. |
21 elements addLast: element ]. |
21 elements addLast: element ]. |
22 positions := OrderedCollection with: aStream position. |
22 positions := OrderedCollection with: aPPContext remember. |
23 [ elements size < max and: [ (element := parser parseOn: aStream) isPetitFailure not ] ] whileTrue: [ |
23 [ elements size < max and: [ (element := parser parseOn: aPPContext) isPetitFailure not ] ] whileTrue: [ |
24 elements addLast: element. |
24 elements addLast: element. |
25 positions addLast: aStream position ]. |
25 positions addLast: aPPContext remember ]. |
26 [ positions isEmpty ] whileFalse: [ |
26 [ positions isEmpty ] whileFalse: [ |
27 aStream position: positions last. |
27 aPPContext restore: positions last. |
28 element := limit parseOn: aStream. |
28 element := limit parseOn: aPPContext. |
29 element isPetitFailure ifFalse: [ |
29 element isPetitFailure ifFalse: [ |
30 aStream position: positions last. |
30 aPPContext restore: positions last. |
31 ^ elements asArray ]. |
31 ^ elements asArray ]. |
32 elements isEmpty ifTrue: [ |
32 elements isEmpty ifTrue: [ |
33 aStream position: start. |
33 aPPContext restore: memento. |
34 ^ element ]. |
34 ^ element ]. |
35 elements removeLast. |
35 elements removeLast. |
36 positions removeLast ]. |
36 positions removeLast ]. |
37 aStream position: start. |
37 aPPContext restore: memento. |
38 ^ PPFailure message: 'overflow' at: start |
38 ^ PPFailure message: 'overflow' context: aPPContext at: memento position |
39 ! ! |
39 ! ! |
40 |
40 |
41 !PPGreedyRepeatingParser class methodsFor:'documentation'! |
41 !PPGreedyRepeatingParser class methodsFor:'documentation'! |
42 |
42 |
43 version |
43 version |