|
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 Object subclass:#PPCDistinctScanner |
|
6 instanceVariableNames:'position match matchPosition currentChar context returnBlock' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Scanner' |
|
10 ! |
|
11 |
|
12 !PPCDistinctScanner methodsFor:'accessing-private'! |
|
13 |
|
14 getMatch |
|
15 ^ match |
|
16 ! |
|
17 |
|
18 position |
|
19 "returns the start position before the scan method..." |
|
20 ^ position |
|
21 ! |
|
22 |
|
23 position: anObject |
|
24 position := matchPosition := anObject |
|
25 ! |
|
26 |
|
27 setMatch: value |
|
28 match := value |
|
29 ! |
|
30 |
|
31 stream |
|
32 ^ context |
|
33 ! |
|
34 |
|
35 stream: anObject |
|
36 context := anObject |
|
37 ! ! |
|
38 |
|
39 !PPCDistinctScanner methodsFor:'initialization'! |
|
40 |
|
41 initialize |
|
42 super initialize. |
|
43 match := nil. |
|
44 position := 0. |
|
45 matchPosition := 0. |
|
46 ! |
|
47 |
|
48 resetDistinct |
|
49 ! ! |
|
50 |
|
51 !PPCDistinctScanner methodsFor:'memoization'! |
|
52 |
|
53 remember |
|
54 ^ position |
|
55 ! |
|
56 |
|
57 restore: restorePosition |
|
58 context position: (matchPosition := position := restorePosition). |
|
59 match := nil |
|
60 ! ! |
|
61 |
|
62 !PPCDistinctScanner methodsFor:'results'! |
|
63 |
|
64 polyResult |
|
65 | dictionary | |
|
66 dictionary := IdentityDictionary new. |
|
67 match isNil ifFalse: [ |
|
68 dictionary at: match put: matchPosition. |
|
69 ]. |
|
70 |
|
71 ^ dictionary |
|
72 ! |
|
73 |
|
74 recordDistinctFailure |
|
75 self flag: 'Potential bug? What if there is something after the failure? Might that happen for distinct parser?'. |
|
76 |
|
77 match := nil. |
|
78 matchPosition := position. |
|
79 context position: position. |
|
80 ^ false |
|
81 ! |
|
82 |
|
83 recordDistinctMatch: matchValue |
|
84 match := matchValue. |
|
85 matchPosition := context position. |
|
86 ^ true |
|
87 ! |
|
88 |
|
89 recordDistinctMatch: matchValue offset: offset |
|
90 match := matchValue. |
|
91 |
|
92 currentChar isNil ifFalse: [ |
|
93 matchPosition := context position - offset. |
|
94 ] ifTrue: [ |
|
95 matchPosition := context position. |
|
96 ]. |
|
97 ^ true |
|
98 ! |
|
99 |
|
100 result |
|
101 ^ match |
|
102 ! |
|
103 |
|
104 resultPosition |
|
105 ^ matchPosition |
|
106 ! |
|
107 |
|
108 returnDistinct |
|
109 " |
|
110 match isNil ifTrue: [ |
|
111 self assert: matchPosition == position |
|
112 ]. |
|
113 " |
|
114 |
|
115 context position: matchPosition. |
|
116 ^ match isNotNil |
|
117 ! ! |
|
118 |
|
119 !PPCDistinctScanner methodsFor:'scanning'! |
|
120 |
|
121 back |
|
122 currentChar isNil ifFalse: [ |
|
123 context skip: -1 |
|
124 ] |
|
125 ! |
|
126 |
|
127 peekBetween: start and: stop |
|
128 (currentChar == nil) ifTrue: [ ^ false ]. |
|
129 ^ (start <= currentChar codePoint) and: [ currentChar codePoint <= stop ] |
|
130 ! |
|
131 |
|
132 step |
|
133 currentChar := context next |
|
134 ! ! |
|
135 |