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