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