|
1 "{ Package: 'stx:goodies/petitparser/islands' }" |
|
2 |
|
3 PPDelegateParser subclass:#PPWater |
|
4 instanceVariableNames:'waterToken context' |
|
5 classVariableNames:'' |
|
6 poolDictionaries:'' |
|
7 category:'PetitIslands-Parsers' |
|
8 ! |
|
9 |
|
10 PPWater comment:'' |
|
11 ! |
|
12 |
|
13 !PPWater class methodsFor:'as yet unclassified'! |
|
14 |
|
15 on: parser |
|
16 ^ self on: parser waterToken: #any asParser |
|
17 ! |
|
18 |
|
19 on: parser waterToken: waterToken |
|
20 ^ (super on: parser) |
|
21 waterToken: waterToken; |
|
22 yourself |
|
23 ! ! |
|
24 |
|
25 !PPWater methodsFor:'as yet unclassified'! |
|
26 |
|
27 checkContext: aPPContext |
|
28 context == aPPContext ifFalse: [ |
|
29 self reset: aPPContext |
|
30 ] |
|
31 ! |
|
32 |
|
33 children |
|
34 ^ Array with: waterToken |
|
35 ! |
|
36 |
|
37 initialize |
|
38 super initialize. |
|
39 waterToken := nil asParser. |
|
40 context := nil. |
|
41 ! |
|
42 |
|
43 parseOn: aPPContext |
|
44 | waterPosition result | |
|
45 |
|
46 (aPPContext waterPosition == aPPContext position) ifFalse: [ |
|
47 waterPosition := aPPContext waterPosition. |
|
48 aPPContext waterPosition: aPPContext position. |
|
49 |
|
50 "TODO: probably can be rewritten with test in the end!!" |
|
51 result := parser parseOn: aPPContext. |
|
52 [result isPetitFailure] whileFalse: [ |
|
53 waterToken parseOn: aPPContext. |
|
54 aPPContext waterPosition: aPPContext position. |
|
55 result := parser parseOn: aPPContext. |
|
56 ]. |
|
57 |
|
58 aPPContext waterPosition: waterPosition. |
|
59 ]. |
|
60 |
|
61 ^ #water |
|
62 ! |
|
63 |
|
64 replace: child with: anotherChild |
|
65 child == waterToken ifTrue: [ |
|
66 waterToken := anotherChild. |
|
67 ] |
|
68 ! |
|
69 |
|
70 reset: aPPContext |
|
71 | waterObjects | |
|
72 |
|
73 context := aPPContext. |
|
74 |
|
75 waterObjects := aPPContext globalAt: #waterObjects ifAbsent: [ OrderedCollection new ]. |
|
76 waterObjects add: #any asParser. |
|
77 waterToken := PPChoiceParser withAll: waterObjects. |
|
78 ! |
|
79 |
|
80 waterToken: aPPParser |
|
81 ^ waterToken := aPPParser |
|
82 ! ! |
|
83 |