1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
2 |
2 |
3 "{ NameSpace: Smalltalk }" |
3 "{ NameSpace: Smalltalk }" |
4 |
4 |
5 Object subclass:#PPCScanner |
5 Object subclass:#PPCScanner |
6 instanceVariableNames:'match matchPosition matches tokens stream currentChar |
6 instanceVariableNames:'match matchPosition matches tokens currentChar maxSymbolNumber |
7 maxSymbolNumber position' |
7 position context' |
8 classVariableNames:'' |
8 classVariableNames:'' |
9 poolDictionaries:'' |
9 poolDictionaries:'' |
10 category:'PetitCompiler-Scanner' |
10 category:'PetitCompiler-Scanner' |
11 ! |
11 ! |
12 |
12 |
53 ! |
53 ! |
54 |
54 |
55 reset |
55 reset |
56 matchPosition := nil. "This flag says that multimode run the last time" |
56 matchPosition := nil. "This flag says that multimode run the last time" |
57 |
57 |
58 position := stream position. |
58 position := context position. |
59 " matches := Array new: maxSymbolNumber." |
59 " matches := Array new: maxSymbolNumber." |
60 ! |
60 ! |
61 |
61 |
62 reset: tokenList |
62 reset: tokenList |
63 "Method should not be used, it is here for debugging and testing purposes" |
63 "Method should not be used, it is here for debugging and testing purposes" |
168 ] ]. |
168 ] ]. |
169 ! ! |
169 ! ! |
170 |
170 |
171 !PPCScanner methodsFor:'results - distinct'! |
171 !PPCScanner methodsFor:'results - distinct'! |
172 |
172 |
|
173 recordDistinctFailure |
|
174 match := nil. |
|
175 matchPosition := position. |
|
176 ^ false |
|
177 ! |
|
178 |
|
179 recordDistinctFailure: matchValue |
|
180 match := matchValue. |
|
181 matchPosition := context position. |
|
182 ^ false |
|
183 ! |
|
184 |
173 recordDistinctMatch: matchValue |
185 recordDistinctMatch: matchValue |
174 match := matchValue. |
186 match := matchValue. |
175 matchPosition := stream position. |
187 matchPosition := context position. |
|
188 ^ true |
176 ! |
189 ! |
177 |
190 |
178 recordDistinctMatch: matchValue offset: offset |
191 recordDistinctMatch: matchValue offset: offset |
179 match := matchValue. |
192 match := matchValue. |
180 currentChar isNil ifFalse: [ |
193 currentChar isNil ifFalse: [ |
181 matchPosition := stream position - offset. |
194 matchPosition := context position - offset. |
182 ] ifTrue: [ |
195 ] ifTrue: [ |
183 matchPosition := stream position. |
196 matchPosition := context position. |
184 ] |
197 ]. |
|
198 ^ true |
185 ! |
199 ! |
186 |
200 |
187 returnDistinct |
201 returnDistinct |
188 ^ match isNotNil |
202 ^ match isNotNil |
189 ! ! |
203 ! ! |
197 recordFailure: index offset: offset |
211 recordFailure: index offset: offset |
198 matches at: index put: -1. |
212 matches at: index put: -1. |
199 ! |
213 ! |
200 |
214 |
201 recordMatch: index |
215 recordMatch: index |
202 matches at: index put: stream position. |
216 matches at: index put: context position. |
203 ! |
217 ! |
204 |
218 |
205 recordMatch: index offset: offset |
219 recordMatch: index offset: offset |
206 currentChar isNil ifFalse: [ |
220 currentChar isNil ifFalse: [ |
207 matches at: index put: stream position - offset. |
221 matches at: index put: context position - offset. |
208 ] ifTrue: [ |
222 ] ifTrue: [ |
209 matches at: index put: stream position. |
223 matches at: index put: context position. |
210 ]. |
224 ]. |
211 |
225 |
212 ! |
226 ! |
213 |
227 |
214 return |
228 return |
215 ^ matches |
229 ^ matches |
216 ! ! |
230 ! ! |
217 |
231 |
218 !PPCScanner methodsFor:'scanning'! |
232 !PPCScanner methodsFor:'scanning'! |
219 |
233 |
220 next |
234 back |
221 self error: 'deprecated?'. |
235 currentChar isNil ifFalse: [ |
222 stream next |
236 context skip: -1 |
|
237 ] |
223 ! |
238 ! |
224 |
239 |
225 peek |
240 peek |
|
241 self flag: 'inline this, do not call peek!!'. |
226 ^ currentChar |
242 ^ currentChar |
227 ! |
243 ! |
228 |
244 |
229 peekBetween: start and: stop |
245 peekBetween: start and: stop |
230 (currentChar == nil) ifTrue: [ ^ false ]. |
246 (currentChar == nil) ifTrue: [ ^ false ]. |
231 ^ (start <= currentChar codePoint) and: [ currentChar codePoint <= stop ] |
247 ^ (start <= currentChar codePoint) and: [ currentChar codePoint <= stop ] |
232 ! |
248 ! |
233 |
249 |
234 step |
250 step |
235 currentChar := stream next |
251 currentChar := context next |
236 ! ! |
252 ! ! |
237 |
253 |
238 !PPCScanner methodsFor:'testing'! |
254 !PPCScanner methodsFor:'testing'! |
239 |
255 |
240 isSingleMatch |
256 isSingleMatch |