1
|
1 |
"{ Package: 'stx:goodies/smaCC' }"
|
|
2 |
|
|
3 |
"{ NameSpace: SmaCC }"
|
|
4 |
|
|
5 |
SmaCCParser subclass:#SmaCCScannerParser
|
|
6 |
instanceVariableNames:'tokens'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'SmaCC-Scanner Generator'
|
|
10 |
!
|
|
11 |
|
|
12 |
SmaCCScannerParser comment:'SmaCCScannerParser is the parser for the scanner definition.
|
|
13 |
|
|
14 |
Instance Variables:
|
|
15 |
tokens <Dictionary key: String value: SmaCCRegularExpressionNode> the tokens that are parsed
|
|
16 |
|
|
17 |
'
|
|
18 |
!
|
|
19 |
|
|
20 |
|
|
21 |
!SmaCCScannerParser class methodsFor:'generated-accessing'!
|
|
22 |
|
|
23 |
scannerClass
|
|
24 |
^SmaCCScannerScanner
|
|
25 |
! !
|
|
26 |
|
|
27 |
!SmaCCScannerParser class methodsFor:'generated-comments'!
|
|
28 |
|
|
29 |
parserDefinitionComment
|
|
30 |
|
|
31 |
"%left ""|"";
|
|
32 |
%left ""("" <character> <backslashcharacter> <characterblock> <anycharacter> <tokenname>;
|
|
33 |
%left ""*"" ""+"" ""?"" <repeat> ;
|
|
34 |
|
|
35 |
File: Rules {tokens}
|
|
36 |
| {tokens};
|
|
37 |
|
|
38 |
Rules: Rule "";""
|
|
39 |
| Rules Rule "";"" ;
|
|
40 |
|
|
41 |
Rule: <tokenname> "":"" Regex {'3' position: '1' startPosition. tokens at: '1' value put: '3'. nil};
|
|
42 |
|
|
43 |
Regex: RegexTerm {'1'}
|
|
44 |
| Regex ""|"" Regex {'1' | '3'}
|
|
45 |
| Regex RegexTerm {'1' , '2'};
|
|
46 |
|
|
47 |
RegexTerm: <character> {SmaCCCharacterRENode characters: '1' value}
|
|
48 |
| <anycharacter> {SmaCCCharacterRENode characters: self allCharacters}
|
|
49 |
| <backslashcharacter> {self nodeFor: (ReadStream on: ('1' value copyFrom: 2 to: '1' value size))}
|
|
50 |
| ""("" Regex "")"" {'2'}
|
|
51 |
| <characterblock> {SmaCCCharacterRENode characters: (self parseCharacterBlock: '1')}
|
|
52 |
| <tokenname> {(tokens at: '1' value) copy}
|
|
53 |
| RegexTerm ""*"" {'1' repeat}
|
|
54 |
| RegexTerm ""+"" {'1' repeatForAtLeast: 1}
|
|
55 |
| RegexTerm ""?"" {'1' repeatFor: 0 to: 1}
|
|
56 |
| RegexTerm <repeat> {| readStream start stop |
|
|
57 |
readStream := ReadStream on: ('2' value copyFrom: 2 to: '2' value size - 1).
|
|
58 |
start := readStream upTo: $,.
|
|
59 |
stop := readStream upToEnd.
|
|
60 |
'1' repeatFor: (start isEmpty ifTrue: [0] ifFalse: [start asNumber]) to: (stop isEmpty ifTrue: [(1 bitShift: 31)] ifFalse: [stop asNumber])} ;"
|
|
61 |
! !
|
|
62 |
|
|
63 |
!SmaCCScannerParser class methodsFor:'generated-starting states'!
|
|
64 |
|
|
65 |
startingStateForFile
|
|
66 |
^1
|
|
67 |
! !
|
|
68 |
|
|
69 |
!SmaCCScannerParser methodsFor:'generated-reduction actions'!
|
|
70 |
|
|
71 |
reduceActionForFile1: nodes
|
|
72 |
^tokens
|
|
73 |
!
|
|
74 |
|
|
75 |
reduceActionForFile2: nodes
|
|
76 |
^tokens
|
|
77 |
!
|
|
78 |
|
|
79 |
reduceActionForRegex1: nodes
|
|
80 |
^nodes at: 1
|
|
81 |
!
|
|
82 |
|
|
83 |
reduceActionForRegex2: nodes
|
|
84 |
^(nodes at: 1) | (nodes at: 3)
|
|
85 |
!
|
|
86 |
|
|
87 |
reduceActionForRegex3: nodes
|
|
88 |
^(nodes at: 1) , (nodes at: 2)
|
|
89 |
!
|
|
90 |
|
|
91 |
reduceActionForRegexTerm10: nodes
|
|
92 |
| readStream start stop |
|
|
93 |
readStream := ReadStream
|
|
94 |
on: ((nodes at: 2) value copyFrom: 2 to: (nodes at: 2) value size - 1).
|
|
95 |
start := readStream upTo: $,.
|
|
96 |
stop := readStream upToEnd.
|
|
97 |
^(nodes at: 1) repeatFor: (start isEmpty ifTrue: [0] ifFalse: [start asNumber])
|
|
98 |
to: (stop isEmpty ifTrue: [1 bitShift: 31] ifFalse: [stop asNumber])
|
|
99 |
!
|
|
100 |
|
|
101 |
reduceActionForRegexTerm1: nodes
|
|
102 |
^SmaCCCharacterRENode characters: (nodes at: 1) value
|
|
103 |
!
|
|
104 |
|
|
105 |
reduceActionForRegexTerm2: nodes
|
|
106 |
^SmaCCCharacterRENode characters: self allCharacters
|
|
107 |
!
|
|
108 |
|
|
109 |
reduceActionForRegexTerm3: nodes
|
|
110 |
^self
|
|
111 |
nodeFor: (ReadStream on: ((nodes at: 1) value copyFrom: 2 to: (nodes at: 1) value size))
|
|
112 |
!
|
|
113 |
|
|
114 |
reduceActionForRegexTerm4: nodes
|
|
115 |
^nodes at: 2
|
|
116 |
!
|
|
117 |
|
|
118 |
reduceActionForRegexTerm5: nodes
|
|
119 |
^SmaCCCharacterRENode characters: (self parseCharacterBlock: (nodes at: 1))
|
|
120 |
!
|
|
121 |
|
|
122 |
reduceActionForRegexTerm6: nodes
|
|
123 |
^(tokens at: (nodes at: 1) value) copy
|
|
124 |
!
|
|
125 |
|
|
126 |
reduceActionForRegexTerm7: nodes
|
|
127 |
^(nodes at: 1) repeat
|
|
128 |
!
|
|
129 |
|
|
130 |
reduceActionForRegexTerm8: nodes
|
|
131 |
^(nodes at: 1) repeatForAtLeast: 1
|
|
132 |
!
|
|
133 |
|
|
134 |
reduceActionForRegexTerm9: nodes
|
|
135 |
^(nodes at: 1) repeatFor: 0 to: 1
|
|
136 |
!
|
|
137 |
|
|
138 |
reduceActionForRule1: nodes
|
|
139 |
(nodes at: 3) position: (nodes at: 1) startPosition.
|
|
140 |
tokens at: (nodes at: 1) value put: (nodes at: 3).
|
|
141 |
^nil
|
|
142 |
! !
|
|
143 |
|
|
144 |
!SmaCCScannerParser methodsFor:'generated-tables'!
|
|
145 |
|
|
146 |
reduceTable
|
|
147 |
^#(
|
|
148 |
#(19 3 #reduceActionForRule1:)
|
|
149 |
#(20 2 #reduceFor:)
|
|
150 |
#(20 3 #reduceFor:)
|
|
151 |
#(21 1 #reduceActionForRegexTerm1:)
|
|
152 |
#(21 1 #reduceActionForRegexTerm2:)
|
|
153 |
#(21 1 #reduceActionForRegexTerm3:)
|
|
154 |
#(21 3 #reduceActionForRegexTerm4:)
|
|
155 |
#(21 1 #reduceActionForRegexTerm5:)
|
|
156 |
#(21 1 #reduceActionForRegexTerm6:)
|
|
157 |
#(21 2 #reduceActionForRegexTerm7:)
|
|
158 |
#(21 2 #reduceActionForRegexTerm8:)
|
|
159 |
#(21 2 #reduceActionForRegexTerm9:)
|
|
160 |
#(21 2 #reduceActionForRegexTerm10:)
|
|
161 |
#(22 1 #reduceActionForFile1:)
|
|
162 |
#(22 0 #reduceActionForFile2:)
|
|
163 |
#(23 1 #reduceActionForRegex1:)
|
|
164 |
#(23 3 #reduceActionForRegex2:)
|
|
165 |
#(23 2 #reduceActionForRegex3:)
|
|
166 |
#(24 1 #reduceFor:)
|
|
167 |
)
|
|
168 |
!
|
|
169 |
|
|
170 |
transitionTable
|
|
171 |
^#(
|
|
172 |
#[1 0 9 0 12 0 62 0 18 0 13 0 19 0 17 0 20 0 21 0 22]
|
|
173 |
#[0 0 25 0 5]
|
|
174 |
#[0 0 29 0 7]
|
|
175 |
#[1 0 9 0 12 0 58 0 18 0 33 0 19]
|
|
176 |
#[0 0 0 0 18]
|
|
177 |
#[1 0 37 0 4 0 41 0 9 0 45 0 10 0 49 0 12 0 53 0 15 0 57 0 16 0 61 0 21 0 65 0 23]
|
|
178 |
#[0 0 10 0 12 0 18]
|
|
179 |
#[0 0 69 0 7]
|
|
180 |
#[1 0 37 0 4 0 41 0 9 0 45 0 10 0 49 0 12 0 53 0 15 0 57 0 16 0 61 0 21 0 73 0 23]
|
|
181 |
#[0 0 26 0 1 0 2 0 3 0 4 0 6 0 7 0 8 0 9 0 10 0 12 0 14 0 15 0 16]
|
|
182 |
#[0 0 34 0 1 0 2 0 3 0 4 0 6 0 7 0 8 0 9 0 10 0 12 0 14 0 15 0 16]
|
|
183 |
#[0 0 38 0 1 0 2 0 3 0 4 0 6 0 7 0 8 0 9 0 10 0 12 0 14 0 15 0 16]
|
|
184 |
#[0 0 18 0 1 0 2 0 3 0 4 0 6 0 7 0 8 0 9 0 10 0 12 0 14 0 15 0 16]
|
|
185 |
#[0 0 22 0 1 0 2 0 3 0 4 0 6 0 7 0 8 0 9 0 10 0 12 0 14 0 15 0 16]
|
|
186 |
#[1 0 66 0 1 0 77 0 2 0 66 0 3 0 66 0 4 0 81 0 6 0 66 0 7 0 85 0 8 0 66 0 9 0 66 0 10 0 66 0 12 0 89 0 14 0 66 0 15 0 66 0 16]
|
|
187 |
#[1 0 93 0 3 0 37 0 4 0 6 0 7 0 41 0 9 0 45 0 10 0 49 0 12 0 53 0 15 0 57 0 16 0 97 0 21]
|
|
188 |
#[0 0 14 0 12 0 18]
|
|
189 |
#[1 0 101 0 1 0 93 0 3 0 37 0 4 0 41 0 9 0 45 0 10 0 49 0 12 0 53 0 15 0 57 0 16 0 97 0 21]
|
|
190 |
#[0 0 42 0 1 0 2 0 3 0 4 0 6 0 7 0 8 0 9 0 10 0 12 0 14 0 15 0 16]
|
|
191 |
#[0 0 46 0 1 0 2 0 3 0 4 0 6 0 7 0 8 0 9 0 10 0 12 0 14 0 15 0 16]
|
|
192 |
#[0 0 50 0 1 0 2 0 3 0 4 0 6 0 7 0 8 0 9 0 10 0 12 0 14 0 15 0 16]
|
|
193 |
#[0 0 54 0 1 0 2 0 3 0 4 0 6 0 7 0 8 0 9 0 10 0 12 0 14 0 15 0 16]
|
|
194 |
#[1 0 37 0 4 0 41 0 9 0 45 0 10 0 49 0 12 0 53 0 15 0 57 0 16 0 61 0 21 0 105 0 23]
|
|
195 |
#[1 0 74 0 1 0 77 0 2 0 74 0 3 0 74 0 4 0 81 0 6 0 74 0 7 0 85 0 8 0 74 0 9 0 74 0 10 0 74 0 12 0 89 0 14 0 74 0 15 0 74 0 16]
|
|
196 |
#[0 0 30 0 1 0 2 0 3 0 4 0 6 0 7 0 8 0 9 0 10 0 12 0 14 0 15 0 16]
|
|
197 |
#[1 0 70 0 1 0 70 0 3 0 37 0 4 0 70 0 7 0 41 0 9 0 45 0 10 0 49 0 12 0 53 0 15 0 57 0 16 0 97 0 21]
|
|
198 |
)
|
|
199 |
! !
|
|
200 |
|
|
201 |
!SmaCCScannerParser methodsFor:'initialize-release'!
|
|
202 |
|
|
203 |
initialize
|
|
204 |
super initialize.
|
|
205 |
tokens := Dictionary new
|
|
206 |
! !
|
|
207 |
|
|
208 |
!SmaCCScannerParser methodsFor:'private'!
|
|
209 |
|
|
210 |
allCharacters
|
|
211 |
^UnicodeString withAll: ((0 to: SmaCCGrammar maximumCharacterValue)
|
|
212 |
collect: [:each | Character value: each])
|
|
213 |
|
|
214 |
"Modified: / 26-05-2006 / 22:16:45 / janfrog"
|
|
215 |
!
|
|
216 |
|
|
217 |
charactersFor: aStream in: aToken
|
|
218 |
| characters char endCharacters |
|
|
219 |
aStream atEnd ifTrue: [self reportCharacterBlockErrorForToken: aToken].
|
|
220 |
char := aStream next.
|
|
221 |
characters := char == $\
|
|
222 |
ifTrue: [(self nodeFor: aStream) characters]
|
|
223 |
ifFalse: [OrderedCollection with: char].
|
|
224 |
(characters size = 1 and: [aStream peekFor: $-]) ifFalse: [^characters].
|
|
225 |
endCharacters := self charactersFor: aStream in: aToken.
|
|
226 |
endCharacters size > 1
|
|
227 |
ifTrue: [self reportCharacterBlockErrorForToken: aToken].
|
|
228 |
^(characters first asInteger to: endCharacters first asInteger)
|
|
229 |
collect: [:each | Character value: each]
|
|
230 |
!
|
|
231 |
|
|
232 |
nodeFor: aStream
|
|
233 |
| block char value count |
|
|
234 |
char := aStream next.
|
|
235 |
char == $f
|
|
236 |
ifTrue:
|
|
237 |
[^SmaCCCharacterRENode characters: (String with: (Character value: 12))].
|
|
238 |
char == $n
|
|
239 |
ifTrue:
|
|
240 |
[^SmaCCCharacterRENode characters: (String with: (Character value: 10))].
|
|
241 |
char == $r
|
|
242 |
ifTrue:
|
|
243 |
[^SmaCCCharacterRENode characters: (String with: (Character value: 13))].
|
|
244 |
char == $t ifTrue: [^SmaCCCharacterRENode characters: ' '].
|
|
245 |
char == $v
|
|
246 |
ifTrue:
|
|
247 |
[^SmaCCCharacterRENode characters: (String with: (Character value: 11))].
|
|
248 |
char == $c
|
|
249 |
ifTrue:
|
|
250 |
[^SmaCCCharacterRENode characters: (String
|
|
251 |
with: (Character value: aStream next asInteger - $A asInteger))].
|
|
252 |
char == $x
|
|
253 |
ifTrue:
|
|
254 |
[count := value := 0.
|
|
255 |
|
|
256 |
[aStream atEnd not and:
|
|
257 |
[count < 4 and:
|
|
258 |
[char := aStream peek.
|
|
259 |
(char between: $0 and: $9)
|
|
260 |
or: [(char between: $A and: $F) or: [char between: $a and: $f]]]]]
|
|
261 |
whileTrue:
|
|
262 |
[count := count + 1.
|
|
263 |
value := value * 16 + aStream next digitValue].
|
|
264 |
^SmaCCCharacterRENode characters: (String with: (Character value: value))].
|
|
265 |
char == $d ifTrue: [block := [:each | each between: $0 and: $9]].
|
|
266 |
char == $D ifTrue: [block := [:each | (each between: $0 and: $9) not]].
|
|
267 |
char == $s
|
|
268 |
ifTrue: [block := [:each | #[9 10 11 12 13 32] includes: each asInteger]].
|
|
269 |
char == $S
|
|
270 |
ifTrue:
|
|
271 |
[block := [:each | (#[9 10 11 12 13 32] includes: each asInteger) not]].
|
|
272 |
char == $w
|
|
273 |
ifTrue:
|
|
274 |
[block :=
|
|
275 |
[:each |
|
|
276 |
(each between: $a and: $z) or:
|
|
277 |
[(each between: $A and: $Z)
|
|
278 |
or: [(each between: $0 and: $9) or: [each == $_]]]]].
|
|
279 |
char == $W
|
|
280 |
ifTrue:
|
|
281 |
[block :=
|
|
282 |
[:each |
|
|
283 |
((each between: $a and: $z) or:
|
|
284 |
[(each between: $A and: $Z)
|
|
285 |
or: [(each between: $0 and: $9) or: [each == $_]]])
|
|
286 |
not]].
|
|
287 |
block isNil
|
|
288 |
ifTrue: [^SmaCCCharacterRENode characters: (String with: char)].
|
|
289 |
^SmaCCCharacterRENode
|
|
290 |
characters: (String withAll: (self allCharacters select: block))
|
|
291 |
!
|
|
292 |
|
|
293 |
parseCharacterBlock: aToken
|
|
294 |
| characters aStream invert |
|
|
295 |
aStream := ReadStream
|
|
296 |
on: (aToken value copyFrom: 2 to: aToken value size - 1).
|
|
297 |
characters := OrderedCollection new.
|
|
298 |
invert := aStream peekFor: $^.
|
|
299 |
[aStream atEnd]
|
|
300 |
whileFalse: [characters addAll: (self charactersFor: aStream in: aToken)].
|
|
301 |
^UnicodeString withAll: (invert
|
|
302 |
ifTrue: [self allCharacters reject: [:each | characters includes: each]]
|
|
303 |
ifFalse: [characters])
|
|
304 |
|
|
305 |
"Modified: / 26-05-2006 / 22:17:06 / janfrog"
|
|
306 |
!
|
|
307 |
|
|
308 |
reportCharacterBlockErrorForToken: aToken
|
|
309 |
currentToken := aToken.
|
|
310 |
self reportErrorMessage: 'Invalid character block'
|
|
311 |
! !
|
|
312 |
|
|
313 |
!SmaCCScannerParser class methodsFor:'documentation'!
|
|
314 |
|
|
315 |
version
|
|
316 |
^ '$Header: /opt/data/cvs/stx/goodies/smaCC/SmaCC__SmaCCScannerParser.st,v 1.2 2006-05-28 20:10:22 vranyj1 Exp $'
|
|
317 |
! !
|