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