author | Claus Gittinger <cg@exept.de> |
Fri, 08 Nov 1996 18:55:46 +0100 | |
changeset 431 | 058e1ce760ea |
parent 426 | 871231a532fc |
child 441 | fa5637faa969 |
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 |
||
431
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
353 |
lastTokenLineNumber |
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
354 |
^ tokenLineNr |
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
355 |
|
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
356 |
"Created: 8.11.1996 / 18:46:36 / cg" |
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
357 |
! |
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
358 |
|
0 | 359 |
notifyError:aMessage position:position to:endPos |
360 |
"notify requestor of an error - if there is no requestor |
|
53 | 361 |
put it on the transcript. Requestor is typically the CodeView |
362 |
in which the accept/doIt was triggered, or the PositionableStream |
|
363 |
which does the fileIn. The requestor may decide how to highlight the |
|
364 |
error (and/or to abort the compile). |
|
0 | 365 |
Return the result passed back by the requestor." |
366 |
||
53 | 367 |
ignoreErrors ifFalse:[ |
368 |
requestor isNil ifTrue:[ |
|
369 |
self showErrorMessage:aMessage position:position. |
|
370 |
^ false |
|
371 |
]. |
|
83 | 372 |
^ requestor error:aMessage position:position to:endPos from:self |
0 | 373 |
]. |
53 | 374 |
^ false |
0 | 375 |
! |
376 |
||
377 |
notifyWarning:aMessage position:position to:endPos |
|
378 |
"notify requestor of an warning - if there is no requestor |
|
379 |
put it on the transcript. |
|
380 |
Return the result passed back by the requestor." |
|
381 |
||
53 | 382 |
ignoreWarnings ifFalse:[ |
383 |
requestor isNil ifTrue:[ |
|
45 | 384 |
self showErrorMessage:aMessage position:position. |
53 | 385 |
^ false |
45 | 386 |
]. |
83 | 387 |
^ requestor warning:aMessage position:position to:endPos from:self |
0 | 388 |
]. |
53 | 389 |
^ false |
0 | 390 |
! |
391 |
||
141 | 392 |
showErrorMessage:aMessage position:pos |
393 |
"show an errormessage on the Transcript" |
|
0 | 394 |
|
141 | 395 |
ignoreErrors ifFalse:[ |
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
396 |
Smalltalk silentLoading == true ifFalse:[ |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
397 |
Transcript showCR:(pos printString , ' [line: ' , tokenLineNr printString , '] ' , aMessage) |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
398 |
] |
141 | 399 |
] |
274 | 400 |
|
401 |
"Modified: 18.5.1996 / 15:44:35 / cg" |
|
141 | 402 |
! |
403 |
||
404 |
syntaxError:aMessage |
|
405 |
"a syntax error happened - position is not known" |
|
406 |
||
407 |
^ self syntaxError:aMessage position:tokenPosition |
|
0 | 408 |
! |
409 |
||
410 |
syntaxError:aMessage position:position |
|
411 |
"a syntax error happened - only start position is known" |
|
412 |
||
413 |
^ self syntaxError:aMessage position:position to:nil |
|
414 |
! |
|
415 |
||
141 | 416 |
syntaxError:aMessage position:position to:endPos |
417 |
"a syntax error happened" |
|
0 | 418 |
|
141 | 419 |
self notifyError:('Error:' , aMessage) position:position to:endPos. |
420 |
exitBlock notNil ifTrue:[exitBlock value]. |
|
421 |
^ false |
|
87 | 422 |
! |
423 |
||
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
424 |
warnCommonMistake:msg at:position |
311 | 425 |
self warnCommonMistake:msg position:position to:position |
426 |
||
427 |
"Modified: 18.7.1996 / 10:28:53 / cg" |
|
428 |
! |
|
429 |
||
430 |
warnCommonMistake:msg position:pos1 to:pos2 |
|
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
431 |
ignoreWarnings ifFalse:[ |
311 | 432 |
warnCommonMistakes ifTrue:[ |
433 |
self |
|
434 |
warning:msg |
|
435 |
position:pos1 to:pos2. |
|
436 |
] |
|
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
437 |
] |
311 | 438 |
|
439 |
"Created: 18.7.1996 / 10:28:38 / cg" |
|
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
440 |
! |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
441 |
|
87 | 442 |
warnOldStyleAssignmentAt:position |
443 |
ignoreWarnings ifFalse:[ |
|
444 |
warnOldStyleAssignment ifTrue:[ |
|
445 |
self |
|
446 |
warning:'old style assignment - please change to use '':=''' |
|
447 |
position:position to:position. |
|
448 |
" |
|
449 |
only warn once (per method) |
|
450 |
" |
|
451 |
warnOldStyleAssignment := false |
|
452 |
] |
|
453 |
] |
|
454 |
! |
|
455 |
||
456 |
warnUnderscoreAt:position |
|
457 |
ignoreWarnings ifFalse:[ |
|
458 |
warnUnderscoreInIdentifier ifTrue:[ |
|
459 |
self |
|
460 |
warning:'underscores in identifiers/symbols are nonportable' |
|
461 |
position:position to:position. |
|
462 |
" |
|
463 |
only warn once (per method) |
|
464 |
" |
|
465 |
warnUnderscoreInIdentifier := false |
|
466 |
] |
|
467 |
] |
|
141 | 468 |
! |
469 |
||
470 |
warning:aMessage |
|
471 |
"a warning - position is not known" |
|
472 |
||
473 |
^ self warning:aMessage position:tokenPosition |
|
474 |
! |
|
475 |
||
476 |
warning:aMessage position:position |
|
477 |
"a warning - only start position is known" |
|
478 |
||
479 |
^ self warning:aMessage position:position to:nil |
|
480 |
! |
|
481 |
||
482 |
warning:aMessage position:position to:endPos |
|
483 |
"a warning" |
|
484 |
||
485 |
^ self notifyWarning:('Warning: ' , aMessage) position:position to:endPos |
|
0 | 486 |
! ! |
487 |
||
17 | 488 |
!Scanner methodsFor:'general scanning'! |
489 |
||
490 |
scanPositionsFor:aTokenString inString:aSourceString |
|
491 |
"scan aSourceString for occurrances of aTokenString. |
|
492 |
Return a collection of start positions. |
|
493 |
Added for VW compatibility (to support syntax-highlight)." |
|
494 |
||
495 |
|searchType searchName searchValue positions t| |
|
496 |
||
497 |
" |
|
498 |
first, look what kind of token we have to search for |
|
499 |
" |
|
500 |
self initializeFor:(ReadStream on:aTokenString). |
|
501 |
self nextToken. |
|
502 |
searchType := tokenType. |
|
503 |
searchName := tokenName. |
|
504 |
searchValue := tokenValue. |
|
505 |
||
506 |
" |
|
507 |
start the real work ... |
|
508 |
" |
|
509 |
self initializeFor:(ReadStream on:aSourceString). |
|
510 |
positions := OrderedCollection new. |
|
511 |
||
512 |
[(t := self nextToken) ~~ #EOF] whileTrue:[ |
|
45 | 513 |
searchType == t ifTrue:[ |
514 |
(searchName isNil or:[tokenName = searchName]) ifTrue:[ |
|
515 |
(searchValue isNil or:[tokenValue = searchValue]) ifTrue:[ |
|
516 |
positions add:tokenPosition. |
|
517 |
] |
|
518 |
] |
|
519 |
] |
|
17 | 520 |
]. |
521 |
||
522 |
^ positions |
|
523 |
||
524 |
" |
|
30 | 525 |
Scanner new scanPositionsFor:'hello' inString:'foo bar hello baz hello' |
526 |
Scanner new scanPositionsFor:'3.14' inString:'foo 3.145 bar hello 3.14 baz hello 3.14' |
|
527 |
Scanner new scanPositionsFor:'16' inString:'foo 16 bar hello 16r10 baz hello 2r10000' |
|
17 | 528 |
" |
529 |
! ! |
|
530 |
||
141 | 531 |
!Scanner methodsFor:'private'! |
3 | 532 |
|
141 | 533 |
backupPosition |
534 |
"if reading from a stream, at the end we might have read |
|
535 |
one token too many" |
|
20 | 536 |
|
141 | 537 |
(tokenType == #EOF) ifFalse:[ |
538 |
source position:tokenPosition |
|
539 |
] |
|
540 |
! |
|
15 | 541 |
|
141 | 542 |
beginComment |
543 |
^ self |
|
544 |
! |
|
545 |
||
546 |
collectedSource |
|
547 |
^ collectedSource |
|
548 |
! |
|
74 | 549 |
|
141 | 550 |
endComment:comment |
551 |
saveComments ifTrue:[ |
|
552 |
currentComments isNil ifTrue:[ |
|
553 |
currentComments := OrderedCollection with:comment |
|
45 | 554 |
] ifFalse:[ |
141 | 555 |
currentComments add:comment |
45 | 556 |
] |
3 | 557 |
]. |
558 |
! |
|
559 |
||
141 | 560 |
ignoreErrors |
561 |
"turn off notification of errors" |
|
562 |
||
563 |
ignoreErrors := true |
|
564 |
! |
|
0 | 565 |
|
141 | 566 |
ignoreWarnings |
567 |
"turn off notification of warnings" |
|
568 |
||
569 |
ignoreWarnings := true |
|
570 |
! |
|
0 | 571 |
|
141 | 572 |
initialize |
573 |
"prepare a scan" |
|
3 | 574 |
|
141 | 575 |
errorFlag := false. |
266
6c6c1d5a3d9d
initialize tokenPosition (error/warning at first token had it nil)
Claus Gittinger <cg@exept.de>
parents:
265
diff
changeset
|
576 |
tokenPosition := 1. |
141 | 577 |
tokenLineNr := 1. |
578 |
currentComments := nil. |
|
579 |
saveComments := false. |
|
580 |
ignoreErrors := false. |
|
581 |
ignoreWarnings := Warnings not. |
|
582 |
warnSTXSpecialComment := WarnSTXSpecials. |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
583 |
warnSTXNameSpaceUse := WarnSTXSpecials. |
141 | 584 |
warnUnderscoreInIdentifier := WarnUnderscoreInIdentifier. |
585 |
warnOldStyleAssignment := WarnOldStyleAssignment. |
|
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
586 |
warnCommonMistakes := WarnCommonMistakes. |
141 | 587 |
ActionArray isNil ifTrue:[ |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
588 |
self class setupActions |
141 | 589 |
] |
266
6c6c1d5a3d9d
initialize tokenPosition (error/warning at first token had it nil)
Claus Gittinger <cg@exept.de>
parents:
265
diff
changeset
|
590 |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
591 |
"Modified: 14.10.1996 / 19:08:22 / cg" |
0 | 592 |
! |
593 |
||
141 | 594 |
initializeFor:aStringOrStream |
595 |
"initialize - |
|
596 |
if this is the first time, setup character- and action tables" |
|
597 |
||
598 |
self initialize. |
|
599 |
||
600 |
aStringOrStream isStream ifFalse:[ |
|
601 |
source := ReadStream on:aStringOrStream |
|
602 |
] ifTrue:[ |
|
603 |
source := aStringOrStream. |
|
604 |
]. |
|
605 |
! |
|
606 |
||
607 |
notifying:anObject |
|
608 |
"set the requestor to be notified" |
|
609 |
||
610 |
requestor := anObject |
|
426
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
611 |
! |
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
612 |
|
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
613 |
setNameSpace:aNameSpace |
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
614 |
"/ ignored here |
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
615 |
|
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
616 |
"Created: 8.11.1996 / 13:33:10 / cg" |
141 | 617 |
! ! |
618 |
||
619 |
!Scanner methodsFor:'reading next token'! |
|
620 |
||
621 |
nextCharacter |
|
622 |
"a $ has been read - return a character token" |
|
623 |
||
624 |
|nextChar| |
|
625 |
||
0 | 626 |
source next. |
141 | 627 |
nextChar := source next. |
628 |
nextChar notNil ifTrue:[ |
|
629 |
tokenValue := nextChar. |
|
630 |
tokenType := #Character |
|
631 |
] ifFalse:[ |
|
632 |
tokenType := #EOF |
|
633 |
]. |
|
0 | 634 |
^ tokenType |
635 |
! |
|
636 |
||
637 |
nextColonOrAssign |
|
638 |
"colon has been read - look for = to make it an assign" |
|
639 |
||
120 | 640 |
"/ special kludge for identifier:= (without spaces inbetween) |
641 |
"/ here we needed two characters lookahead after the identifier ... |
|
642 |
||
643 |
peekChar == $= ifTrue:[ |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
644 |
source next. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
645 |
peekChar := nil. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
646 |
tokenType := #':='. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
647 |
^ tokenType |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
648 |
]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
649 |
|
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
650 |
"/ special kludge for nameSpace:: (without spaces inbetween) |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
651 |
"/ here we needed two characters lookahead after the identifier ... |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
652 |
|
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
653 |
peekChar == $: ifTrue:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
654 |
source next. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
655 |
peekChar := nil. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
656 |
tokenType := #'::'. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
657 |
^ tokenType |
120 | 658 |
]. |
659 |
||
0 | 660 |
(source nextPeek == $=) ifTrue:[ |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
661 |
source next. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
662 |
tokenType := $_ |
0 | 663 |
] ifFalse:[ |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
664 |
tokenType := $: |
0 | 665 |
]. |
666 |
^ tokenType |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
667 |
|
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
668 |
"Modified: 14.10.1996 / 18:49:29 / cg" |
0 | 669 |
! |
670 |
||
141 | 671 |
nextHash |
672 |
|nextChar string| |
|
0 | 673 |
|
141 | 674 |
nextChar := source nextPeek. |
675 |
nextChar notNil ifTrue:[ |
|
676 |
nextChar isLetterOrDigit ifTrue:[ |
|
677 |
string := ''. |
|
678 |
[nextChar notNil and:[nextChar isLetterOrDigit]] whileTrue:[ |
|
679 |
string := string , (source nextAlphaNumericWord "self nextId"). |
|
680 |
nextChar := source peek. |
|
681 |
AllowUnderscoreInIdentifier == true ifTrue:[ |
|
682 |
nextChar == $_ ifTrue:[ |
|
683 |
self warnUnderscoreAt:source position. |
|
684 |
]. |
|
685 |
[nextChar == $_] whileTrue:[ |
|
686 |
string := string copyWith:nextChar. |
|
687 |
nextChar := source nextPeek. |
|
688 |
(nextChar isAlphaNumeric) ifTrue:[ |
|
689 |
string := string , source nextAlphaNumericWord. |
|
690 |
nextChar := source peek. |
|
691 |
] |
|
692 |
]. |
|
693 |
]. |
|
694 |
(nextChar == $:) ifFalse:[ |
|
695 |
tokenValue := string asSymbol. |
|
696 |
tokenType := #Symbol. |
|
697 |
^ tokenType |
|
698 |
]. |
|
699 |
string := string copyWith:nextChar. |
|
700 |
nextChar := source nextPeek |
|
701 |
]. |
|
702 |
tokenValue := string asSymbol. |
|
703 |
tokenType := #Symbol. |
|
704 |
^ tokenType |
|
705 |
]. |
|
706 |
(nextChar == $( ) ifTrue:[ |
|
707 |
source next. |
|
708 |
tokenType := #HashLeftParen. |
|
709 |
^ tokenType |
|
710 |
]. |
|
711 |
(nextChar == $[ ) ifTrue:[ |
|
712 |
"it seems that ST-80 supports Constant ByteArrays as #[...] |
|
713 |
(seen in a PD program)" |
|
714 |
source next. |
|
715 |
tokenType := #HashLeftBrack. |
|
716 |
^ tokenType |
|
717 |
]. |
|
718 |
(nextChar == $' ) ifTrue:[ |
|
719 |
"it seems that ST-80 supports arbitrary symbols as #'...' |
|
720 |
(seen in a PD program)" |
|
721 |
self nextString. |
|
722 |
tokenValue := tokenValue asSymbol. |
|
723 |
tokenType := #Symbol. |
|
724 |
^ tokenType |
|
725 |
]. |
|
726 |
((TypeArray at:(nextChar asciiValue)) == #special) ifTrue:[ |
|
727 |
string := source next asString. |
|
728 |
nextChar := source peek. |
|
729 |
nextChar notNil ifTrue:[ |
|
730 |
((TypeArray at:(nextChar asciiValue)) == #special) ifTrue:[ |
|
731 |
source next. |
|
732 |
string := string copyWith:nextChar |
|
733 |
] |
|
734 |
]. |
|
735 |
tokenValue := string asSymbol. |
|
736 |
tokenType := #Symbol. |
|
45 | 737 |
^ tokenType |
738 |
] |
|
0 | 739 |
]. |
141 | 740 |
"this allows hash to be used as binop - |
741 |
I dont know, if this is correct ..." |
|
742 |
||
743 |
tokenName := '#'. |
|
0 | 744 |
tokenType := #BinaryOperator. |
745 |
^ tokenType |
|
141 | 746 |
" |
747 |
self syntaxError:'unexpected end-of-input in Symbol' |
|
748 |
position:tokenPosition to:(tokenPosition + 1). |
|
749 |
^ #Error |
|
750 |
" |
|
0 | 751 |
! |
752 |
||
753 |
nextId |
|
754 |
|nextChar string oldString |
|
755 |
index "{ Class: SmallInteger }" |
|
756 |
max "{ Class: SmallInteger }" | |
|
757 |
||
758 |
nextChar := source peek. |
|
96 | 759 |
string := String basicNew:20. |
0 | 760 |
index := 0. |
761 |
max := 10. |
|
762 |
[true] whileTrue:[ |
|
45 | 763 |
(nextChar notNil and:[nextChar isLetterOrDigit]) ifFalse:[ |
764 |
^ string copyTo:index |
|
765 |
]. |
|
766 |
(index == max) ifTrue:[ |
|
767 |
oldString := string. |
|
96 | 768 |
string := String basicNew:(max * 2). |
45 | 769 |
string replaceFrom:1 to:max with:oldString. |
770 |
max := max * 2 |
|
771 |
]. |
|
772 |
index := index + 1. |
|
773 |
string at:index put:nextChar. |
|
774 |
nextChar := source nextPeek |
|
0 | 775 |
] |
776 |
! |
|
777 |
||
778 |
nextIdentifier |
|
97 | 779 |
|nextChar string firstChar| |
0 | 780 |
|
87 | 781 |
hereChar == $_ ifTrue:[ |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
782 |
"/ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
783 |
"/ no need to check for AllowUnderscoreInIdentifier here; |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
784 |
"/ could not arrive here if it was off |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
785 |
"/ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
786 |
nextChar := source nextPeek. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
787 |
(nextChar isAlphaNumeric or:[nextChar == $_]) ifFalse:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
788 |
"oops: a single underscore is an old-style assignement" |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
789 |
self warnOldStyleAssignmentAt:tokenPosition. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
790 |
source next. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
791 |
tokenType := $_. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
792 |
^ tokenType |
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 := '_'. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
795 |
self warnUnderscoreAt:tokenPosition. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
796 |
[nextChar == $_] whileTrue:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
797 |
string := string copyWith:$_. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
798 |
nextChar := source nextPeek. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
799 |
]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
800 |
string := string , source nextAlphaNumericWord. |
87 | 801 |
] ifFalse:[ |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
802 |
string := source nextAlphaNumericWord "self nextId". |
87 | 803 |
]. |
0 | 804 |
nextChar := source peek. |
87 | 805 |
|
60 | 806 |
AllowUnderscoreInIdentifier ifTrue:[ |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
807 |
nextChar == $_ ifTrue:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
808 |
self warnUnderscoreAt:(source position). |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
809 |
]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
810 |
[nextChar == $_] whileTrue:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
811 |
string := string copyWith:nextChar. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
812 |
nextChar := source nextPeek. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
813 |
(nextChar isAlphaNumeric) ifTrue:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
814 |
string := string , source nextAlphaNumericWord. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
815 |
nextChar := source peek. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
816 |
] |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
817 |
]. |
60 | 818 |
]. |
819 |
||
0 | 820 |
(nextChar == $:) ifTrue:[ |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
821 |
source next. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
822 |
(source peek == $=) ifFalse:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
823 |
(source peek == $:) ifFalse:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
824 |
tokenName := string copyWith:nextChar. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
825 |
tokenType := #Keyword. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
826 |
^ self |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
827 |
]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
828 |
peekChar := $:. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
829 |
peekChar2 := $:. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
830 |
] ifTrue:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
831 |
peekChar := $:. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
832 |
peekChar2 := $=. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
833 |
] |
0 | 834 |
]. |
20 | 835 |
tokenName := string. |
0 | 836 |
firstChar := string at:1. |
837 |
(firstChar == $s) ifTrue:[ |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
838 |
(string = 'self') ifTrue:[tokenType := #Self. ^self]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
839 |
(string = 'super') ifTrue:[tokenType := #Super. ^self] |
0 | 840 |
]. |
841 |
(firstChar == $n) ifTrue:[ |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
842 |
(string = 'nil') ifTrue:[tokenType := #Nil. ^self] |
0 | 843 |
]. |
844 |
(firstChar == $t) ifTrue:[ |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
845 |
(string = 'true') ifTrue:[tokenType := #True. ^self]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
846 |
(string = 'thisContext') ifTrue:[tokenType := #ThisContext. ^self] |
0 | 847 |
]. |
848 |
(firstChar == $f) ifTrue:[ |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
849 |
(string = 'false') ifTrue:[tokenType := #False. ^self] |
0 | 850 |
]. |
851 |
tokenType := #Identifier. |
|
852 |
^ tokenType |
|
120 | 853 |
|
854 |
"Created: 13.9.1995 / 12:56:42 / claus" |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
855 |
"Modified: 14.10.1996 / 18:50:45 / cg" |
0 | 856 |
! |
857 |
||
141 | 858 |
nextMantissa:radix |
859 |
|nextChar value factor| |
|
860 |
||
861 |
value := 0. |
|
862 |
factor := 1.0 / radix. |
|
863 |
nextChar := source peek. |
|
864 |
[(nextChar notNil and:[nextChar isDigitRadix:radix])] whileTrue:[ |
|
865 |
value := value + (nextChar digitValue * factor). |
|
866 |
factor := factor / radix. |
|
867 |
nextChar := source nextPeek |
|
868 |
]. |
|
869 |
^ value |
|
870 |
! |
|
871 |
||
872 |
nextNumber |
|
873 |
|nextChar value s| |
|
874 |
||
875 |
tokenRadix := 10. |
|
876 |
value := Integer readFrom:source radix:tokenRadix. |
|
877 |
nextChar := source peek. |
|
878 |
(nextChar == $r) ifTrue:[ |
|
313
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
879 |
tokenRadix := value. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
880 |
source next. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
881 |
s := 1. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
882 |
source peek == $- ifTrue:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
883 |
source next. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
884 |
s := -1 |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
885 |
]. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
886 |
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
|
887 |
value := value * s. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
888 |
nextChar := source peek |
141 | 889 |
]. |
890 |
(nextChar == $.) ifTrue:[ |
|
313
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
891 |
nextChar := source nextPeek. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
892 |
(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
|
893 |
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
|
894 |
nextChar := source peek |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
895 |
] ifFalse:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
896 |
nextChar == (Character cr) ifTrue:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
897 |
tokenLineNr := tokenLineNr + 1. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
898 |
]. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
899 |
peekChar := $. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
900 |
] |
141 | 901 |
]. |
902 |
((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
|
903 |
nextChar := source nextPeek. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
904 |
(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
|
905 |
s := 1. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
906 |
(nextChar == $+) ifTrue:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
907 |
nextChar := source nextPeek |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
908 |
] ifFalse:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
909 |
(nextChar == $-) ifTrue:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
910 |
nextChar := source nextPeek. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
911 |
s := s negated |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
912 |
] |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
913 |
]. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
914 |
value := value asFloat |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
915 |
* (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
|
916 |
] |
141 | 917 |
]. |
918 |
tokenValue := value. |
|
919 |
(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
|
920 |
(nextChar == $d) ifTrue:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
921 |
source next |
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 |
tokenType := #Float |
141 | 924 |
] ifFalse:[ |
313
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
925 |
tokenType := #Integer |
141 | 926 |
]. |
927 |
^ tokenType |
|
313
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
928 |
|
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
929 |
"Modified: 19.7.1996 / 12:23:38 / cg" |
141 | 930 |
! |
931 |
||
0 | 932 |
nextPrimitive |
933 |
|nextChar inPrimitive string |
|
934 |
index "{ Class: SmallInteger }" |
|
935 |
len "{ Class: SmallInteger }" | |
|
936 |
||
937 |
nextChar := source nextPeek. |
|
938 |
string := String new:500. |
|
939 |
len := 500. |
|
940 |
index := 1. |
|
941 |
(nextChar == ${) ifTrue:[ |
|
45 | 942 |
nextChar := source nextPeek. |
943 |
inPrimitive := true. |
|
944 |
[inPrimitive] whileTrue:[ |
|
945 |
[nextChar == $%] whileFalse:[ |
|
946 |
string at:index put:nextChar. |
|
947 |
(index == len) ifTrue:[ |
|
948 |
string := string , (String new:len). |
|
949 |
len := len * 2 |
|
950 |
]. |
|
951 |
index := index + 1. |
|
952 |
nextChar := source next |
|
953 |
]. |
|
954 |
(source peek == $}) ifTrue:[ |
|
955 |
inPrimitive := false |
|
956 |
] ifFalse:[ |
|
957 |
string at:index put:nextChar. |
|
958 |
(index == len) ifTrue:[ |
|
959 |
string := string , (String new:len). |
|
960 |
len := len * 2 |
|
961 |
]. |
|
962 |
index := index + 1. |
|
963 |
nextChar := source next |
|
964 |
] |
|
965 |
]. |
|
966 |
source next. |
|
967 |
tokenValue := string copyTo:(index - 1). |
|
968 |
tokenType := #Primitive. |
|
969 |
tokenLineNr := tokenLineNr + (tokenValue occurrencesOf:(Character cr)). |
|
970 |
^ tokenType |
|
0 | 971 |
]. |
972 |
||
973 |
"a % alone is a binary operator" |
|
974 |
tokenName := '%'. |
|
975 |
tokenType := #BinaryOperator. |
|
976 |
^ tokenType. |
|
977 |
" |
|
978 |
self syntaxError:('invalid character: ''' , nextChar asString , '''') |
|
45 | 979 |
position:tokenPosition to:(tokenPosition + 1). |
0 | 980 |
^ #Error |
981 |
" |
|
982 |
! |
|
983 |
||
141 | 984 |
nextSpecial |
985 |
"a special character has been read, look for another one. |
|
986 |
also -number is handled here" |
|
987 |
||
988 |
|firstChar secondChar thirdChar string p| |
|
0 | 989 |
|
141 | 990 |
firstChar := source next. |
991 |
secondChar := source peek. |
|
241
418eb41350d3
no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
992 |
((firstChar == $-) and:[secondChar notNil]) ifTrue:[ |
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
993 |
secondChar isDigit ifTrue:[ |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
994 |
self nextNumber. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
995 |
tokenValue := tokenValue negated. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
996 |
^ tokenType |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
997 |
] |
0 | 998 |
]. |
141 | 999 |
string := firstChar asString. |
1000 |
secondChar notNil ifTrue:[ |
|
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1001 |
((TypeArray at:(secondChar asciiValue)) == #special) ifTrue:[ |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1002 |
(secondChar == $-) ifTrue:[ |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1003 |
"special- look if minus belongs to number following" |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1004 |
p := source position. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1005 |
source next. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1006 |
thirdChar := source peek. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1007 |
source position:p. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1008 |
thirdChar isDigit ifTrue:[ |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1009 |
tokenName := string. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1010 |
tokenType := #BinaryOperator. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1011 |
^ tokenType |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1012 |
] |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1013 |
]. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1014 |
source next. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1015 |
string := string copyWith:secondChar |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1016 |
]. |
141 | 1017 |
]. |
1018 |
tokenName := string. |
|
45 | 1019 |
tokenType := #BinaryOperator. |
3 | 1020 |
^ tokenType |
241
418eb41350d3
no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
1021 |
|
418eb41350d3
no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
1022 |
"Modified: 12.4.1996 / 15:05:19 / cg" |
0 | 1023 |
! |
1024 |
||
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1025 |
nextString |
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1026 |
|nextChar string pos |
0 | 1027 |
index "{ Class: SmallInteger }" |
1028 |
len "{ Class: SmallInteger }" |
|
1029 |
inString| |
|
1030 |
||
96 | 1031 |
string := String basicNew:20. |
0 | 1032 |
len := 20. |
1033 |
index := 1. |
|
1034 |
pos := source position. |
|
1035 |
source next. |
|
1036 |
nextChar := source next. |
|
1037 |
inString := true. |
|
1038 |
||
1039 |
[inString] whileTrue:[ |
|
45 | 1040 |
nextChar isNil ifTrue:[ |
1041 |
self syntaxError:'unexpected end-of-input in String' |
|
1042 |
position:pos to:(source position - 1). |
|
1043 |
tokenType := #EOF. |
|
1044 |
^ tokenType |
|
1045 |
]. |
|
1046 |
(nextChar == Character cr) ifTrue:[ |
|
1047 |
tokenLineNr := tokenLineNr + 1 |
|
1048 |
]. |
|
1049 |
(nextChar == Character quote) ifTrue:[ |
|
1050 |
(source peek == Character quote) ifTrue:[ |
|
1051 |
source next |
|
1052 |
] ifFalse:[ |
|
1053 |
inString := false |
|
1054 |
] |
|
1055 |
]. |
|
1056 |
inString ifTrue:[ |
|
1057 |
string at:index put:nextChar. |
|
1058 |
(index == len) ifTrue:[ |
|
1059 |
string := string , (String new:len). |
|
1060 |
len := len * 2 |
|
1061 |
]. |
|
1062 |
index := index + 1. |
|
1063 |
nextChar := source next |
|
1064 |
] |
|
0 | 1065 |
]. |
15 | 1066 |
tokenValue := string copyTo:(index - 1). |
0 | 1067 |
tokenType := #String. |
1068 |
^ tokenType |
|
141 | 1069 |
! |
1070 |
||
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1071 |
nextToken |
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1072 |
"return the next token from the source-stream" |
141 | 1073 |
|
1074 |
|skipping actionBlock| |
|
1075 |
||
1076 |
peekChar notNil ifTrue:[ |
|
1077 |
hereChar := peekChar. |
|
1078 |
peekChar := peekChar2. |
|
1079 |
peekChar2 := nil |
|
1080 |
] ifFalse:[ |
|
1081 |
skipping := true. |
|
1082 |
[skipping] whileTrue:[ |
|
1083 |
outStream notNil ifTrue:[ |
|
1084 |
[(hereChar := source peek) == Character space] whileTrue:[ |
|
1085 |
source next. |
|
1086 |
outStream space. |
|
1087 |
outCol := outCol + 1. |
|
1088 |
] |
|
1089 |
] ifFalse:[ |
|
1090 |
hereChar := source skipSeparatorsExceptCR. |
|
1091 |
]. |
|
1092 |
hereChar == (Character cr) ifTrue:[ |
|
1093 |
tokenLineNr := tokenLineNr + 1. |
|
1094 |
source next. |
|
1095 |
outStream notNil ifTrue:[ |
|
1096 |
outStream cr. |
|
1097 |
outCol := 1 |
|
1098 |
] |
|
1099 |
] ifFalse:[ |
|
1100 |
hereChar == (Character doubleQuote) ifTrue:[ |
|
1101 |
"start of a comment" |
|
1102 |
||
1103 |
self skipComment. |
|
1104 |
hereChar := source peek. |
|
1105 |
] ifFalse:[ |
|
1106 |
skipping := false |
|
1107 |
] |
|
1108 |
] |
|
1109 |
]. |
|
1110 |
hereChar isNil ifTrue:[ |
|
1111 |
tokenType := #EOF. |
|
1112 |
^ tokenType |
|
1113 |
] |
|
1114 |
]. |
|
1115 |
tokenPosition := source position. |
|
1116 |
||
1117 |
actionBlock := ActionArray at:(hereChar asciiValue). |
|
1118 |
actionBlock notNil ifTrue:[ |
|
1119 |
^ actionBlock value:self value:hereChar |
|
1120 |
]. |
|
1121 |
||
1122 |
self syntaxError:('invalid character: ''' , hereChar asString , ''' ', |
|
1123 |
'(' , hereChar asciiValue printString , ')') |
|
1124 |
position:tokenPosition to:tokenPosition. |
|
1125 |
tokenType := #Error. |
|
1126 |
^ #Error |
|
1127 |
||
1128 |
"Modified: 13.9.1995 / 12:56:14 / claus" |
|
1129 |
! |
|
1130 |
||
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1131 |
nextToken:aCharacter |
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1132 |
tokenType := aCharacter. |
141 | 1133 |
source next. |
1134 |
^ tokenType |
|
1135 |
! |
|
1136 |
||
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1137 |
skipComment |
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1138 |
|commentStream startPos| |
141 | 1139 |
|
1140 |
saveComments ifTrue:[ |
|
1141 |
commentStream := WriteStream on:''. |
|
1142 |
self beginComment. |
|
1143 |
]. |
|
1144 |
||
1145 |
outStream notNil ifTrue:[ |
|
1146 |
outStream nextPut:Character doubleQuote. |
|
1147 |
outCol := outCol + 1 |
|
1148 |
]. |
|
1149 |
||
1150 |
startPos := source position. |
|
1151 |
source next. |
|
1152 |
hereChar := source peek. |
|
1153 |
||
1154 |
" |
|
1155 |
special ST/X addition: |
|
1156 |
a $/ right after the initial double quote makes it an up-to-end-of-line comment, |
|
1157 |
which is very useful to comment out parts of filed-in source code. |
|
1158 |
Since this is non-standard, use it in very rare cases only. |
|
1159 |
(maybe the upcoming ansi-standard adds something similar - in this case, I will |
|
1160 |
change it without notice)" |
|
1161 |
||
1162 |
hereChar == $/ ifTrue:[ |
|
1163 |
[hereChar notNil and:[hereChar ~~ Character cr]] whileTrue:[ |
|
1164 |
saveComments ifTrue:[ |
|
1165 |
commentStream nextPut:hereChar |
|
1166 |
]. |
|
1167 |
outStream notNil ifTrue:[ |
|
1168 |
outStream nextPut:hereChar. |
|
1169 |
outCol := outCol + 1 |
|
1170 |
]. |
|
1171 |
hereChar := source nextPeek. |
|
1172 |
]. |
|
1173 |
tokenLineNr := tokenLineNr + 1. |
|
1174 |
ignoreWarnings ifFalse:[ |
|
1175 |
warnSTXSpecialComment ifTrue:[ |
|
1176 |
self warning:'end-of-line comments are a nonstandard feature of ST/X' |
|
1177 |
position:startPos to:(source position). |
|
1178 |
" |
|
1179 |
only warn once |
|
1180 |
" |
|
1181 |
warnSTXSpecialComment := false |
|
1182 |
] |
|
1183 |
]. |
|
1184 |
outStream notNil ifTrue:[ |
|
1185 |
outStream cr. |
|
1186 |
outCol := 1 |
|
1187 |
]. |
|
1188 |
] ifFalse:[ |
|
1189 |
hereChar == ${ ifTrue:[ |
|
1190 |
" |
|
1191 |
special ST/X addition: |
|
1192 |
a ${ right after the initial double quote starts a directive |
|
1193 |
" |
|
1194 |
self parseDirective |
|
1195 |
]. |
|
1196 |
||
1197 |
[hereChar notNil and:[hereChar ~~ (Character doubleQuote)]] whileTrue:[ |
|
1198 |
hereChar == (Character cr) ifTrue:[ |
|
1199 |
tokenLineNr := tokenLineNr + 1. |
|
1200 |
]. |
|
1201 |
saveComments ifTrue:[ |
|
1202 |
commentStream nextPut:hereChar |
|
1203 |
]. |
|
1204 |
outStream notNil ifTrue:[ |
|
1205 |
outStream nextPut:hereChar. |
|
1206 |
outCol := outCol + 1 |
|
1207 |
]. |
|
1208 |
hereChar := source nextPeek |
|
1209 |
]. |
|
1210 |
hereChar isNil ifTrue:[ |
|
1211 |
self warning:'unclosed comment' position:startPos to:(source position) |
|
1212 |
] ifFalse:[ |
|
1213 |
outStream notNil ifTrue:[ |
|
1214 |
outStream nextPut:(Character doubleQuote). |
|
1215 |
outCol := outCol + 1 |
|
1216 |
]. |
|
1217 |
] |
|
1218 |
]. |
|
1219 |
||
1220 |
"skip final dQuote or cr" |
|
1221 |
source next. |
|
1222 |
||
1223 |
saveComments ifTrue:[ |
|
1224 |
self endComment:commentStream contents. |
|
1225 |
]. |
|
0 | 1226 |
! ! |
141 | 1227 |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1228 |
!Scanner class methodsFor:'documentation'! |
148 | 1229 |
|
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1230 |
version |
431
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
1231 |
^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.54 1996-11-08 17:55:46 cg Exp $' |
148 | 1232 |
! ! |
141 | 1233 |
Scanner initialize! |