0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Object subclass:#Scanner
|
|
14 |
instanceVariableNames:'source
|
|
15 |
token tokenType tokenPosition tokenValue
|
|
16 |
tokenName tokenLineNr
|
|
17 |
thisChar peekChar
|
|
18 |
requestor exitBlock
|
3
|
19 |
errorFlag
|
|
20 |
saveComments currentComments'
|
0
|
21 |
classVariableNames:'typeArray actionArray'
|
|
22 |
poolDictionaries:''
|
|
23 |
category:'System-Compiler'
|
|
24 |
!
|
|
25 |
|
|
26 |
Scanner comment:'
|
|
27 |
|
|
28 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
29 |
All Rights Reserved
|
|
30 |
|
|
31 |
Scanner reads from a stream and returns individual smalltalk tokens
|
3
|
32 |
$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.2 1993-10-13 00:26:15 claus Exp $
|
0
|
33 |
'!
|
|
34 |
|
|
35 |
!Scanner class methodsFor:'instance creation'!
|
|
36 |
|
|
37 |
for:aStream
|
|
38 |
"return a new scanner reading from aStream"
|
|
39 |
|
|
40 |
^ (super new) initializeFor:aStream
|
|
41 |
! !
|
|
42 |
|
|
43 |
!Scanner methodsFor:'private'!
|
|
44 |
|
|
45 |
initializeFor:aStream
|
|
46 |
"initialize -
|
|
47 |
if this is the first time, setup character- and action tables"
|
|
48 |
|
|
49 |
|block|
|
|
50 |
|
|
51 |
errorFlag := false.
|
|
52 |
tokenLineNr := 1.
|
|
53 |
source := aStream.
|
3
|
54 |
currentComments := nil.
|
|
55 |
saveComments := false.
|
0
|
56 |
|
|
57 |
actionArray isNil ifTrue:[
|
|
58 |
actionArray := Array new:256.
|
|
59 |
typeArray := Array new:256.
|
|
60 |
|
|
61 |
block := [:s :char | s nextNumber].
|
|
62 |
($0 asciiValue) to:($9 asciiValue) do:[:index |
|
|
63 |
actionArray at:index put:block
|
|
64 |
].
|
|
65 |
|
|
66 |
block := [:s :char | s nextIdentifier].
|
|
67 |
($a asciiValue) to:($z asciiValue) do:[:index |
|
|
68 |
actionArray at:index put:block
|
|
69 |
].
|
|
70 |
($A asciiValue) to:($Z asciiValue) do:[:index |
|
|
71 |
actionArray at:index put:block
|
|
72 |
].
|
|
73 |
|
|
74 |
block := [:s :char | s nextSpecial].
|
|
75 |
#( $& $- $+ $= $* $/ $\ $< $> $~ $@ $, $? ) do:[:binop |
|
|
76 |
typeArray at:(binop asciiValue) put:#special.
|
|
77 |
actionArray at:(binop asciiValue) put:block
|
|
78 |
].
|
|
79 |
|
|
80 |
block := [:s :char | s nextToken:char].
|
|
81 |
#( $; $. $( $) $[ $] $!! $^ $| $_ ) do:[:ch |
|
|
82 |
actionArray at:(ch asciiValue) put:block
|
|
83 |
].
|
|
84 |
|
|
85 |
"kludge: action is characterToken, but type is special"
|
|
86 |
typeArray at:($| asciiValue) put:#special.
|
|
87 |
|
|
88 |
actionArray at:($' asciiValue) put:[:s :char | s nextString].
|
|
89 |
actionArray at:($$ asciiValue) put:[:s :char | s nextCharacter].
|
|
90 |
actionArray at:($# asciiValue) put:[:s :char | s nextHash].
|
|
91 |
actionArray at:($% asciiValue) put:[:s :char | s nextPrimitive].
|
|
92 |
actionArray at:($: asciiValue) put:[:s :char | s nextColonOrAssign]
|
|
93 |
]
|
|
94 |
!
|
|
95 |
|
3
|
96 |
initialize
|
|
97 |
"prepare a scan"
|
|
98 |
|
|
99 |
errorFlag := false.
|
|
100 |
tokenLineNr := 1.
|
|
101 |
currentComments := nil.
|
|
102 |
saveComments := false.
|
|
103 |
!
|
|
104 |
|
0
|
105 |
notifying:anObject
|
|
106 |
"set the requestor to be notified"
|
|
107 |
|
|
108 |
requestor := anObject
|
|
109 |
!
|
|
110 |
|
|
111 |
backupPosition
|
|
112 |
"if reading from a stream, at the end we might have read
|
|
113 |
one token too many"
|
|
114 |
|
|
115 |
(tokenType == #EOF) ifFalse:[
|
|
116 |
source position:tokenPosition
|
|
117 |
]
|
|
118 |
! !
|
|
119 |
|
|
120 |
!Scanner methodsFor:'error handling'!
|
|
121 |
|
|
122 |
showErrorMessage:aMessage position:pos
|
|
123 |
"show an errormessage on the Transcript"
|
|
124 |
|
|
125 |
Transcript showCr:(pos printString , ' ' , aMessage)
|
|
126 |
!
|
|
127 |
|
|
128 |
notifyError:aMessage position:position to:endPos
|
|
129 |
"notify requestor of an error - if there is no requestor
|
|
130 |
put it on the transcript.
|
|
131 |
Return the result passed back by the requestor."
|
|
132 |
|
|
133 |
requestor isNil ifTrue:[
|
|
134 |
self showErrorMessage:aMessage position:position.
|
|
135 |
^ false
|
|
136 |
].
|
|
137 |
^ requestor error:aMessage position:position to:endPos
|
|
138 |
!
|
|
139 |
|
|
140 |
notifyWarning:aMessage position:position to:endPos
|
|
141 |
"notify requestor of an warning - if there is no requestor
|
|
142 |
put it on the transcript.
|
|
143 |
Return the result passed back by the requestor."
|
|
144 |
|
|
145 |
requestor isNil ifTrue:[
|
|
146 |
self showErrorMessage:aMessage position:position.
|
|
147 |
^ false
|
|
148 |
].
|
|
149 |
^ requestor warning:aMessage position:position to:endPos
|
|
150 |
!
|
|
151 |
|
|
152 |
syntaxError:aMessage position:position to:endPos
|
|
153 |
"a syntax error happened"
|
|
154 |
|
|
155 |
self notifyError:(' Error:' , aMessage) position:position to:endPos.
|
|
156 |
exitBlock notNil ifTrue:[exitBlock value].
|
|
157 |
^ false
|
|
158 |
!
|
|
159 |
|
|
160 |
syntaxError:aMessage position:position
|
|
161 |
"a syntax error happened - only start position is known"
|
|
162 |
|
|
163 |
^ self syntaxError:aMessage position:position to:nil
|
|
164 |
!
|
|
165 |
|
|
166 |
syntaxError:aMessage
|
|
167 |
"a syntax error happened - position is not known"
|
|
168 |
|
|
169 |
^ self syntaxError:aMessage position:tokenPosition
|
|
170 |
!
|
|
171 |
|
|
172 |
warning:aMessage position:position to:endPos
|
|
173 |
"a warning"
|
|
174 |
|
|
175 |
^ self notifyWarning:(' Warning:' , aMessage) position:position to:endPos
|
|
176 |
!
|
|
177 |
|
|
178 |
warning:aMessage position:position
|
|
179 |
"a warning - only start position is known"
|
|
180 |
|
|
181 |
^ self warning:aMessage position:position to:nil
|
|
182 |
!
|
|
183 |
|
|
184 |
warning:aMessage
|
|
185 |
"a warning - position is not known"
|
|
186 |
|
|
187 |
^ self warning:aMessage position:tokenPosition
|
|
188 |
! !
|
|
189 |
|
|
190 |
!Scanner methodsFor:'reading next token'!
|
|
191 |
|
3
|
192 |
skipComment
|
|
193 |
|comment|
|
|
194 |
|
|
195 |
comment := ''.
|
|
196 |
|
|
197 |
source next.
|
|
198 |
thisChar := source peek.
|
|
199 |
[thisChar notNil and:[thisChar ~~ (Character doubleQuote)]] whileTrue:[
|
|
200 |
thisChar == (Character cr) ifTrue:[
|
|
201 |
tokenLineNr := tokenLineNr + 1.
|
|
202 |
].
|
|
203 |
saveComments ifTrue:[
|
|
204 |
comment := comment copyWith:thisChar
|
|
205 |
].
|
|
206 |
source next.
|
|
207 |
thisChar := source peek
|
|
208 |
].
|
|
209 |
saveComments ifTrue:[
|
|
210 |
currentComments isNil ifTrue:[
|
|
211 |
currentComments := OrderedCollection with:comment
|
|
212 |
] ifFalse:[
|
|
213 |
currentComments add:comment
|
|
214 |
]
|
|
215 |
].
|
|
216 |
"skip final dQuote"
|
|
217 |
source next.
|
|
218 |
!
|
|
219 |
|
0
|
220 |
nextToken
|
|
221 |
"return the next token from the source-stream"
|
|
222 |
|
3
|
223 |
|skipping actionBlock comment|
|
0
|
224 |
|
|
225 |
peekChar notNil ifTrue:[
|
|
226 |
thisChar := peekChar.
|
|
227 |
peekChar := nil
|
|
228 |
] ifFalse:[
|
|
229 |
skipping := true.
|
|
230 |
[skipping] whileTrue:[
|
|
231 |
thisChar := source skipSeparatorsExceptCR.
|
|
232 |
thisChar == (Character cr) ifTrue:[
|
|
233 |
tokenLineNr := tokenLineNr + 1.
|
|
234 |
source next
|
|
235 |
] ifFalse:[
|
|
236 |
thisChar == (Character doubleQuote) ifTrue:[
|
3
|
237 |
"start of a comment"
|
|
238 |
|
|
239 |
self skipComment.
|
0
|
240 |
thisChar := source peek.
|
|
241 |
] ifFalse:[
|
|
242 |
skipping := false
|
|
243 |
]
|
|
244 |
]
|
|
245 |
].
|
|
246 |
thisChar isNil ifTrue:[
|
|
247 |
tokenType := #EOF.
|
|
248 |
^ tokenType
|
|
249 |
]
|
|
250 |
].
|
|
251 |
tokenPosition := source position.
|
|
252 |
|
|
253 |
actionBlock := actionArray at:(thisChar asciiValue).
|
|
254 |
actionBlock notNil ifTrue:[
|
|
255 |
^ actionBlock value:self value:thisChar
|
|
256 |
].
|
|
257 |
|
|
258 |
self syntaxError:('invalid character: ''' , thisChar asString , ''' ',
|
|
259 |
'(' , thisChar asciiValue printString , ')')
|
|
260 |
position:tokenPosition to:tokenPosition.
|
|
261 |
tokenType := #Error.
|
|
262 |
^ #Error
|
|
263 |
!
|
|
264 |
|
|
265 |
nextToken:aCharacter
|
|
266 |
tokenType := aCharacter.
|
|
267 |
source next.
|
|
268 |
^ tokenType
|
|
269 |
!
|
|
270 |
|
|
271 |
nextColonOrAssign
|
|
272 |
"colon has been read - look for = to make it an assign"
|
|
273 |
|
|
274 |
(source nextPeek == $=) ifTrue:[
|
|
275 |
source next.
|
|
276 |
tokenType := $_
|
|
277 |
] ifFalse:[
|
|
278 |
tokenType := $:
|
|
279 |
].
|
|
280 |
^ tokenType
|
|
281 |
!
|
|
282 |
|
|
283 |
nextSpecial
|
|
284 |
"a special character has been read, look for another one.
|
|
285 |
also -number is handled here"
|
|
286 |
|
|
287 |
|firstChar secondChar thirdChar string p|
|
|
288 |
|
|
289 |
firstChar := source next.
|
|
290 |
secondChar := source peek.
|
|
291 |
(firstChar == $-) ifTrue:[
|
|
292 |
secondChar isDigit ifTrue:[
|
|
293 |
self nextNumber.
|
|
294 |
tokenValue := tokenValue negated.
|
|
295 |
^ tokenType
|
|
296 |
]
|
|
297 |
].
|
|
298 |
string := firstChar asString.
|
|
299 |
((typeArray at:(secondChar asciiValue)) == #special) ifTrue:[
|
|
300 |
(secondChar == $-) ifTrue:[
|
|
301 |
"special- look if minus belongs to number following"
|
|
302 |
p := source position.
|
|
303 |
source next.
|
|
304 |
thirdChar := source peek.
|
|
305 |
source position:p.
|
|
306 |
thirdChar isDigit ifTrue:[
|
|
307 |
tokenName := string.
|
|
308 |
tokenType := #BinaryOperator.
|
|
309 |
^ tokenType
|
|
310 |
]
|
|
311 |
].
|
|
312 |
source next.
|
|
313 |
string := string copyWith:secondChar
|
|
314 |
].
|
|
315 |
tokenName := string.
|
|
316 |
tokenType := #BinaryOperator.
|
|
317 |
^ tokenType
|
|
318 |
!
|
|
319 |
|
|
320 |
nextCharacter
|
|
321 |
"a $ has been read - return a character token"
|
|
322 |
|
|
323 |
|nextChar|
|
|
324 |
|
|
325 |
source next.
|
|
326 |
nextChar := source next.
|
|
327 |
nextChar notNil ifTrue:[
|
|
328 |
tokenValue := nextChar.
|
|
329 |
tokenType := #Character
|
|
330 |
] ifFalse:[
|
|
331 |
tokenType := #EOF
|
|
332 |
].
|
|
333 |
^ tokenType
|
|
334 |
!
|
|
335 |
|
|
336 |
nextMantissa:radix
|
|
337 |
|nextChar value factor|
|
|
338 |
|
|
339 |
value := 0.
|
|
340 |
factor := 1.0 / radix.
|
|
341 |
nextChar := source peek.
|
|
342 |
[(nextChar notNil and:[nextChar isDigitRadix:radix])] whileTrue:[
|
|
343 |
value := value + (nextChar digitValue * factor).
|
|
344 |
factor := factor / radix.
|
|
345 |
nextChar := source nextPeek
|
|
346 |
].
|
|
347 |
^ value
|
|
348 |
!
|
|
349 |
|
|
350 |
nextNumber
|
|
351 |
|nextChar value radix s|
|
|
352 |
|
|
353 |
radix := 10.
|
|
354 |
value := Integer readFrom:source radix:radix.
|
|
355 |
nextChar := source peek.
|
|
356 |
(nextChar == $r) ifTrue:[
|
|
357 |
radix := value.
|
|
358 |
source next.
|
|
359 |
value := Integer readFrom:source radix:radix.
|
|
360 |
nextChar := source peek
|
|
361 |
].
|
|
362 |
(nextChar == $.) ifTrue:[
|
|
363 |
nextChar := source nextPeek.
|
|
364 |
(nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[
|
|
365 |
value := value asFloat + (self nextMantissa:radix).
|
|
366 |
nextChar := source peek
|
|
367 |
] ifFalse:[
|
3
|
368 |
nextChar == (Character cr) ifTrue:[
|
|
369 |
tokenLineNr := tokenLineNr + 1.
|
|
370 |
].
|
0
|
371 |
peekChar := $.
|
|
372 |
]
|
|
373 |
].
|
|
374 |
(nextChar == $e) ifTrue:[
|
|
375 |
nextChar := source nextPeek.
|
|
376 |
(nextChar notNil and:[(nextChar isDigitRadix:radix) or:['+-' includes:nextChar]]) ifTrue:[
|
|
377 |
s := 1.
|
|
378 |
(nextChar == $+) ifTrue:[
|
|
379 |
nextChar := source nextPeek
|
|
380 |
] ifFalse:[
|
|
381 |
(nextChar == $-) ifTrue:[
|
|
382 |
nextChar := source nextPeek.
|
|
383 |
s := s negated
|
|
384 |
]
|
|
385 |
].
|
|
386 |
value := value asFloat
|
|
387 |
* (10.0 raisedToInteger:((Integer readFrom:source radix:radix) * s))
|
|
388 |
]
|
|
389 |
].
|
|
390 |
tokenValue := value.
|
|
391 |
(value isMemberOf:Float) ifTrue:[
|
|
392 |
tokenType := #Float
|
|
393 |
] ifFalse:[
|
|
394 |
tokenType := #Integer
|
|
395 |
].
|
|
396 |
^ tokenType
|
|
397 |
!
|
|
398 |
|
|
399 |
nextId
|
|
400 |
|nextChar string oldString
|
|
401 |
index "{ Class: SmallInteger }"
|
|
402 |
max "{ Class: SmallInteger }" |
|
|
403 |
|
|
404 |
nextChar := source peek.
|
|
405 |
string := String new:10.
|
|
406 |
index := 0.
|
|
407 |
max := 10.
|
|
408 |
[true] whileTrue:[
|
|
409 |
(nextChar notNil and:[nextChar isAlphaNumeric]) ifFalse:[
|
|
410 |
^ string copyFrom:1 to:index
|
|
411 |
].
|
|
412 |
(index == max) ifTrue:[
|
|
413 |
oldString := string.
|
|
414 |
string := String new:(max * 2).
|
|
415 |
string replaceFrom:1 to:max with:oldString.
|
|
416 |
max := max * 2
|
|
417 |
].
|
|
418 |
index := index + 1.
|
|
419 |
string at:index put:nextChar.
|
|
420 |
nextChar := source nextPeek
|
|
421 |
]
|
|
422 |
!
|
|
423 |
|
|
424 |
nextIdentifier
|
|
425 |
|nextChar string firstChar|
|
|
426 |
|
|
427 |
string := source nextWord "self nextId".
|
|
428 |
nextChar := source peek.
|
|
429 |
(nextChar == $:) ifTrue:[
|
|
430 |
source next.
|
|
431 |
(source peek == $=) ifFalse:[
|
|
432 |
tokenName := string copyWith:nextChar.
|
|
433 |
tokenType := #Keyword.
|
|
434 |
^ self
|
|
435 |
].
|
|
436 |
peekChar := $_
|
|
437 |
].
|
|
438 |
firstChar := string at:1.
|
|
439 |
(firstChar == $s) ifTrue:[
|
|
440 |
(string = 'self') ifTrue:[tokenType := #Self. ^self].
|
|
441 |
(string = 'super') ifTrue:[tokenType := #Super. ^self]
|
|
442 |
].
|
|
443 |
(firstChar == $n) ifTrue:[
|
|
444 |
(string = 'nil') ifTrue:[tokenType := #Nil. ^self]
|
|
445 |
].
|
|
446 |
(firstChar == $t) ifTrue:[
|
|
447 |
(string = 'true') ifTrue:[tokenType := #True. ^self].
|
|
448 |
(string = 'thisContext') ifTrue:[tokenType := #ThisContext. ^self]
|
|
449 |
].
|
|
450 |
(firstChar == $f) ifTrue:[
|
|
451 |
(string = 'false') ifTrue:[tokenType := #False. ^self]
|
|
452 |
].
|
|
453 |
tokenName := string.
|
|
454 |
tokenType := #Identifier.
|
|
455 |
^ tokenType
|
|
456 |
!
|
|
457 |
|
|
458 |
nextPrimitive
|
|
459 |
|nextChar inPrimitive string
|
|
460 |
index "{ Class: SmallInteger }"
|
|
461 |
len "{ Class: SmallInteger }" |
|
|
462 |
|
|
463 |
nextChar := source nextPeek.
|
|
464 |
string := String new:500.
|
|
465 |
len := 500.
|
|
466 |
index := 1.
|
|
467 |
(nextChar == ${) ifTrue:[
|
|
468 |
nextChar := source nextPeek.
|
|
469 |
inPrimitive := true.
|
|
470 |
[inPrimitive] whileTrue:[
|
|
471 |
[nextChar == $%] whileFalse:[
|
|
472 |
string at:index put:nextChar.
|
|
473 |
(index == len) ifTrue:[
|
|
474 |
string := string , (String new:len).
|
|
475 |
len := len * 2
|
|
476 |
].
|
|
477 |
index := index + 1.
|
|
478 |
nextChar := source next
|
|
479 |
].
|
|
480 |
(source peek == $}) ifTrue:[
|
|
481 |
inPrimitive := false
|
|
482 |
] ifFalse:[
|
|
483 |
string at:index put:nextChar.
|
|
484 |
(index == len) ifTrue:[
|
|
485 |
string := string , (String new:len).
|
|
486 |
len := len * 2
|
|
487 |
].
|
|
488 |
index := index + 1.
|
|
489 |
nextChar := source next
|
|
490 |
]
|
|
491 |
].
|
|
492 |
source next.
|
|
493 |
tokenValue := string copyFrom:1 to:(index - 1).
|
|
494 |
tokenType := #Primitive.
|
|
495 |
tokenLineNr := tokenLineNr + (tokenValue occurrencesOf:(Character cr)).
|
|
496 |
^ tokenType
|
|
497 |
].
|
|
498 |
|
|
499 |
"a % alone is a binary operator"
|
|
500 |
tokenName := '%'.
|
|
501 |
tokenType := #BinaryOperator.
|
|
502 |
^ tokenType.
|
|
503 |
"
|
|
504 |
self syntaxError:('invalid character: ''' , nextChar asString , '''')
|
|
505 |
position:tokenPosition to:(tokenPosition + 1).
|
|
506 |
^ #Error
|
|
507 |
"
|
|
508 |
!
|
|
509 |
|
|
510 |
nextHash
|
|
511 |
|nextChar string|
|
|
512 |
|
|
513 |
nextChar := source nextPeek.
|
|
514 |
nextChar notNil ifTrue:[
|
|
515 |
nextChar isAlphaNumeric ifTrue:[
|
|
516 |
string := ''.
|
|
517 |
[nextChar notNil and:[nextChar isAlphaNumeric]] whileTrue:[
|
|
518 |
string := string , (source nextWord "self nextId").
|
|
519 |
nextChar := source peek.
|
|
520 |
(nextChar == $:) ifFalse:[
|
|
521 |
tokenValue := string asSymbol.
|
3
|
522 |
tokenType := #Symbol.
|
|
523 |
^ tokenType
|
0
|
524 |
].
|
|
525 |
string := string copyWith:nextChar.
|
|
526 |
nextChar := source nextPeek
|
|
527 |
].
|
|
528 |
tokenValue := string asSymbol.
|
3
|
529 |
tokenType := #Symbol.
|
0
|
530 |
^ tokenType
|
|
531 |
].
|
|
532 |
(nextChar == $( ) ifTrue:[
|
|
533 |
source next.
|
|
534 |
tokenType := #HashLeftParen.
|
|
535 |
^ tokenType
|
|
536 |
].
|
|
537 |
(nextChar == $[ ) ifTrue:[
|
|
538 |
"it seems that ST-80 supports Constant ByteArrays as #[...]
|
|
539 |
(seen in a PD program)"
|
|
540 |
source next.
|
|
541 |
tokenType := #HashLeftBrack.
|
|
542 |
^ tokenType
|
|
543 |
].
|
|
544 |
(nextChar == $' ) ifTrue:[
|
|
545 |
"it seems that ST-80 supports arbitrary symbols as #'...'
|
|
546 |
(seen in a PD program)"
|
|
547 |
self nextString.
|
|
548 |
tokenValue := tokenValue asSymbol.
|
|
549 |
tokenType := #Symbol.
|
|
550 |
^ tokenType
|
|
551 |
].
|
|
552 |
((typeArray at:(nextChar asciiValue)) == #special) ifTrue:[
|
|
553 |
string := source next asString.
|
|
554 |
nextChar := source peek.
|
|
555 |
nextChar notNil ifTrue:[
|
|
556 |
((typeArray at:(nextChar asciiValue)) == #special) ifTrue:[
|
|
557 |
source next.
|
|
558 |
string := string copyWith:nextChar
|
|
559 |
]
|
|
560 |
].
|
|
561 |
tokenValue := string asSymbol.
|
3
|
562 |
tokenType := #Symbol.
|
0
|
563 |
^ tokenType
|
|
564 |
]
|
|
565 |
].
|
3
|
566 |
"this allows hash to be used as binop -
|
|
567 |
I dont know, if this is correct ..."
|
|
568 |
|
|
569 |
tokenName := '#'.
|
|
570 |
tokenType := BinaryOperator.
|
|
571 |
^ tokenType
|
|
572 |
"
|
0
|
573 |
self syntaxError:'unexpected end-of-input in Symbol'
|
|
574 |
position:tokenPosition to:(tokenPosition + 1).
|
|
575 |
^ #Error
|
3
|
576 |
"
|
0
|
577 |
!
|
|
578 |
|
|
579 |
nextString
|
|
580 |
|nextChar string pos
|
|
581 |
index "{ Class: SmallInteger }"
|
|
582 |
len "{ Class: SmallInteger }"
|
|
583 |
inString|
|
|
584 |
|
|
585 |
string := String new:20.
|
|
586 |
len := 20.
|
|
587 |
index := 1.
|
|
588 |
pos := source position.
|
|
589 |
source next.
|
|
590 |
nextChar := source next.
|
|
591 |
inString := true.
|
|
592 |
|
|
593 |
[inString] whileTrue:[
|
|
594 |
nextChar isNil ifTrue:[
|
|
595 |
self syntaxError:'unexpected end-of-input in String'
|
|
596 |
position:pos to:(source position - 1).
|
|
597 |
tokenType := #EOF.
|
|
598 |
^ tokenType
|
|
599 |
].
|
|
600 |
(nextChar == Character cr) ifTrue:[
|
|
601 |
tokenLineNr := tokenLineNr + 1
|
|
602 |
].
|
|
603 |
(nextChar == Character quote) ifTrue:[
|
|
604 |
(source peek == Character quote) ifTrue:[
|
|
605 |
source next
|
|
606 |
] ifFalse:[
|
|
607 |
inString := false
|
|
608 |
]
|
|
609 |
].
|
|
610 |
inString ifTrue:[
|
|
611 |
string at:index put:nextChar.
|
|
612 |
(index == len) ifTrue:[
|
|
613 |
string := string , (String new:len).
|
|
614 |
len := len * 2
|
|
615 |
].
|
|
616 |
index := index + 1.
|
|
617 |
nextChar := source next
|
|
618 |
]
|
|
619 |
].
|
|
620 |
tokenValue := string copyFrom:1 to:(index - 1).
|
|
621 |
tokenType := #String.
|
|
622 |
^ tokenType
|
|
623 |
! !
|