|
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 Object subclass:#PPCScanner |
|
6 instanceVariableNames:'matches stream maxPriority currentChar' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Scanner' |
|
10 ! |
|
11 |
|
12 !PPCScanner methodsFor:'accessing'! |
|
13 |
|
14 stream |
|
15 ^ stream |
|
16 ! |
|
17 |
|
18 stream: anObject |
|
19 stream := anObject |
|
20 ! ! |
|
21 |
|
22 !PPCScanner methodsFor:'as yet unclassified'! |
|
23 |
|
24 recordMatch: match |
|
25 ^ self recordMatch: match priority: 0 |
|
26 ! |
|
27 |
|
28 recordMatch: match priority: currentPriority |
|
29 (maxPriority < currentPriority) ifTrue: [ |
|
30 matches := IdentityDictionary new. |
|
31 maxPriority := currentPriority. |
|
32 ]. |
|
33 |
|
34 (maxPriority == currentPriority) ifTrue: [ |
|
35 matches at: match put: stream position |
|
36 ]. |
|
37 ! |
|
38 |
|
39 return |
|
40 ^ self returnPriority: SmallInteger minVal. |
|
41 ! |
|
42 |
|
43 returnPriority: priority |
|
44 (maxPriority < priority) ifTrue: [ |
|
45 ^ IdentityDictionary new |
|
46 ]. |
|
47 ^ matches keysAndValuesRemove: [ :key :value | key class == PEGFsaFailure ] |
|
48 ! ! |
|
49 |
|
50 !PPCScanner methodsFor:'initialization'! |
|
51 |
|
52 initialize |
|
53 super initialize. |
|
54 matches := IdentityDictionary new. |
|
55 maxPriority := SmallInteger minVal. |
|
56 ! ! |
|
57 |
|
58 !PPCScanner methodsFor:'scanning'! |
|
59 |
|
60 consumeConditionally: character |
|
61 ^ (stream peek == character) ifTrue: [ stream next. true ] ifFalse: [ false ] |
|
62 ! |
|
63 |
|
64 next |
|
65 stream next |
|
66 ! |
|
67 |
|
68 peek |
|
69 ^ currentChar |
|
70 ! |
|
71 |
|
72 peekBetween: start and: stop |
|
73 (currentChar == nil) ifTrue: [ ^ false ]. |
|
74 ^ start <= currentChar codePoint and: [ currentChar codePoint <= stop ] |
|
75 ! |
|
76 |
|
77 step |
|
78 currentChar := stream next |
|
79 ! ! |
|
80 |