1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
2 |
2 |
3 "{ NameSpace: Smalltalk }" |
3 "{ NameSpace: Smalltalk }" |
4 |
4 |
5 PPParser subclass:#PPCompiledParser |
5 PPParser subclass:#PPCompiledParser |
6 instanceVariableNames:'startSymbol context failure error' |
6 instanceVariableNames:'startSymbol context failure error currentTokenValue |
|
7 currentTokenType' |
7 classVariableNames:'' |
8 classVariableNames:'' |
8 poolDictionaries:'' |
9 poolDictionaries:'' |
9 category:'PetitCompiler-Core' |
10 category:'PetitCompiler-Core' |
10 ! |
11 ! |
11 |
12 |
12 PPCompiledParser class instanceVariableNames:'parsers constants referringParser' |
13 PPCompiledParser class instanceVariableNames:'parsers constants referringParser startSymbol' |
13 |
14 |
14 " |
15 " |
15 No other class instance variables are inherited by this class. |
16 No other class instance variables are inherited by this class. |
16 " |
17 " |
17 ! |
18 ! |
18 |
19 |
19 !PPCompiledParser class methodsFor:'as yet unclassified'! |
20 !PPCompiledParser class methodsFor:'as yet unclassified'! |
20 |
21 |
21 addConstant: value as: id |
22 addConstant: value as: id |
22 self constants at: id ifPresent: [:ignored | |
23 self constants at: id ifPresent: [ |
23 ((self constants at: id) = value) ifFalse: [self error: 'ooups']]. |
24 ((self constants at: id) = value) ifFalse: [self error: 'ooups']]. |
24 |
25 |
25 self constants at: id put: value. |
26 self constants at: id put: value. |
26 ! |
|
27 |
|
28 addParser: aPPParser as: id |
|
29 |
|
30 "(self parsers includesKey: id) ifTrue: [self error: 'Ooups' ]." |
|
31 self parsers at: id put: aPPParser. |
|
32 ! |
27 ! |
33 |
28 |
34 constants |
29 constants |
35 constants ifNil: [ constants := IdentityDictionary new ]. |
30 constants ifNil: [ constants := IdentityDictionary new ]. |
36 ^ constants |
31 ^ constants |
38 |
33 |
39 parse: input |
34 parse: input |
40 ^ self new parse: input |
35 ^ self new parse: input |
41 ! |
36 ! |
42 |
37 |
43 parsers |
|
44 parsers ifNil: [ parsers := IdentityDictionary new ]. |
|
45 ^ parsers |
|
46 ! |
|
47 |
|
48 referringParser |
38 referringParser |
49 ^ referringParser |
39 ^ referringParser ifNil: [ ^ PPSentinel new ] |
50 ! |
40 ! |
51 |
41 |
52 referringParser: aPPParser |
42 referringParser: aPPParser |
53 referringParser := aPPParser |
43 referringParser := aPPParser |
|
44 ! |
|
45 |
|
46 startSymbol |
|
47 ^ startSymbol ifNil: [ ^ #start ] |
|
48 ! |
|
49 |
|
50 startSymbol: symbol |
|
51 startSymbol := symbol |
54 ! ! |
52 ! ! |
55 |
53 |
56 !PPCompiledParser methodsFor:'as yet unclassified'! |
54 !PPCompiledParser methodsFor:'as yet unclassified'! |
57 |
55 |
58 callParser: id |
56 callParser: id |
139 |
132 |
140 " aPPContext position: context position." |
133 " aPPContext position: context position." |
141 ^ retval |
134 ^ retval |
142 ! ! |
135 ! ! |
143 |
136 |
|
137 !PPCompiledParser methodsFor:'tokenizing'! |
|
138 |
|
139 consume: tokenType |
|
140 (currentTokenType = tokenType) ifTrue: [ |
|
141 | retval | |
|
142 retval := currentTokenValue. |
|
143 self nextToken. |
|
144 ^ retval |
|
145 ] ifFalse: [ |
|
146 self error: 'expected: ', tokenType storeString, ' got ', currentTokenType storeString. |
|
147 ] |
|
148 ! |
|
149 |
|
150 currentTokenType |
|
151 currentTokenType isNil ifTrue: [ self nextToken ]. |
|
152 ^ currentTokenType |
|
153 ! |
|
154 |
|
155 currentTokenValue |
|
156 currentTokenType isNil ifTrue: [ self nextToken ]. |
|
157 ^ currentTokenType |
|
158 ! |
|
159 |
|
160 nextToken |
|
161 self shouldBeImplemented |
|
162 ! ! |
|
163 |