0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
45
|
3 |
All Rights Reserved
|
0
|
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
|
76
|
14 |
instanceVariableNames:'source collectedSource
|
45
|
15 |
token tokenType tokenPosition tokenValue
|
|
16 |
tokenName tokenLineNr tokenRadix
|
64
|
17 |
hereChar peekChar
|
45
|
18 |
requestor exitBlock
|
|
19 |
errorFlag
|
|
20 |
ignoreErrors ignoreWarnings
|
|
21 |
saveComments currentComments
|
60
|
22 |
warnSTXSpecialComment warnUnderscoreInIdentifier
|
87
|
23 |
warnOldStyleAssignment
|
45
|
24 |
outStream outCol'
|
60
|
25 |
classVariableNames:'TypeArray ActionArray
|
|
26 |
AllowUnderscoreInIdentifier
|
87
|
27 |
Warnings
|
|
28 |
WarnSTXSpecials WarnOldStyleAssignment
|
60
|
29 |
WarnUnderscoreInIdentifier'
|
45
|
30 |
poolDictionaries:''
|
|
31 |
category:'System-Compiler'
|
0
|
32 |
!
|
|
33 |
|
|
34 |
Scanner comment:'
|
4
|
35 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
45
|
36 |
All Rights Reserved
|
30
|
37 |
|
98
|
38 |
$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.31 1995-07-23 02:24:35 claus Exp $
|
20
|
39 |
'!
|
0
|
40 |
|
20
|
41 |
!Scanner class methodsFor:'documentation'!
|
|
42 |
|
|
43 |
copyright
|
|
44 |
"
|
|
45 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
45
|
46 |
All Rights Reserved
|
20
|
47 |
|
|
48 |
This software is furnished under a license and may be used
|
|
49 |
only in accordance with the terms of that license and with the
|
|
50 |
inclusion of the above copyright notice. This software may not
|
|
51 |
be provided or otherwise made available to, or used by, any
|
|
52 |
other person. No title to or ownership of the software is
|
|
53 |
hereby transferred.
|
|
54 |
"
|
|
55 |
!
|
|
56 |
|
|
57 |
version
|
|
58 |
"
|
98
|
59 |
$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.31 1995-07-23 02:24:35 claus Exp $
|
20
|
60 |
"
|
|
61 |
!
|
|
62 |
|
|
63 |
documentation
|
|
64 |
"
|
|
65 |
Scanner reads from a stream and returns individual smalltalk tokens
|
75
|
66 |
|
|
67 |
TODO: some testers noticed, that ST-80's scanner methods are called
|
|
68 |
xLetter, xDigit etc. For code using these (internals), the nextNumber,
|
|
69 |
nextIdentifier etc. methods should be renamed.
|
20
|
70 |
"
|
|
71 |
! !
|
0
|
72 |
|
|
73 |
!Scanner class methodsFor:'instance creation'!
|
|
74 |
|
30
|
75 |
for:aStringOrStream
|
|
76 |
"return a new scanner reading from aStringOrStream"
|
0
|
77 |
|
30
|
78 |
^ (super new) initializeFor:aStringOrStream
|
0
|
79 |
! !
|
|
80 |
|
41
|
81 |
!Scanner class methodsFor:'defaults'!
|
|
82 |
|
80
|
83 |
warnings
|
|
84 |
"return true, if any warnings are to be shown"
|
|
85 |
|
|
86 |
^ Warnings
|
|
87 |
!
|
|
88 |
|
41
|
89 |
warnings:aBoolean
|
|
90 |
"this allows turning on/off warnings; the default is on.
|
|
91 |
You can turn off warnings in your 'private.rc' file with
|
45
|
92 |
Compiler warnings:false
|
41
|
93 |
"
|
|
94 |
|
|
95 |
Warnings := aBoolean
|
|
96 |
!
|
|
97 |
|
80
|
98 |
warnSTXSpecials
|
|
99 |
"return true, if ST/X specials are to be warned about"
|
|
100 |
|
|
101 |
^ WarnSTXSpecials
|
|
102 |
!
|
|
103 |
|
41
|
104 |
warnSTXSpecials:aBoolean
|
|
105 |
"this allows turning on/off warnings about stx specials.
|
|
106 |
If you get bored by those warnings, turn them off by adding
|
|
107 |
a line as:
|
45
|
108 |
Compiler warnSTXSpecials:false
|
41
|
109 |
in your 'private.rc' file"
|
|
110 |
|
|
111 |
WarnSTXSpecials := aBoolean
|
60
|
112 |
!
|
|
113 |
|
80
|
114 |
warnUnderscoreInIdentifier
|
|
115 |
"return true, if underscores in identifiers are to be warned about"
|
|
116 |
|
|
117 |
^ WarnUnderscoreInIdentifier
|
|
118 |
!
|
|
119 |
|
60
|
120 |
warnUnderscoreInIdentifier:aBoolean
|
|
121 |
"this allows turning on/off warnings about underscores in identifiers.
|
|
122 |
If you get bored by those warnings, turn them off by adding
|
|
123 |
a line as:
|
|
124 |
Compiler warnUnderscoreInIdentifier:false
|
|
125 |
in your 'private.rc' file"
|
|
126 |
|
|
127 |
WarnUnderscoreInIdentifier := aBoolean
|
|
128 |
!
|
|
129 |
|
87
|
130 |
warnOldStyleAssignment
|
|
131 |
"return true, if underscore-assignment (pre ST-80v4 syntax) are to be warned about"
|
|
132 |
|
|
133 |
^ WarnOldStyleAssignment
|
|
134 |
!
|
|
135 |
|
|
136 |
warnOldStyleAssignment:aBoolean
|
|
137 |
"this allows turning on/off warnings about underscore-assignment (pre ST-80v4 syntax).
|
|
138 |
If you get bored by those warnings, turn them off by adding
|
|
139 |
a line as:
|
|
140 |
Compiler warnOldStyleAssignment:false
|
|
141 |
in your 'private.rc' file"
|
|
142 |
|
|
143 |
WarnOldStyleAssignment := aBoolean
|
|
144 |
!
|
|
145 |
|
80
|
146 |
allowUnderscoreInIdentifier
|
|
147 |
"return true, if underscores are allowed in identifiers"
|
|
148 |
|
|
149 |
^ AllowUnderscoreInIdentifier
|
|
150 |
!
|
|
151 |
|
60
|
152 |
allowUnderscoreInIdentifier:aBoolean
|
|
153 |
"this allows turning on/off underscores in identifiers.
|
|
154 |
If turned off (the default), underscores are not allowed in identifiers,
|
|
155 |
but instead scanned as assignment character (old ST/80 syntax).
|
|
156 |
If turned on, underscores are in identifiers are allowed, while extra
|
|
157 |
underscores are still scanned as assignment.
|
|
158 |
If you have to fileIn VV-Vsn2 classes,
|
|
159 |
add a line such as:
|
|
160 |
Compiler allowUnderscoreInIdentifiers:false
|
|
161 |
in your 'private.rc'/'smalltalk.rc' file"
|
|
162 |
|
71
|
163 |
AllowUnderscoreInIdentifier := aBoolean.
|
|
164 |
self setupActions
|
41
|
165 |
! !
|
|
166 |
|
33
|
167 |
!Scanner class methodsFor:'initialization'!
|
|
168 |
|
60
|
169 |
initialize
|
|
170 |
Warnings := true.
|
|
171 |
WarnSTXSpecials := true.
|
|
172 |
WarnUnderscoreInIdentifier := true.
|
87
|
173 |
WarnOldStyleAssignment := true.
|
60
|
174 |
AllowUnderscoreInIdentifier := false.
|
|
175 |
!
|
|
176 |
|
33
|
177 |
setupActions
|
|
178 |
|block|
|
|
179 |
|
|
180 |
ActionArray := Array new:256.
|
|
181 |
TypeArray := Array new:256.
|
|
182 |
|
|
183 |
block := [:s :char | s nextNumber].
|
|
184 |
($0 asciiValue) to:($9 asciiValue) do:[:index |
|
45
|
185 |
ActionArray at:index put:block
|
33
|
186 |
].
|
|
187 |
|
87
|
188 |
block := [:s :char | s nextSpecial].
|
89
|
189 |
#( $& $- $+ $= $* $/ $\ $< $> $~ $@ $, $? "new:" $!! ) do:[:binop |
|
87
|
190 |
TypeArray at:(binop asciiValue) put:#special.
|
|
191 |
ActionArray at:(binop asciiValue) put:block
|
|
192 |
].
|
|
193 |
|
|
194 |
block := [:s :char | s nextToken:char].
|
89
|
195 |
#( $; $. $( $) $[ $] "$!!" $^ $| $_ ) do:[:ch |
|
87
|
196 |
ActionArray at:(ch asciiValue) put:block
|
|
197 |
].
|
|
198 |
|
33
|
199 |
block := [:s :char | s nextIdentifier].
|
|
200 |
($a asciiValue) to:($z asciiValue) do:[:index |
|
45
|
201 |
ActionArray at:index put:block
|
33
|
202 |
].
|
|
203 |
($A asciiValue) to:($Z asciiValue) do:[:index |
|
45
|
204 |
ActionArray at:index put:block
|
33
|
205 |
].
|
71
|
206 |
AllowUnderscoreInIdentifier ifTrue:[
|
|
207 |
ActionArray at:$_ asciiValue put:block
|
|
208 |
].
|
33
|
209 |
|
|
210 |
"kludge: action is characterToken, but type is special"
|
|
211 |
TypeArray at:($| asciiValue) put:#special.
|
|
212 |
|
80
|
213 |
"kludge: action is nextColonOrAssign, but type is special"
|
|
214 |
TypeArray at:($: asciiValue) put:#special.
|
|
215 |
|
33
|
216 |
ActionArray at:($' asciiValue) put:[:s :char | s nextString].
|
|
217 |
ActionArray at:($$ asciiValue) put:[:s :char | s nextCharacter].
|
|
218 |
ActionArray at:($# asciiValue) put:[:s :char | s nextHash].
|
|
219 |
ActionArray at:($% asciiValue) put:[:s :char | s nextPrimitive].
|
|
220 |
ActionArray at:($: asciiValue) put:[:s :char | s nextColonOrAssign]
|
|
221 |
|
|
222 |
"
|
|
223 |
Scanner setupActions
|
|
224 |
"
|
|
225 |
! !
|
|
226 |
|
98
|
227 |
!Scanner methodsFor:'ST-80 compatibility'!
|
|
228 |
|
|
229 |
endOfLastToken
|
|
230 |
^ source position
|
|
231 |
! !
|
|
232 |
|
0
|
233 |
!Scanner methodsFor:'private'!
|
|
234 |
|
30
|
235 |
initializeFor:aStringOrStream
|
0
|
236 |
"initialize -
|
|
237 |
if this is the first time, setup character- and action tables"
|
|
238 |
|
49
|
239 |
self initialize.
|
|
240 |
|
30
|
241 |
aStringOrStream isStream ifFalse:[
|
45
|
242 |
source := ReadStream on:aStringOrStream
|
30
|
243 |
] ifTrue:[
|
45
|
244 |
source := aStringOrStream.
|
30
|
245 |
].
|
0
|
246 |
!
|
|
247 |
|
3
|
248 |
initialize
|
|
249 |
"prepare a scan"
|
|
250 |
|
|
251 |
errorFlag := false.
|
|
252 |
tokenLineNr := 1.
|
|
253 |
currentComments := nil.
|
|
254 |
saveComments := false.
|
7
|
255 |
ignoreErrors := false.
|
41
|
256 |
ignoreWarnings := Warnings not.
|
49
|
257 |
warnSTXSpecialComment := WarnSTXSpecials.
|
60
|
258 |
warnUnderscoreInIdentifier := WarnUnderscoreInIdentifier.
|
87
|
259 |
warnOldStyleAssignment := WarnOldStyleAssignment.
|
49
|
260 |
ActionArray isNil ifTrue:[
|
|
261 |
self class setupActions
|
|
262 |
]
|
3
|
263 |
!
|
|
264 |
|
0
|
265 |
notifying:anObject
|
|
266 |
"set the requestor to be notified"
|
|
267 |
|
|
268 |
requestor := anObject
|
|
269 |
!
|
|
270 |
|
76
|
271 |
collectedSource
|
|
272 |
^ collectedSource
|
|
273 |
!
|
|
274 |
|
7
|
275 |
ignoreErrors
|
|
276 |
"turn off notification of errors"
|
|
277 |
|
|
278 |
ignoreErrors := true
|
|
279 |
!
|
|
280 |
|
17
|
281 |
ignoreWarnings
|
|
282 |
"turn off notification of warnings"
|
|
283 |
|
|
284 |
ignoreWarnings := true
|
|
285 |
!
|
|
286 |
|
0
|
287 |
backupPosition
|
|
288 |
"if reading from a stream, at the end we might have read
|
|
289 |
one token too many"
|
|
290 |
|
|
291 |
(tokenType == #EOF) ifFalse:[
|
45
|
292 |
source position:tokenPosition
|
0
|
293 |
]
|
20
|
294 |
!
|
|
295 |
|
|
296 |
beginComment
|
|
297 |
^ self
|
|
298 |
!
|
|
299 |
|
|
300 |
endComment:comment
|
|
301 |
saveComments ifTrue:[
|
45
|
302 |
currentComments isNil ifTrue:[
|
|
303 |
currentComments := OrderedCollection with:comment
|
|
304 |
] ifFalse:[
|
|
305 |
currentComments add:comment
|
|
306 |
]
|
20
|
307 |
].
|
81
|
308 |
! !
|
|
309 |
|
|
310 |
!Scanner methodsFor:'directives'!
|
|
311 |
|
|
312 |
parseDirectiveStringArg
|
|
313 |
hereChar == $' ifTrue:[
|
|
314 |
self nextString.
|
|
315 |
tokenType == #String ifTrue:[
|
|
316 |
^ tokenValue
|
|
317 |
]
|
|
318 |
].
|
|
319 |
^ nil
|
|
320 |
!
|
|
321 |
|
|
322 |
parseDirectiveStringListArg
|
|
323 |
|list|
|
|
324 |
|
|
325 |
list := OrderedCollection new.
|
|
326 |
|
|
327 |
[hereChar == $'] whileTrue:[
|
|
328 |
list addLast:self parseDirectiveStringArg.
|
|
329 |
source skipSeparatorsExceptCR.
|
|
330 |
hereChar := source peek.
|
|
331 |
(hereChar == $,) ifTrue:[
|
|
332 |
source next.
|
|
333 |
source skipSeparatorsExceptCR.
|
|
334 |
hereChar := source peek.
|
|
335 |
].
|
|
336 |
].
|
|
337 |
^ list
|
74
|
338 |
!
|
|
339 |
|
|
340 |
parseDirective
|
81
|
341 |
|directive packageName namespace list|
|
74
|
342 |
|
|
343 |
source next.
|
|
344 |
source skipSeparatorsExceptCR.
|
|
345 |
hereChar := source peek.
|
|
346 |
hereChar isLetter ifTrue:[
|
|
347 |
directive := source nextWord.
|
|
348 |
source peek == $: ifTrue:[
|
|
349 |
source next.
|
|
350 |
source skipSeparatorsExceptCR.
|
|
351 |
hereChar := source peek.
|
|
352 |
|
|
353 |
"
|
|
354 |
Package: 'name-of-package'
|
|
355 |
"
|
|
356 |
directive = 'Package' ifTrue:[
|
81
|
357 |
packageName := self parseDirectiveStringArg.
|
|
358 |
packageName notNil ifTrue:[
|
|
359 |
(requestor respondsTo:#setPackage:) ifTrue:[
|
|
360 |
requestor setPackage:packageName
|
|
361 |
].
|
74
|
362 |
].
|
|
363 |
].
|
|
364 |
|
|
365 |
"
|
81
|
366 |
Namespace: 'name-of-package'
|
|
367 |
"
|
|
368 |
directive = 'Namespace' ifTrue:[
|
|
369 |
namespace := self parseDirectiveStringArg.
|
|
370 |
namespace notNil ifTrue:[
|
|
371 |
(requestor respondsTo:#setNameSpace:) ifTrue:[
|
|
372 |
requestor setNameSpace:namespace
|
|
373 |
].
|
|
374 |
].
|
|
375 |
].
|
|
376 |
|
|
377 |
"
|
|
378 |
Uses: 'nameSpace1', ... , 'nameSpace2'
|
|
379 |
"
|
|
380 |
directive = 'Uses' ifTrue:[
|
|
381 |
list := self parseDirectiveStringListArg.
|
|
382 |
(requestor respondsTo:#useNameSpaces:) ifTrue:[
|
|
383 |
requestor useNameSpaces:list
|
|
384 |
].
|
|
385 |
].
|
|
386 |
"
|
74
|
387 |
Prerequisites: 'name-of-package', ... , 'name-of-package'
|
|
388 |
"
|
|
389 |
directive = 'Prerequisites' ifTrue:[
|
81
|
390 |
list := self parseDirectiveStringListArg.
|
|
391 |
(requestor respondsTo:#requirePackages:) ifTrue:[
|
|
392 |
requestor requirePackages:list
|
74
|
393 |
].
|
|
394 |
].
|
|
395 |
]
|
|
396 |
].
|
|
397 |
hereChar := source peek.
|
0
|
398 |
! !
|
|
399 |
|
|
400 |
!Scanner methodsFor:'error handling'!
|
|
401 |
|
|
402 |
showErrorMessage:aMessage position:pos
|
|
403 |
"show an errormessage on the Transcript"
|
|
404 |
|
7
|
405 |
ignoreErrors ifFalse:[
|
45
|
406 |
Smalltalk silentLoading == true ifFalse:[
|
|
407 |
Transcript showCr:(pos printString , ' ' , aMessage)
|
|
408 |
]
|
7
|
409 |
]
|
0
|
410 |
!
|
|
411 |
|
|
412 |
notifyError:aMessage position:position to:endPos
|
|
413 |
"notify requestor of an error - if there is no requestor
|
53
|
414 |
put it on the transcript. Requestor is typically the CodeView
|
|
415 |
in which the accept/doIt was triggered, or the PositionableStream
|
|
416 |
which does the fileIn. The requestor may decide how to highlight the
|
|
417 |
error (and/or to abort the compile).
|
0
|
418 |
Return the result passed back by the requestor."
|
|
419 |
|
53
|
420 |
ignoreErrors ifFalse:[
|
|
421 |
requestor isNil ifTrue:[
|
|
422 |
self showErrorMessage:aMessage position:position.
|
|
423 |
^ false
|
|
424 |
].
|
83
|
425 |
^ requestor error:aMessage position:position to:endPos from:self
|
0
|
426 |
].
|
53
|
427 |
^ false
|
0
|
428 |
!
|
|
429 |
|
|
430 |
notifyWarning:aMessage position:position to:endPos
|
|
431 |
"notify requestor of an warning - if there is no requestor
|
|
432 |
put it on the transcript.
|
|
433 |
Return the result passed back by the requestor."
|
|
434 |
|
53
|
435 |
ignoreWarnings ifFalse:[
|
|
436 |
requestor isNil ifTrue:[
|
45
|
437 |
self showErrorMessage:aMessage position:position.
|
53
|
438 |
^ false
|
45
|
439 |
].
|
83
|
440 |
^ requestor warning:aMessage position:position to:endPos from:self
|
0
|
441 |
].
|
53
|
442 |
^ false
|
0
|
443 |
!
|
|
444 |
|
|
445 |
syntaxError:aMessage position:position to:endPos
|
|
446 |
"a syntax error happened"
|
|
447 |
|
91
|
448 |
self notifyError:('Error:' , aMessage) position:position to:endPos.
|
0
|
449 |
exitBlock notNil ifTrue:[exitBlock value].
|
|
450 |
^ false
|
|
451 |
!
|
|
452 |
|
|
453 |
syntaxError:aMessage position:position
|
|
454 |
"a syntax error happened - only start position is known"
|
|
455 |
|
|
456 |
^ self syntaxError:aMessage position:position to:nil
|
|
457 |
!
|
|
458 |
|
|
459 |
syntaxError:aMessage
|
|
460 |
"a syntax error happened - position is not known"
|
|
461 |
|
|
462 |
^ self syntaxError:aMessage position:tokenPosition
|
|
463 |
!
|
|
464 |
|
|
465 |
warning:aMessage position:position to:endPos
|
|
466 |
"a warning"
|
|
467 |
|
30
|
468 |
^ self notifyWarning:('Warning: ' , aMessage) position:position to:endPos
|
0
|
469 |
!
|
|
470 |
|
|
471 |
warning:aMessage position:position
|
|
472 |
"a warning - only start position is known"
|
|
473 |
|
|
474 |
^ self warning:aMessage position:position to:nil
|
|
475 |
!
|
|
476 |
|
|
477 |
warning:aMessage
|
|
478 |
"a warning - position is not known"
|
|
479 |
|
|
480 |
^ self warning:aMessage position:tokenPosition
|
87
|
481 |
!
|
|
482 |
|
|
483 |
warnOldStyleAssignmentAt:position
|
|
484 |
ignoreWarnings ifFalse:[
|
|
485 |
warnOldStyleAssignment ifTrue:[
|
|
486 |
self
|
|
487 |
warning:'old style assignment - please change to use '':='''
|
|
488 |
position:position to:position.
|
|
489 |
"
|
|
490 |
only warn once (per method)
|
|
491 |
"
|
|
492 |
warnOldStyleAssignment := false
|
|
493 |
]
|
|
494 |
]
|
|
495 |
!
|
|
496 |
|
|
497 |
warnUnderscoreAt:position
|
|
498 |
ignoreWarnings ifFalse:[
|
|
499 |
warnUnderscoreInIdentifier ifTrue:[
|
|
500 |
self
|
|
501 |
warning:'underscores in identifiers/symbols are nonportable'
|
|
502 |
position:position to:position.
|
|
503 |
"
|
|
504 |
only warn once (per method)
|
|
505 |
"
|
|
506 |
warnUnderscoreInIdentifier := false
|
|
507 |
]
|
|
508 |
]
|
0
|
509 |
! !
|
|
510 |
|
17
|
511 |
!Scanner methodsFor:'general scanning'!
|
|
512 |
|
|
513 |
scanPositionsFor:aTokenString inString:aSourceString
|
|
514 |
"scan aSourceString for occurrances of aTokenString.
|
|
515 |
Return a collection of start positions.
|
|
516 |
Added for VW compatibility (to support syntax-highlight)."
|
|
517 |
|
|
518 |
|searchType searchName searchValue positions t|
|
|
519 |
|
|
520 |
"
|
|
521 |
first, look what kind of token we have to search for
|
|
522 |
"
|
|
523 |
self initializeFor:(ReadStream on:aTokenString).
|
|
524 |
self nextToken.
|
|
525 |
searchType := tokenType.
|
|
526 |
searchName := tokenName.
|
|
527 |
searchValue := tokenValue.
|
|
528 |
|
|
529 |
"
|
|
530 |
start the real work ...
|
|
531 |
"
|
|
532 |
self initializeFor:(ReadStream on:aSourceString).
|
|
533 |
positions := OrderedCollection new.
|
|
534 |
|
|
535 |
[(t := self nextToken) ~~ #EOF] whileTrue:[
|
45
|
536 |
searchType == t ifTrue:[
|
|
537 |
(searchName isNil or:[tokenName = searchName]) ifTrue:[
|
|
538 |
(searchValue isNil or:[tokenValue = searchValue]) ifTrue:[
|
|
539 |
positions add:tokenPosition.
|
|
540 |
]
|
|
541 |
]
|
|
542 |
]
|
17
|
543 |
].
|
|
544 |
|
|
545 |
^ positions
|
|
546 |
|
|
547 |
"
|
30
|
548 |
Scanner new scanPositionsFor:'hello' inString:'foo bar hello baz hello'
|
|
549 |
Scanner new scanPositionsFor:'3.14' inString:'foo 3.145 bar hello 3.14 baz hello 3.14'
|
|
550 |
Scanner new scanPositionsFor:'16' inString:'foo 16 bar hello 16r10 baz hello 2r10000'
|
17
|
551 |
"
|
|
552 |
! !
|
|
553 |
|
0
|
554 |
!Scanner methodsFor:'reading next token'!
|
|
555 |
|
3
|
556 |
skipComment
|
69
|
557 |
|commentStream startPos|
|
3
|
558 |
|
69
|
559 |
saveComments ifTrue:[
|
|
560 |
commentStream := WriteStream on:''.
|
|
561 |
self beginComment.
|
|
562 |
].
|
3
|
563 |
|
20
|
564 |
outStream notNil ifTrue:[
|
45
|
565 |
outStream nextPut:Character doubleQuote.
|
|
566 |
outCol := outCol + 1
|
20
|
567 |
].
|
|
568 |
|
7
|
569 |
startPos := source position.
|
3
|
570 |
source next.
|
64
|
571 |
hereChar := source peek.
|
15
|
572 |
|
74
|
573 |
"
|
|
574 |
special ST/X addition:
|
17
|
575 |
a $/ right after the initial double quote makes it an up-to-end-of-line comment,
|
15
|
576 |
which is very useful to comment out parts of filed-in source code.
|
17
|
577 |
Since this is non-standard, use it in very rare cases only.
|
|
578 |
(maybe the upcoming ansi-standard adds something similar - in this case, I will
|
|
579 |
change it without notice)"
|
15
|
580 |
|
64
|
581 |
hereChar == $/ ifTrue:[
|
|
582 |
[hereChar notNil and:[hereChar ~~ Character cr]] whileTrue:[
|
45
|
583 |
saveComments ifTrue:[
|
69
|
584 |
commentStream nextPut:hereChar
|
45
|
585 |
].
|
|
586 |
outStream notNil ifTrue:[
|
64
|
587 |
outStream nextPut:hereChar.
|
45
|
588 |
outCol := outCol + 1
|
|
589 |
].
|
64
|
590 |
hereChar := source nextPeek.
|
45
|
591 |
].
|
|
592 |
tokenLineNr := tokenLineNr + 1.
|
|
593 |
ignoreWarnings ifFalse:[
|
|
594 |
warnSTXSpecialComment ifTrue:[
|
|
595 |
self warning:'end-of-line comments are a nonstandard feature of ST/X'
|
|
596 |
position:startPos to:(source position).
|
|
597 |
"
|
|
598 |
only warn once
|
|
599 |
"
|
|
600 |
warnSTXSpecialComment := false
|
|
601 |
]
|
|
602 |
].
|
|
603 |
outStream notNil ifTrue:[
|
|
604 |
outStream cr.
|
|
605 |
outCol := 1
|
|
606 |
].
|
15
|
607 |
] ifFalse:[
|
74
|
608 |
hereChar == ${ ifTrue:[
|
|
609 |
"
|
|
610 |
special ST/X addition:
|
|
611 |
a ${ right after the initial double quote starts a directive
|
|
612 |
"
|
|
613 |
self parseDirective
|
|
614 |
].
|
|
615 |
|
64
|
616 |
[hereChar notNil and:[hereChar ~~ (Character doubleQuote)]] whileTrue:[
|
|
617 |
hereChar == (Character cr) ifTrue:[
|
45
|
618 |
tokenLineNr := tokenLineNr + 1.
|
|
619 |
].
|
|
620 |
saveComments ifTrue:[
|
69
|
621 |
commentStream nextPut:hereChar
|
45
|
622 |
].
|
|
623 |
outStream notNil ifTrue:[
|
64
|
624 |
outStream nextPut:hereChar.
|
45
|
625 |
outCol := outCol + 1
|
|
626 |
].
|
64
|
627 |
hereChar := source nextPeek
|
45
|
628 |
].
|
64
|
629 |
hereChar isNil ifTrue:[
|
45
|
630 |
self warning:'unclosed comment' position:startPos to:(source position)
|
|
631 |
] ifFalse:[
|
|
632 |
outStream notNil ifTrue:[
|
|
633 |
outStream nextPut:(Character doubleQuote).
|
|
634 |
outCol := outCol + 1
|
|
635 |
].
|
|
636 |
]
|
3
|
637 |
].
|
15
|
638 |
|
20
|
639 |
"skip final dQuote or cr"
|
3
|
640 |
source next.
|
20
|
641 |
|
69
|
642 |
saveComments ifTrue:[
|
|
643 |
self endComment:commentStream contents.
|
|
644 |
].
|
3
|
645 |
!
|
|
646 |
|
0
|
647 |
nextToken
|
|
648 |
"return the next token from the source-stream"
|
|
649 |
|
41
|
650 |
|skipping actionBlock|
|
0
|
651 |
|
|
652 |
peekChar notNil ifTrue:[
|
64
|
653 |
hereChar := peekChar.
|
45
|
654 |
peekChar := nil
|
0
|
655 |
] ifFalse:[
|
45
|
656 |
skipping := true.
|
|
657 |
[skipping] whileTrue:[
|
|
658 |
outStream notNil ifTrue:[
|
64
|
659 |
[(hereChar := source peek) == Character space] whileTrue:[
|
45
|
660 |
source next.
|
|
661 |
outStream space.
|
|
662 |
outCol := outCol + 1.
|
|
663 |
]
|
|
664 |
] ifFalse:[
|
64
|
665 |
hereChar := source skipSeparatorsExceptCR.
|
45
|
666 |
].
|
64
|
667 |
hereChar == (Character cr) ifTrue:[
|
45
|
668 |
tokenLineNr := tokenLineNr + 1.
|
|
669 |
source next.
|
|
670 |
outStream notNil ifTrue:[
|
|
671 |
outStream cr.
|
|
672 |
outCol := 1
|
|
673 |
]
|
|
674 |
] ifFalse:[
|
64
|
675 |
hereChar == (Character doubleQuote) ifTrue:[
|
45
|
676 |
"start of a comment"
|
3
|
677 |
|
45
|
678 |
self skipComment.
|
64
|
679 |
hereChar := source peek.
|
45
|
680 |
] ifFalse:[
|
|
681 |
skipping := false
|
|
682 |
]
|
|
683 |
]
|
|
684 |
].
|
64
|
685 |
hereChar isNil ifTrue:[
|
45
|
686 |
tokenType := #EOF.
|
|
687 |
^ tokenType
|
|
688 |
]
|
0
|
689 |
].
|
|
690 |
tokenPosition := source position.
|
|
691 |
|
64
|
692 |
actionBlock := ActionArray at:(hereChar asciiValue).
|
0
|
693 |
actionBlock notNil ifTrue:[
|
64
|
694 |
^ actionBlock value:self value:hereChar
|
0
|
695 |
].
|
|
696 |
|
64
|
697 |
self syntaxError:('invalid character: ''' , hereChar asString , ''' ',
|
|
698 |
'(' , hereChar asciiValue printString , ')')
|
45
|
699 |
position:tokenPosition to:tokenPosition.
|
0
|
700 |
tokenType := #Error.
|
|
701 |
^ #Error
|
|
702 |
!
|
|
703 |
|
|
704 |
nextToken:aCharacter
|
|
705 |
tokenType := aCharacter.
|
|
706 |
source next.
|
|
707 |
^ tokenType
|
|
708 |
!
|
|
709 |
|
|
710 |
nextColonOrAssign
|
|
711 |
"colon has been read - look for = to make it an assign"
|
|
712 |
|
|
713 |
(source nextPeek == $=) ifTrue:[
|
45
|
714 |
source next.
|
|
715 |
tokenType := $_
|
0
|
716 |
] ifFalse:[
|
45
|
717 |
tokenType := $:
|
0
|
718 |
].
|
|
719 |
^ tokenType
|
|
720 |
!
|
|
721 |
|
|
722 |
nextSpecial
|
|
723 |
"a special character has been read, look for another one.
|
|
724 |
also -number is handled here"
|
|
725 |
|
|
726 |
|firstChar secondChar thirdChar string p|
|
|
727 |
|
|
728 |
firstChar := source next.
|
|
729 |
secondChar := source peek.
|
|
730 |
(firstChar == $-) ifTrue:[
|
45
|
731 |
secondChar isDigit ifTrue:[
|
|
732 |
self nextNumber.
|
|
733 |
tokenValue := tokenValue negated.
|
|
734 |
^ tokenType
|
|
735 |
]
|
0
|
736 |
].
|
|
737 |
string := firstChar asString.
|
20
|
738 |
secondChar notNil ifTrue:[
|
45
|
739 |
((TypeArray at:(secondChar asciiValue)) == #special) ifTrue:[
|
|
740 |
(secondChar == $-) ifTrue:[
|
|
741 |
"special- look if minus belongs to number following"
|
|
742 |
p := source position.
|
|
743 |
source next.
|
|
744 |
thirdChar := source peek.
|
|
745 |
source position:p.
|
|
746 |
thirdChar isDigit ifTrue:[
|
|
747 |
tokenName := string.
|
|
748 |
tokenType := #BinaryOperator.
|
|
749 |
^ tokenType
|
|
750 |
]
|
|
751 |
].
|
|
752 |
source next.
|
|
753 |
string := string copyWith:secondChar
|
|
754 |
].
|
0
|
755 |
].
|
|
756 |
tokenName := string.
|
|
757 |
tokenType := #BinaryOperator.
|
|
758 |
^ tokenType
|
|
759 |
!
|
|
760 |
|
|
761 |
nextCharacter
|
|
762 |
"a $ has been read - return a character token"
|
|
763 |
|
|
764 |
|nextChar|
|
|
765 |
|
|
766 |
source next.
|
|
767 |
nextChar := source next.
|
|
768 |
nextChar notNil ifTrue:[
|
45
|
769 |
tokenValue := nextChar.
|
|
770 |
tokenType := #Character
|
0
|
771 |
] ifFalse:[
|
45
|
772 |
tokenType := #EOF
|
0
|
773 |
].
|
|
774 |
^ tokenType
|
|
775 |
!
|
|
776 |
|
|
777 |
nextMantissa:radix
|
|
778 |
|nextChar value factor|
|
|
779 |
|
|
780 |
value := 0.
|
|
781 |
factor := 1.0 / radix.
|
|
782 |
nextChar := source peek.
|
|
783 |
[(nextChar notNil and:[nextChar isDigitRadix:radix])] whileTrue:[
|
45
|
784 |
value := value + (nextChar digitValue * factor).
|
|
785 |
factor := factor / radix.
|
|
786 |
nextChar := source nextPeek
|
0
|
787 |
].
|
|
788 |
^ value
|
|
789 |
!
|
|
790 |
|
|
791 |
nextNumber
|
30
|
792 |
|nextChar value s|
|
0
|
793 |
|
30
|
794 |
tokenRadix := 10.
|
|
795 |
value := Integer readFrom:source radix:tokenRadix.
|
0
|
796 |
nextChar := source peek.
|
|
797 |
(nextChar == $r) ifTrue:[
|
45
|
798 |
tokenRadix := value.
|
|
799 |
source next.
|
|
800 |
s := 1.
|
|
801 |
source peek == $- ifTrue:[
|
|
802 |
source next.
|
|
803 |
s := -1
|
|
804 |
].
|
|
805 |
value := Integer readFrom:source radix:tokenRadix.
|
|
806 |
value := value * s.
|
|
807 |
nextChar := source peek
|
0
|
808 |
].
|
|
809 |
(nextChar == $.) ifTrue:[
|
45
|
810 |
nextChar := source nextPeek.
|
|
811 |
(nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[
|
|
812 |
value := value asFloat + (self nextMantissa:tokenRadix).
|
|
813 |
nextChar := source peek
|
|
814 |
] ifFalse:[
|
|
815 |
nextChar == (Character cr) ifTrue:[
|
|
816 |
tokenLineNr := tokenLineNr + 1.
|
|
817 |
].
|
|
818 |
peekChar := $.
|
|
819 |
]
|
0
|
820 |
].
|
30
|
821 |
((nextChar == $e) or:[nextChar == $E]) ifTrue:[
|
45
|
822 |
nextChar := source nextPeek.
|
|
823 |
(nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[
|
|
824 |
s := 1.
|
|
825 |
(nextChar == $+) ifTrue:[
|
|
826 |
nextChar := source nextPeek
|
|
827 |
] ifFalse:[
|
|
828 |
(nextChar == $-) ifTrue:[
|
|
829 |
nextChar := source nextPeek.
|
|
830 |
s := s negated
|
|
831 |
]
|
|
832 |
].
|
|
833 |
value := value asFloat
|
|
834 |
* (10.0 raisedToInteger:((Integer readFrom:source radix:tokenRadix) * s))
|
|
835 |
]
|
0
|
836 |
].
|
|
837 |
tokenValue := value.
|
|
838 |
(value isMemberOf:Float) ifTrue:[
|
45
|
839 |
tokenType := #Float
|
0
|
840 |
] ifFalse:[
|
45
|
841 |
tokenType := #Integer
|
0
|
842 |
].
|
|
843 |
^ tokenType
|
|
844 |
!
|
|
845 |
|
|
846 |
nextId
|
|
847 |
|nextChar string oldString
|
|
848 |
index "{ Class: SmallInteger }"
|
|
849 |
max "{ Class: SmallInteger }" |
|
|
850 |
|
|
851 |
nextChar := source peek.
|
96
|
852 |
string := String basicNew:20.
|
0
|
853 |
index := 0.
|
|
854 |
max := 10.
|
|
855 |
[true] whileTrue:[
|
45
|
856 |
(nextChar notNil and:[nextChar isLetterOrDigit]) ifFalse:[
|
|
857 |
^ string copyTo:index
|
|
858 |
].
|
|
859 |
(index == max) ifTrue:[
|
|
860 |
oldString := string.
|
96
|
861 |
string := String basicNew:(max * 2).
|
45
|
862 |
string replaceFrom:1 to:max with:oldString.
|
|
863 |
max := max * 2
|
|
864 |
].
|
|
865 |
index := index + 1.
|
|
866 |
string at:index put:nextChar.
|
|
867 |
nextChar := source nextPeek
|
0
|
868 |
]
|
|
869 |
!
|
|
870 |
|
|
871 |
nextIdentifier
|
97
|
872 |
|nextChar string firstChar|
|
0
|
873 |
|
87
|
874 |
hereChar == $_ ifTrue:[
|
|
875 |
"/
|
|
876 |
"/ no need to check for AllowUnderscoreInIdentifier here;
|
|
877 |
"/ could not arrive here if it was off
|
|
878 |
"/
|
|
879 |
nextChar := source nextPeek.
|
|
880 |
(nextChar isAlphaNumeric or:[nextChar == $_]) ifFalse:[
|
|
881 |
"oops: a single underscore is an old-style assignement"
|
|
882 |
self warnOldStyleAssignmentAt:tokenPosition.
|
|
883 |
source next.
|
|
884 |
tokenType := $_.
|
|
885 |
^ tokenType
|
|
886 |
].
|
|
887 |
string := '_'.
|
|
888 |
self warnUnderscoreAt:tokenPosition.
|
|
889 |
[nextChar == '_'] whileTrue:[
|
|
890 |
string := string copyWith:$_.
|
|
891 |
nextChar := source nextPeek.
|
|
892 |
].
|
|
893 |
string := string , source nextAlphaNumericWord.
|
|
894 |
] ifFalse:[
|
|
895 |
string := source nextAlphaNumericWord "self nextId".
|
|
896 |
].
|
0
|
897 |
nextChar := source peek.
|
87
|
898 |
|
60
|
899 |
AllowUnderscoreInIdentifier ifTrue:[
|
|
900 |
nextChar == $_ ifTrue:[
|
87
|
901 |
self warnUnderscoreAt:(source position).
|
60
|
902 |
].
|
|
903 |
[nextChar == $_] whileTrue:[
|
|
904 |
string := string copyWith:nextChar.
|
|
905 |
nextChar := source nextPeek.
|
|
906 |
(nextChar isAlphaNumeric) ifTrue:[
|
|
907 |
string := string , source nextAlphaNumericWord.
|
|
908 |
nextChar := source peek.
|
|
909 |
]
|
|
910 |
].
|
|
911 |
].
|
|
912 |
|
0
|
913 |
(nextChar == $:) ifTrue:[
|
45
|
914 |
source next.
|
|
915 |
(source peek == $=) ifFalse:[
|
|
916 |
tokenName := string copyWith:nextChar.
|
|
917 |
tokenType := #Keyword.
|
|
918 |
^ self
|
|
919 |
].
|
|
920 |
peekChar := $_
|
0
|
921 |
].
|
20
|
922 |
tokenName := string.
|
0
|
923 |
firstChar := string at:1.
|
|
924 |
(firstChar == $s) ifTrue:[
|
45
|
925 |
(string = 'self') ifTrue:[tokenType := #Self. ^self].
|
|
926 |
(string = 'super') ifTrue:[tokenType := #Super. ^self]
|
0
|
927 |
].
|
|
928 |
(firstChar == $n) ifTrue:[
|
45
|
929 |
(string = 'nil') ifTrue:[tokenType := #Nil. ^self]
|
0
|
930 |
].
|
|
931 |
(firstChar == $t) ifTrue:[
|
45
|
932 |
(string = 'true') ifTrue:[tokenType := #True. ^self].
|
|
933 |
(string = 'thisContext') ifTrue:[tokenType := #ThisContext. ^self]
|
0
|
934 |
].
|
|
935 |
(firstChar == $f) ifTrue:[
|
45
|
936 |
(string = 'false') ifTrue:[tokenType := #False. ^self]
|
0
|
937 |
].
|
|
938 |
tokenType := #Identifier.
|
|
939 |
^ tokenType
|
|
940 |
!
|
|
941 |
|
|
942 |
nextPrimitive
|
|
943 |
|nextChar inPrimitive string
|
|
944 |
index "{ Class: SmallInteger }"
|
|
945 |
len "{ Class: SmallInteger }" |
|
|
946 |
|
|
947 |
nextChar := source nextPeek.
|
|
948 |
string := String new:500.
|
|
949 |
len := 500.
|
|
950 |
index := 1.
|
|
951 |
(nextChar == ${) ifTrue:[
|
45
|
952 |
nextChar := source nextPeek.
|
|
953 |
inPrimitive := true.
|
|
954 |
[inPrimitive] whileTrue:[
|
|
955 |
[nextChar == $%] whileFalse:[
|
|
956 |
string at:index put:nextChar.
|
|
957 |
(index == len) ifTrue:[
|
|
958 |
string := string , (String new:len).
|
|
959 |
len := len * 2
|
|
960 |
].
|
|
961 |
index := index + 1.
|
|
962 |
nextChar := source next
|
|
963 |
].
|
|
964 |
(source peek == $}) ifTrue:[
|
|
965 |
inPrimitive := false
|
|
966 |
] ifFalse:[
|
|
967 |
string at:index put:nextChar.
|
|
968 |
(index == len) ifTrue:[
|
|
969 |
string := string , (String new:len).
|
|
970 |
len := len * 2
|
|
971 |
].
|
|
972 |
index := index + 1.
|
|
973 |
nextChar := source next
|
|
974 |
]
|
|
975 |
].
|
|
976 |
source next.
|
|
977 |
tokenValue := string copyTo:(index - 1).
|
|
978 |
tokenType := #Primitive.
|
|
979 |
tokenLineNr := tokenLineNr + (tokenValue occurrencesOf:(Character cr)).
|
|
980 |
^ tokenType
|
0
|
981 |
].
|
|
982 |
|
|
983 |
"a % alone is a binary operator"
|
|
984 |
tokenName := '%'.
|
|
985 |
tokenType := #BinaryOperator.
|
|
986 |
^ tokenType.
|
|
987 |
"
|
|
988 |
self syntaxError:('invalid character: ''' , nextChar asString , '''')
|
45
|
989 |
position:tokenPosition to:(tokenPosition + 1).
|
0
|
990 |
^ #Error
|
|
991 |
"
|
|
992 |
!
|
|
993 |
|
|
994 |
nextHash
|
|
995 |
|nextChar string|
|
|
996 |
|
|
997 |
nextChar := source nextPeek.
|
|
998 |
nextChar notNil ifTrue:[
|
45
|
999 |
nextChar isLetterOrDigit ifTrue:[
|
|
1000 |
string := ''.
|
|
1001 |
[nextChar notNil and:[nextChar isLetterOrDigit]] whileTrue:[
|
60
|
1002 |
string := string , (source nextAlphaNumericWord "self nextId").
|
45
|
1003 |
nextChar := source peek.
|
60
|
1004 |
AllowUnderscoreInIdentifier == true ifTrue:[
|
|
1005 |
nextChar == $_ ifTrue:[
|
87
|
1006 |
self warnUnderscoreAt:source position.
|
60
|
1007 |
].
|
|
1008 |
[nextChar == $_] whileTrue:[
|
|
1009 |
string := string copyWith:nextChar.
|
|
1010 |
nextChar := source nextPeek.
|
|
1011 |
(nextChar isAlphaNumeric) ifTrue:[
|
|
1012 |
string := string , source nextAlphaNumericWord.
|
|
1013 |
nextChar := source peek.
|
|
1014 |
]
|
|
1015 |
].
|
|
1016 |
].
|
45
|
1017 |
(nextChar == $:) ifFalse:[
|
|
1018 |
tokenValue := string asSymbol.
|
|
1019 |
tokenType := #Symbol.
|
|
1020 |
^ tokenType
|
|
1021 |
].
|
|
1022 |
string := string copyWith:nextChar.
|
|
1023 |
nextChar := source nextPeek
|
|
1024 |
].
|
|
1025 |
tokenValue := string asSymbol.
|
|
1026 |
tokenType := #Symbol.
|
|
1027 |
^ tokenType
|
|
1028 |
].
|
|
1029 |
(nextChar == $( ) ifTrue:[
|
|
1030 |
source next.
|
|
1031 |
tokenType := #HashLeftParen.
|
|
1032 |
^ tokenType
|
|
1033 |
].
|
|
1034 |
(nextChar == $[ ) ifTrue:[
|
|
1035 |
"it seems that ST-80 supports Constant ByteArrays as #[...]
|
|
1036 |
(seen in a PD program)"
|
|
1037 |
source next.
|
|
1038 |
tokenType := #HashLeftBrack.
|
|
1039 |
^ tokenType
|
|
1040 |
].
|
|
1041 |
(nextChar == $' ) ifTrue:[
|
|
1042 |
"it seems that ST-80 supports arbitrary symbols as #'...'
|
|
1043 |
(seen in a PD program)"
|
|
1044 |
self nextString.
|
|
1045 |
tokenValue := tokenValue asSymbol.
|
|
1046 |
tokenType := #Symbol.
|
|
1047 |
^ tokenType
|
|
1048 |
].
|
|
1049 |
((TypeArray at:(nextChar asciiValue)) == #special) ifTrue:[
|
|
1050 |
string := source next asString.
|
|
1051 |
nextChar := source peek.
|
|
1052 |
nextChar notNil ifTrue:[
|
|
1053 |
((TypeArray at:(nextChar asciiValue)) == #special) ifTrue:[
|
|
1054 |
source next.
|
|
1055 |
string := string copyWith:nextChar
|
|
1056 |
]
|
|
1057 |
].
|
|
1058 |
tokenValue := string asSymbol.
|
|
1059 |
tokenType := #Symbol.
|
|
1060 |
^ tokenType
|
|
1061 |
]
|
0
|
1062 |
].
|
3
|
1063 |
"this allows hash to be used as binop -
|
|
1064 |
I dont know, if this is correct ..."
|
|
1065 |
|
|
1066 |
tokenName := '#'.
|
45
|
1067 |
tokenType := #BinaryOperator.
|
3
|
1068 |
^ tokenType
|
|
1069 |
"
|
0
|
1070 |
self syntaxError:'unexpected end-of-input in Symbol'
|
45
|
1071 |
position:tokenPosition to:(tokenPosition + 1).
|
0
|
1072 |
^ #Error
|
3
|
1073 |
"
|
0
|
1074 |
!
|
|
1075 |
|
|
1076 |
nextString
|
|
1077 |
|nextChar string pos
|
|
1078 |
index "{ Class: SmallInteger }"
|
|
1079 |
len "{ Class: SmallInteger }"
|
|
1080 |
inString|
|
|
1081 |
|
96
|
1082 |
string := String basicNew:20.
|
0
|
1083 |
len := 20.
|
|
1084 |
index := 1.
|
|
1085 |
pos := source position.
|
|
1086 |
source next.
|
|
1087 |
nextChar := source next.
|
|
1088 |
inString := true.
|
|
1089 |
|
|
1090 |
[inString] whileTrue:[
|
45
|
1091 |
nextChar isNil ifTrue:[
|
|
1092 |
self syntaxError:'unexpected end-of-input in String'
|
|
1093 |
position:pos to:(source position - 1).
|
|
1094 |
tokenType := #EOF.
|
|
1095 |
^ tokenType
|
|
1096 |
].
|
|
1097 |
(nextChar == Character cr) ifTrue:[
|
|
1098 |
tokenLineNr := tokenLineNr + 1
|
|
1099 |
].
|
|
1100 |
(nextChar == Character quote) ifTrue:[
|
|
1101 |
(source peek == Character quote) ifTrue:[
|
|
1102 |
source next
|
|
1103 |
] ifFalse:[
|
|
1104 |
inString := false
|
|
1105 |
]
|
|
1106 |
].
|
|
1107 |
inString ifTrue:[
|
|
1108 |
string at:index put:nextChar.
|
|
1109 |
(index == len) ifTrue:[
|
|
1110 |
string := string , (String new:len).
|
|
1111 |
len := len * 2
|
|
1112 |
].
|
|
1113 |
index := index + 1.
|
|
1114 |
nextChar := source next
|
|
1115 |
]
|
0
|
1116 |
].
|
15
|
1117 |
tokenValue := string copyTo:(index - 1).
|
0
|
1118 |
tokenType := #String.
|
|
1119 |
^ tokenType
|
|
1120 |
! !
|