author | Claus Gittinger <cg@exept.de> |
Wed, 15 Oct 1997 13:15:08 +0200 | |
changeset 620 | 15bd9a44f63f |
parent 610 | 0aa21dd74161 |
child 630 | f2f75975b22e |
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 |
||
620 | 13 |
'From Smalltalk/X, Version:3.2.1 on 14-oct-1997 at 11:15:56 pm' ! |
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
14 |
|
0 | 15 |
Object subclass:#Scanner |
311 | 16 |
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
|
17 |
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
|
18 |
requestor exitBlock errorFlag ignoreErrors ignoreWarnings |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
19 |
saveComments currentComments warnSTXSpecialComment |
311 | 20 |
warnUnderscoreInIdentifier warnOldStyleAssignment |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
21 |
warnCommonMistakes outStream outCol warnSTXNameSpaceUse |
608 | 22 |
warnPossibleIncompatibilities warnDollarInIdentifier' |
241
418eb41350d3
no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
23 |
classVariableNames:'TypeArray ActionArray AllowUnderscoreInIdentifier Warnings |
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
24 |
WarnSTXSpecials WarnOldStyleAssignment WarnUnderscoreInIdentifier |
608 | 25 |
WarnCommonMistakes WarnPossibleIncompatibilities |
26 |
WarnDollarInIdentifier AllowDollarInIdentifier' |
|
241
418eb41350d3
no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
27 |
poolDictionaries:'' |
418eb41350d3
no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
28 |
category:'System-Compiler' |
0 | 29 |
! |
30 |
||
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
31 |
!Scanner class methodsFor:'documentation'! |
20 | 32 |
|
33 |
copyright |
|
34 |
" |
|
35 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
45 | 36 |
All Rights Reserved |
20 | 37 |
|
38 |
This software is furnished under a license and may be used |
|
39 |
only in accordance with the terms of that license and with the |
|
40 |
inclusion of the above copyright notice. This software may not |
|
41 |
be provided or otherwise made available to, or used by, any |
|
42 |
other person. No title to or ownership of the software is |
|
43 |
hereby transferred. |
|
44 |
" |
|
45 |
! |
|
46 |
||
47 |
documentation |
|
48 |
" |
|
49 |
Scanner reads from a stream and returns individual smalltalk tokens |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
50 |
Its main method is #nextToken, which reads and returns the next token |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
51 |
Possibly placing additional information (such as tokenValue) into |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
52 |
instance variables as a side effect. |
75 | 53 |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
54 |
TODO: |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
55 |
some testers noticed, that ST-80's scanner methods are called |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
56 |
xLetter, xDigit etc. For code using these (internals), the nextNumber, |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
57 |
nextIdentifier etc. methods should be renamed. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
58 |
(to me, these seem to be internal private methods; |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
59 |
their public use is not a good idea ..) |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
60 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
61 |
Scanner is typically subclassed for parsing and #nextToken |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
62 |
invoked via #self-sends. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
63 |
This should be changed and scanner ought to be an instance variable |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
64 |
of Parser - this allows more flexible use of the scanner/parser |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
65 |
framework (i.e. changing the scanner without affecting the parser). |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
66 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
67 |
[author:] |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
68 |
Claus Gittinger |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
69 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
70 |
[see also:] |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
71 |
Parser |
20 | 72 |
" |
41 | 73 |
! ! |
74 |
||
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
75 |
!Scanner class methodsFor:'initialization'! |
33 | 76 |
|
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
77 |
binarySelectorCharacters |
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
78 |
"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
|
79 |
binary selectors" |
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
80 |
|
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
81 |
^ #( $& $- $+ $= $* $/ $\ $< $> $~ $@ $, $? $!! $|) |
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
82 |
|
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
83 |
"Created: 4.1.1997 / 14:13:24 / cg" |
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
84 |
! |
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
85 |
|
60 | 86 |
initialize |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
87 |
"initialize the classes defaults. Typically, these are changed |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
88 |
later in the 'private.rc' file." |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
89 |
|
60 | 90 |
Warnings := true. |
91 |
WarnSTXSpecials := true. |
|
92 |
WarnUnderscoreInIdentifier := true. |
|
608 | 93 |
WarnDollarInIdentifier := true. |
87 | 94 |
WarnOldStyleAssignment := true. |
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
95 |
WarnCommonMistakes := true. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
96 |
WarnPossibleIncompatibilities := false. |
60 | 97 |
AllowUnderscoreInIdentifier := false. |
608 | 98 |
AllowDollarInIdentifier := false. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
99 |
|
608 | 100 |
" |
101 |
self initialize |
|
102 |
" |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
103 |
|
608 | 104 |
"Modified: 7.9.1997 / 01:37:57 / cg" |
60 | 105 |
! |
106 |
||
33 | 107 |
setupActions |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
108 |
"initialize the scanners actionTables - these are used to dispatch |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
109 |
into scanner methods as characters are read" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
110 |
|
33 | 111 |
|block| |
112 |
||
113 |
ActionArray := Array new:256. |
|
114 |
TypeArray := Array new:256. |
|
115 |
||
116 |
block := [:s :char | s nextNumber]. |
|
117 |
($0 asciiValue) to:($9 asciiValue) do:[:index | |
|
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
118 |
ActionArray at:index put:block |
33 | 119 |
]. |
120 |
||
87 | 121 |
block := [:s :char | s nextSpecial]. |
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
122 |
self binarySelectorCharacters do:[:binop | |
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
123 |
TypeArray at:(binop asciiValue) put:#special. |
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
124 |
ActionArray at:(binop asciiValue) put:block |
87 | 125 |
]. |
126 |
||
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
127 |
"/ 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
|
128 |
TypeArray at:($| asciiValue) put:nil. |
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
129 |
|
87 | 130 |
block := [:s :char | s nextToken:char]. |
89 | 131 |
#( $; $. $( $) $[ $] "$!!" $^ $| $_ ) do:[:ch | |
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
132 |
ActionArray at:(ch asciiValue) put:block |
87 | 133 |
]. |
134 |
||
33 | 135 |
block := [:s :char | s nextIdentifier]. |
136 |
($a asciiValue) to:($z asciiValue) do:[:index | |
|
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
137 |
ActionArray at:index put:block |
33 | 138 |
]. |
139 |
($A asciiValue) to:($Z asciiValue) do:[:index | |
|
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
140 |
ActionArray at:index put:block |
33 | 141 |
]. |
71 | 142 |
AllowUnderscoreInIdentifier ifTrue:[ |
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
143 |
ActionArray at:$_ asciiValue put:block |
71 | 144 |
]. |
33 | 145 |
|
146 |
"kludge: action is characterToken, but type is special" |
|
147 |
TypeArray at:($| asciiValue) put:#special. |
|
148 |
||
80 | 149 |
"kludge: action is nextColonOrAssign, but type is special" |
150 |
TypeArray at:($: asciiValue) put:#special. |
|
151 |
||
33 | 152 |
ActionArray at:($' asciiValue) put:[:s :char | s nextString]. |
153 |
ActionArray at:($$ asciiValue) put:[:s :char | s nextCharacter]. |
|
154 |
ActionArray at:($# asciiValue) put:[:s :char | s nextHash]. |
|
155 |
ActionArray at:($% asciiValue) put:[:s :char | s nextPrimitive]. |
|
156 |
ActionArray at:($: asciiValue) put:[:s :char | s nextColonOrAssign] |
|
157 |
||
158 |
" |
|
159 |
Scanner setupActions |
|
160 |
" |
|
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
161 |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
162 |
"Modified: 23.5.1997 / 12:07:55 / cg" |
33 | 163 |
! ! |
164 |
||
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
165 |
!Scanner class methodsFor:'instance creation'! |
141 | 166 |
|
167 |
for:aStringOrStream |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
168 |
"create & return a new scanner reading from aStringOrStream" |
141 | 169 |
|
170 |
^ (super new) initializeFor:aStringOrStream |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
171 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
172 |
"Modified: 23.5.1997 / 12:08:42 / cg" |
141 | 173 |
! ! |
174 |
||
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
175 |
!Scanner class methodsFor:'defaults'! |
141 | 176 |
|
608 | 177 |
allowDollarInIdentifier |
178 |
"return true, if $-characters are allowed in identifiers. |
|
179 |
Notice, that dollars are NEVER allowed as the first character in an identifier." |
|
180 |
||
181 |
^ AllowDollarInIdentifier |
|
182 |
||
183 |
"Created: 7.9.1997 / 01:32:18 / cg" |
|
184 |
"Modified: 7.9.1997 / 01:39:44 / cg" |
|
185 |
! |
|
186 |
||
187 |
allowDollarInIdentifier:aBoolean |
|
188 |
"this allows turning on/off $-characters in identifiers. |
|
189 |
Notice, that dollars are NEVER allowed as the first character in an identifier. |
|
190 |
If turned off (the default), dollars are not allowed in identifiers, |
|
191 |
but instead are scanned as character-constant prefix. |
|
192 |
If turned on, dollars are in identifiers are allowed, while extra |
|
193 |
dollars are still scanned as constant character prefix. |
|
194 |
If you have to fileIn old VW-Vsn2.x classes, turn this off |
|
195 |
before filing them in; i.e.: |
|
196 |
Compiler allowDollarInIdentifiers:false" |
|
197 |
||
198 |
AllowDollarInIdentifier := aBoolean. |
|
199 |
self setupActions |
|
200 |
||
201 |
"Created: 7.9.1997 / 01:34:49 / cg" |
|
202 |
"Modified: 7.9.1997 / 01:39:30 / cg" |
|
203 |
! |
|
204 |
||
141 | 205 |
allowUnderscoreInIdentifier |
206 |
"return true, if underscores are allowed in identifiers" |
|
207 |
||
208 |
^ AllowUnderscoreInIdentifier |
|
209 |
! |
|
210 |
||
211 |
allowUnderscoreInIdentifier:aBoolean |
|
212 |
"this allows turning on/off underscores in identifiers. |
|
213 |
If turned off (the default), underscores are not allowed in identifiers, |
|
214 |
but instead scanned as assignment character (old ST/80 syntax). |
|
215 |
If turned on, underscores are in identifiers are allowed, while extra |
|
216 |
underscores are still scanned as assignment. |
|
608 | 217 |
If you have to fileIn old VW-Vsn2.x classes, |
218 |
turn them off with: |
|
219 |
Compiler allowUnderscoreInIdentifiers:false" |
|
141 | 220 |
|
221 |
AllowUnderscoreInIdentifier := aBoolean. |
|
222 |
self setupActions |
|
608 | 223 |
|
224 |
"Modified: 7.9.1997 / 01:35:19 / cg" |
|
141 | 225 |
! |
226 |
||
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
227 |
warnCommonMistakes |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
228 |
"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
|
229 |
|
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
230 |
^ WarnCommonMistakes |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
231 |
! |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
232 |
|
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
233 |
warnCommonMistakes:aBoolean |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
234 |
"this allows turning on/off warnings about common beginners mistakes. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
235 |
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
|
236 |
run time errors later. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
237 |
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
|
238 |
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
|
239 |
a line as: |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
240 |
Compiler warnCommonMistakes:false |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
241 |
in your 'private.rc' file" |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
242 |
|
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
243 |
WarnCommonMistakes := aBoolean |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
244 |
! |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
245 |
|
608 | 246 |
warnDollarInIdentifier |
247 |
"return true, if $-characters in identifiers are to be warned about" |
|
248 |
||
249 |
^ WarnDollarInIdentifier |
|
250 |
||
251 |
"Created: 7.9.1997 / 01:36:17 / cg" |
|
252 |
! |
|
253 |
||
254 |
warnDollarInIdentifier:aBoolean |
|
255 |
"this allows turning on/off warnings about $-characters in identifiers. |
|
256 |
You may find those warnings useful, to make certain that your code |
|
257 |
is portable to other smalltalk versions, which do not allow this |
|
258 |
(i.e. VW releases 2.x and maybe others). |
|
259 |
Notice, that dollars are NEVER allowed as the first character in an identifier. |
|
260 |
If you get bored by those warnings, turn them off by adding |
|
261 |
a line as: |
|
262 |
Compiler warnDollarInIdentifier:false |
|
263 |
in your 'private.rc' file" |
|
264 |
||
265 |
WarnDollarInIdentifier := aBoolean |
|
266 |
||
267 |
"Created: 7.9.1997 / 01:37:42 / cg" |
|
268 |
"Modified: 7.9.1997 / 01:40:02 / cg" |
|
269 |
! |
|
270 |
||
141 | 271 |
warnOldStyleAssignment |
272 |
"return true, if underscore-assignment (pre ST-80v4 syntax) are to be warned about" |
|
273 |
||
274 |
^ WarnOldStyleAssignment |
|
275 |
! |
|
276 |
||
277 |
warnOldStyleAssignment:aBoolean |
|
278 |
"this allows turning on/off warnings about underscore-assignment (pre ST-80v4 syntax). |
|
279 |
If you get bored by those warnings, turn them off by adding |
|
280 |
a line as: |
|
281 |
Compiler warnOldStyleAssignment:false |
|
282 |
in your 'private.rc' file" |
|
283 |
||
284 |
WarnOldStyleAssignment := aBoolean |
|
285 |
! |
|
286 |
||
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
287 |
warnPossibleIncompatibilities |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
288 |
"return true, if possible incompatibilities (with other ST systems) |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
289 |
are to be warned about" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
290 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
291 |
^ WarnPossibleIncompatibilities |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
292 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
293 |
"Modified: 23.5.1997 / 12:02:02 / cg" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
294 |
! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
295 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
296 |
warnPossibleIncompatibilities:aBoolean |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
297 |
"this turns warnings about possible incompatibilities (with other ST systems) |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
298 |
on or off. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
299 |
If you get bored by those warnings, turn them off by adding |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
300 |
a line as: |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
301 |
Compiler warnPossibleIncompatibilities:false |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
302 |
in your 'private.rc' file." |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
303 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
304 |
WarnPossibleIncompatibilities := aBoolean |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
305 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
306 |
"Created: 23.5.1997 / 12:02:45 / cg" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
307 |
! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
308 |
|
141 | 309 |
warnSTXSpecials |
310 |
"return true, if ST/X specials are to be warned about" |
|
311 |
||
312 |
^ WarnSTXSpecials |
|
313 |
! |
|
314 |
||
315 |
warnSTXSpecials:aBoolean |
|
316 |
"this allows turning on/off warnings about stx specials. |
|
317 |
If you get bored by those warnings, turn them off by adding |
|
318 |
a line as: |
|
319 |
Compiler warnSTXSpecials:false |
|
320 |
in your 'private.rc' file" |
|
321 |
||
322 |
WarnSTXSpecials := aBoolean |
|
323 |
! |
|
324 |
||
325 |
warnUnderscoreInIdentifier |
|
326 |
"return true, if underscores in identifiers are to be warned about" |
|
327 |
||
328 |
^ WarnUnderscoreInIdentifier |
|
329 |
! |
|
330 |
||
331 |
warnUnderscoreInIdentifier:aBoolean |
|
332 |
"this allows turning on/off warnings about underscores in identifiers. |
|
608 | 333 |
You may find those warnings useful, to make certain that your code |
334 |
is portable to other smalltalk versions, which do not allow this |
|
335 |
(i.e. VW releases 2.x). |
|
141 | 336 |
If you get bored by those warnings, turn them off by adding |
337 |
a line as: |
|
608 | 338 |
Compiler warnUnderscoreInIdentifier:false |
141 | 339 |
in your 'private.rc' file" |
340 |
||
341 |
WarnUnderscoreInIdentifier := aBoolean |
|
608 | 342 |
|
343 |
"Modified: 7.9.1997 / 01:37:13 / cg" |
|
141 | 344 |
! |
345 |
||
346 |
warnings |
|
347 |
"return true, if any warnings are to be shown" |
|
348 |
||
349 |
^ Warnings |
|
350 |
! |
|
351 |
||
352 |
warnings:aBoolean |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
353 |
"this allows turning on/off all warnings; the default is on. |
141 | 354 |
You can turn off warnings in your 'private.rc' file with |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
355 |
Compiler warnings:false |
141 | 356 |
" |
357 |
||
358 |
Warnings := aBoolean |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
359 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
360 |
"Modified: 23.5.1997 / 12:03:05 / cg" |
141 | 361 |
! ! |
362 |
||
98 | 363 |
!Scanner methodsFor:'ST-80 compatibility'! |
364 |
||
365 |
endOfLastToken |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
366 |
"return the position of the token which was just read. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
367 |
This method was required by some PD program. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
368 |
It is not maintained and may be removed without notice." |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
369 |
|
98 | 370 |
^ source position |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
371 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
372 |
"Modified: 23.5.1997 / 12:14:27 / cg" |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
373 |
! |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
374 |
|
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
375 |
scanTokens:aStringOrStream |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
376 |
"return a collection of symbolic tokens from the passed input" |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
377 |
|
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
378 |
|tokens| |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
379 |
|
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
380 |
self initializeFor:aStringOrStream. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
381 |
tokens := OrderedCollection new. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
382 |
self nextToken. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
383 |
[token notNil] whileTrue:[ |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
384 |
tokens add:token. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
385 |
self nextToken |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
386 |
]. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
387 |
^ tokens |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
388 |
|
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
389 |
" |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
390 |
Scanner new |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
391 |
scanTokens:'Boolean subclass:#True |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
392 |
instanceVariableNames:'''' |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
393 |
classVariableNames:'''' |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
394 |
poolDictionaries:'''' |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
395 |
category:''Kernel-Objects'' |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
396 |
' |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
397 |
" |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
398 |
|
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
399 |
"Modified: 20.6.1997 / 18:22:58 / cg" |
98 | 400 |
! ! |
401 |
||
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
402 |
!Scanner methodsFor:'accessing'! |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
403 |
|
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
404 |
comments |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
405 |
"not yet implemented" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
406 |
|
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
407 |
^ currentComments |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
408 |
|
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
409 |
"Created: 20.4.1996 / 20:07:01 / cg" |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
410 |
"Modified: 23.5.1997 / 12:14:45 / cg" |
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
411 |
! |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
412 |
|
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
413 |
saveComments:aBoolean |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
414 |
"not yet implemented" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
415 |
|
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
416 |
saveComments := aBoolean |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
417 |
|
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
418 |
"Created: 20.4.1996 / 20:03:56 / cg" |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
419 |
"Modified: 23.5.1997 / 12:14:49 / cg" |
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
420 |
! |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
421 |
|
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
422 |
sourceStream |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
423 |
^ source |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
424 |
|
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
425 |
"Created: 20.4.1996 / 19:59:58 / cg" |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
426 |
! ! |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
427 |
|
81 | 428 |
!Scanner methodsFor:'directives'! |
429 |
||
74 | 430 |
parseDirective |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
431 |
"parse a directive - this is an ST/X special" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
432 |
|
81 | 433 |
|directive packageName namespace list| |
74 | 434 |
|
435 |
source next. |
|
436 |
source skipSeparatorsExceptCR. |
|
437 |
hereChar := source peek. |
|
438 |
hereChar isLetter ifTrue:[ |
|
413 | 439 |
directive := source nextWord. |
440 |
source peek == $: ifTrue:[ |
|
441 |
source next. |
|
442 |
source skipSeparatorsExceptCR. |
|
443 |
hereChar := source peek. |
|
74 | 444 |
|
413 | 445 |
" |
446 |
Package: 'name-of-package' |
|
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
447 |
Package: packageId |
413 | 448 |
" |
449 |
directive = 'Package' ifTrue:[ |
|
450 |
packageName := self parseDirectiveStringArg. |
|
451 |
packageName notNil ifTrue:[ |
|
452 |
(requestor respondsTo:#setPackage:) ifTrue:[ |
|
453 |
requestor setPackage:packageName |
|
454 |
]. |
|
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
455 |
] ifFalse:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
456 |
Transcript showCR:'unrecognized ''Package'' directive'. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
457 |
^ false |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
458 |
] |
413 | 459 |
]. |
74 | 460 |
|
413 | 461 |
" |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
462 |
Namespace: 'nameSpaceIdentifier' |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
463 |
Namespace: nameSpaceIdentifier |
413 | 464 |
" |
417 | 465 |
(directive = 'Namespace' |
466 |
or:[directive = 'NameSpace']) ifTrue:[ |
|
413 | 467 |
namespace := self parseDirectiveStringArg. |
468 |
namespace notNil ifTrue:[ |
|
469 |
(requestor respondsTo:#setNameSpace:) ifTrue:[ |
|
470 |
requestor setNameSpace:namespace |
|
426
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
471 |
] ifFalse:[ |
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
472 |
self setNameSpace:namespace |
413 | 473 |
]. |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
474 |
] ifFalse:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
475 |
Transcript showCR:'unrecognized ''NameSpace'' directive'. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
476 |
^ false |
413 | 477 |
]. |
478 |
]. |
|
81 | 479 |
|
413 | 480 |
" |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
481 |
Uses: 'nameSpace1', ... , 'nameSpaceN' |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
482 |
Uses: nameSpaceId1, ... , nameSpaceIdN |
413 | 483 |
" |
484 |
directive = 'Uses' ifTrue:[ |
|
485 |
list := self parseDirectiveStringListArg. |
|
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
486 |
list notNil ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
487 |
(requestor respondsTo:#addNameSpaces:) ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
488 |
requestor addNameSpaces:list |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
489 |
] |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
490 |
] ifFalse:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
491 |
Transcript showCR:'unrecognized ''Uses'' directive'. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
492 |
^ false |
426
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
493 |
] |
413 | 494 |
]. |
495 |
||
496 |
" |
|
497 |
Prerequisites: 'name-of-package', ... , 'name-of-package' |
|
498 |
" |
|
499 |
directive = 'Prerequisites' ifTrue:[ |
|
500 |
list := self parseDirectiveStringListArg. |
|
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
501 |
list notNil ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
502 |
(requestor respondsTo:#requirePackages:) ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
503 |
requestor requirePackages:list |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
504 |
]. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
505 |
] ifFalse:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
506 |
Transcript showCR:'unrecognized ''Prerequisites'' directive'. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
507 |
^ false |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
508 |
] |
413 | 509 |
]. |
510 |
] |
|
74 | 511 |
]. |
512 |
hereChar := source peek. |
|
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
513 |
^ true. |
413 | 514 |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
515 |
"Modified: 23.5.1997 / 12:15:24 / cg" |
141 | 516 |
! |
517 |
||
518 |
parseDirectiveStringArg |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
519 |
"helper for parsing a directive" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
520 |
|
141 | 521 |
hereChar == $' ifTrue:[ |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
522 |
self nextString. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
523 |
tokenType == #String ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
524 |
^ tokenValue |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
525 |
] |
141 | 526 |
]. |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
527 |
(hereChar isLetter or:[hereChar == $_]) ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
528 |
self nextIdentifier. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
529 |
tokenType == #Identifier ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
530 |
^ tokenName |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
531 |
] |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
532 |
]. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
533 |
|
141 | 534 |
^ nil |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
535 |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
536 |
"Modified: 23.5.1997 / 12:15:46 / cg" |
141 | 537 |
! |
538 |
||
539 |
parseDirectiveStringListArg |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
540 |
"helper for parsing a directive" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
541 |
|
141 | 542 |
|list| |
543 |
||
544 |
list := OrderedCollection new. |
|
545 |
||
546 |
[hereChar == $'] whileTrue:[ |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
547 |
list addLast:self parseDirectiveStringArg. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
548 |
source skipSeparatorsExceptCR. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
549 |
hereChar := source peek. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
550 |
(hereChar == $,) ifTrue:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
551 |
source next. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
552 |
source skipSeparatorsExceptCR. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
553 |
hereChar := source peek. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
554 |
]. |
141 | 555 |
]. |
556 |
^ list |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
557 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
558 |
"Modified: 23.5.1997 / 12:15:51 / cg" |
0 | 559 |
! ! |
560 |
||
561 |
!Scanner methodsFor:'error handling'! |
|
562 |
||
431
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
563 |
lastTokenLineNumber |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
564 |
"return the line number of the token which was just read." |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
565 |
|
431
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
566 |
^ tokenLineNr |
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
567 |
|
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
568 |
"Created: 8.11.1996 / 18:46:36 / cg" |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
569 |
"Modified: 23.5.1997 / 12:16:12 / cg" |
431
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
570 |
! |
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
571 |
|
0 | 572 |
notifyError:aMessage position:position to:endPos |
573 |
"notify requestor of an error - if there is no requestor |
|
53 | 574 |
put it on the transcript. Requestor is typically the CodeView |
575 |
in which the accept/doIt was triggered, or the PositionableStream |
|
576 |
which does the fileIn. The requestor may decide how to highlight the |
|
577 |
error (and/or to abort the compile). |
|
0 | 578 |
Return the result passed back by the requestor." |
579 |
||
53 | 580 |
ignoreErrors ifFalse:[ |
581 |
requestor isNil ifTrue:[ |
|
582 |
self showErrorMessage:aMessage position:position. |
|
583 |
^ false |
|
584 |
]. |
|
83 | 585 |
^ requestor error:aMessage position:position to:endPos from:self |
0 | 586 |
]. |
53 | 587 |
^ false |
0 | 588 |
! |
589 |
||
590 |
notifyWarning:aMessage position:position to:endPos |
|
591 |
"notify requestor of an warning - if there is no requestor |
|
592 |
put it on the transcript. |
|
593 |
Return the result passed back by the requestor." |
|
594 |
||
53 | 595 |
ignoreWarnings ifFalse:[ |
596 |
requestor isNil ifTrue:[ |
|
45 | 597 |
self showErrorMessage:aMessage position:position. |
53 | 598 |
^ false |
45 | 599 |
]. |
83 | 600 |
^ requestor warning:aMessage position:position to:endPos from:self |
0 | 601 |
]. |
53 | 602 |
^ false |
0 | 603 |
! |
604 |
||
141 | 605 |
showErrorMessage:aMessage position:pos |
606 |
"show an errormessage on the Transcript" |
|
0 | 607 |
|
141 | 608 |
ignoreErrors ifFalse:[ |
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
609 |
Smalltalk silentLoading == true ifFalse:[ |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
610 |
Transcript showCR:(pos printString , ' [line: ' , tokenLineNr printString , '] ' , aMessage) |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
611 |
] |
141 | 612 |
] |
274 | 613 |
|
614 |
"Modified: 18.5.1996 / 15:44:35 / cg" |
|
141 | 615 |
! |
616 |
||
617 |
syntaxError:aMessage |
|
618 |
"a syntax error happened - position is not known" |
|
619 |
||
620 |
^ self syntaxError:aMessage position:tokenPosition |
|
0 | 621 |
! |
622 |
||
623 |
syntaxError:aMessage position:position |
|
624 |
"a syntax error happened - only start position is known" |
|
625 |
||
626 |
^ self syntaxError:aMessage position:position to:nil |
|
627 |
! |
|
628 |
||
141 | 629 |
syntaxError:aMessage position:position to:endPos |
630 |
"a syntax error happened" |
|
0 | 631 |
|
141 | 632 |
self notifyError:('Error:' , aMessage) position:position to:endPos. |
633 |
exitBlock notNil ifTrue:[exitBlock value]. |
|
634 |
^ false |
|
87 | 635 |
! |
636 |
||
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
637 |
warnCommonMistake:msg at:position |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
638 |
"warn about a common beginners mistake" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
639 |
|
311 | 640 |
self warnCommonMistake:msg position:position to:position |
641 |
||
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
642 |
"Modified: 23.5.1997 / 12:16:34 / cg" |
311 | 643 |
! |
644 |
||
645 |
warnCommonMistake:msg position:pos1 to:pos2 |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
646 |
"warn about a common beginners mistake" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
647 |
|
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
648 |
ignoreWarnings ifFalse:[ |
311 | 649 |
warnCommonMistakes ifTrue:[ |
650 |
self |
|
651 |
warning:msg |
|
652 |
position:pos1 to:pos2. |
|
653 |
] |
|
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
654 |
] |
311 | 655 |
|
656 |
"Created: 18.7.1996 / 10:28:38 / cg" |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
657 |
"Modified: 23.5.1997 / 12:16:39 / cg" |
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
658 |
! |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
659 |
|
608 | 660 |
warnDollarAt:position |
661 |
"warn about $-character in an identifier" |
|
662 |
||
663 |
ignoreWarnings ifFalse:[ |
|
664 |
warnDollarInIdentifier ifTrue:[ |
|
665 |
self |
|
666 |
warning:'$-characters in identifiers/symbols are nonportable' |
|
667 |
position:position to:position. |
|
668 |
" |
|
669 |
only warn once (per method) |
|
670 |
" |
|
671 |
warnDollarInIdentifier := false |
|
672 |
] |
|
673 |
] |
|
674 |
||
675 |
"Created: 7.9.1997 / 01:50:24 / cg" |
|
676 |
"Modified: 7.9.1997 / 01:51:13 / cg" |
|
677 |
! |
|
678 |
||
87 | 679 |
warnOldStyleAssignmentAt:position |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
680 |
"warn about an oldStyle assignment" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
681 |
|
87 | 682 |
ignoreWarnings ifFalse:[ |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
683 |
warnOldStyleAssignment ifTrue:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
684 |
self |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
685 |
warning:'old style assignment - please change to use '':=''' |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
686 |
position:position to:position. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
687 |
" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
688 |
only warn once (per method) |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
689 |
" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
690 |
warnOldStyleAssignment := false |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
691 |
] |
87 | 692 |
] |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
693 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
694 |
"Modified: 23.5.1997 / 12:16:48 / cg" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
695 |
! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
696 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
697 |
warnPossibleIncompatibility:msg position:pos1 to:pos2 |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
698 |
"warn about a possible incompatibility with other ST systems" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
699 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
700 |
ignoreWarnings ifFalse:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
701 |
warnPossibleIncompatibilities ifTrue:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
702 |
self |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
703 |
warning:('Possible incompatibility.\\' , msg) withCRs |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
704 |
position:pos1 to:pos2. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
705 |
] |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
706 |
] |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
707 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
708 |
"Created: 23.5.1997 / 12:17:54 / cg" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
709 |
"Modified: 23.5.1997 / 12:22:37 / cg" |
87 | 710 |
! |
711 |
||
712 |
warnUnderscoreAt:position |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
713 |
"warn about an underscore in an identifier" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
714 |
|
87 | 715 |
ignoreWarnings ifFalse:[ |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
716 |
warnUnderscoreInIdentifier ifTrue:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
717 |
self |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
718 |
warning:'underscores in identifiers/symbols are nonportable' |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
719 |
position:position to:position. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
720 |
" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
721 |
only warn once (per method) |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
722 |
" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
723 |
warnUnderscoreInIdentifier := false |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
724 |
] |
87 | 725 |
] |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
726 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
727 |
"Modified: 23.5.1997 / 12:17:06 / cg" |
141 | 728 |
! |
729 |
||
730 |
warning:aMessage |
|
731 |
"a warning - position is not known" |
|
732 |
||
733 |
^ self warning:aMessage position:tokenPosition |
|
734 |
! |
|
735 |
||
736 |
warning:aMessage position:position |
|
737 |
"a warning - only start position is known" |
|
738 |
||
739 |
^ self warning:aMessage position:position to:nil |
|
740 |
! |
|
741 |
||
742 |
warning:aMessage position:position to:endPos |
|
743 |
"a warning" |
|
744 |
||
745 |
^ self notifyWarning:('Warning: ' , aMessage) position:position to:endPos |
|
0 | 746 |
! ! |
747 |
||
17 | 748 |
!Scanner methodsFor:'general scanning'! |
749 |
||
750 |
scanPositionsFor:aTokenString inString:aSourceString |
|
751 |
"scan aSourceString for occurrances of aTokenString. |
|
752 |
Return a collection of start positions. |
|
753 |
Added for VW compatibility (to support syntax-highlight)." |
|
754 |
||
755 |
|searchType searchName searchValue positions t| |
|
756 |
||
757 |
" |
|
758 |
first, look what kind of token we have to search for |
|
759 |
" |
|
760 |
self initializeFor:(ReadStream on:aTokenString). |
|
761 |
self nextToken. |
|
762 |
searchType := tokenType. |
|
763 |
searchName := tokenName. |
|
764 |
searchValue := tokenValue. |
|
765 |
||
766 |
" |
|
767 |
start the real work ... |
|
768 |
" |
|
769 |
self initializeFor:(ReadStream on:aSourceString). |
|
770 |
positions := OrderedCollection new. |
|
771 |
||
772 |
[(t := self nextToken) ~~ #EOF] whileTrue:[ |
|
45 | 773 |
searchType == t ifTrue:[ |
774 |
(searchName isNil or:[tokenName = searchName]) ifTrue:[ |
|
775 |
(searchValue isNil or:[tokenValue = searchValue]) ifTrue:[ |
|
776 |
positions add:tokenPosition. |
|
777 |
] |
|
778 |
] |
|
779 |
] |
|
17 | 780 |
]. |
781 |
||
782 |
^ positions |
|
783 |
||
784 |
" |
|
30 | 785 |
Scanner new scanPositionsFor:'hello' inString:'foo bar hello baz hello' |
786 |
Scanner new scanPositionsFor:'3.14' inString:'foo 3.145 bar hello 3.14 baz hello 3.14' |
|
787 |
Scanner new scanPositionsFor:'16' inString:'foo 16 bar hello 16r10 baz hello 2r10000' |
|
17 | 788 |
" |
789 |
! ! |
|
790 |
||
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
791 |
!Scanner methodsFor:'initialization'! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
792 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
793 |
initialize |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
794 |
"initialize the scanner" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
795 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
796 |
errorFlag := false. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
797 |
tokenPosition := 1. |
610 | 798 |
tokenLineNr := lineNr := 1. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
799 |
currentComments := nil. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
800 |
saveComments := false. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
801 |
ignoreErrors := false. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
802 |
ignoreWarnings := Warnings not. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
803 |
warnSTXSpecialComment := WarnSTXSpecials. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
804 |
warnSTXNameSpaceUse := WarnSTXSpecials. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
805 |
warnUnderscoreInIdentifier := WarnUnderscoreInIdentifier. |
608 | 806 |
warnDollarInIdentifier := WarnDollarInIdentifier. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
807 |
warnOldStyleAssignment := WarnOldStyleAssignment. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
808 |
warnCommonMistakes := WarnCommonMistakes. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
809 |
warnPossibleIncompatibilities := WarnPossibleIncompatibilities. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
810 |
ActionArray isNil ifTrue:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
811 |
self class setupActions |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
812 |
] |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
813 |
|
608 | 814 |
"Modified: 7.9.1997 / 01:51:01 / cg" |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
815 |
! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
816 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
817 |
initializeFor:aStringOrStream |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
818 |
"initialize the new scanner & prepare for reading from aStringOrStream" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
819 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
820 |
self initialize. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
821 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
822 |
aStringOrStream isStream ifFalse:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
823 |
source := ReadStream on:aStringOrStream |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
824 |
] ifTrue:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
825 |
source := aStringOrStream. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
826 |
]. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
827 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
828 |
"Modified: 23.5.1997 / 12:00:39 / cg" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
829 |
! ! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
830 |
|
141 | 831 |
!Scanner methodsFor:'private'! |
3 | 832 |
|
141 | 833 |
backupPosition |
834 |
"if reading from a stream, at the end we might have read |
|
835 |
one token too many" |
|
20 | 836 |
|
141 | 837 |
(tokenType == #EOF) ifFalse:[ |
838 |
source position:tokenPosition |
|
839 |
] |
|
840 |
! |
|
15 | 841 |
|
141 | 842 |
beginComment |
843 |
^ self |
|
844 |
! |
|
845 |
||
846 |
collectedSource |
|
847 |
^ collectedSource |
|
848 |
! |
|
74 | 849 |
|
141 | 850 |
endComment:comment |
851 |
saveComments ifTrue:[ |
|
852 |
currentComments isNil ifTrue:[ |
|
853 |
currentComments := OrderedCollection with:comment |
|
45 | 854 |
] ifFalse:[ |
141 | 855 |
currentComments add:comment |
45 | 856 |
] |
3 | 857 |
]. |
858 |
! |
|
859 |
||
141 | 860 |
ignoreErrors |
861 |
"turn off notification of errors" |
|
862 |
||
863 |
ignoreErrors := true |
|
864 |
! |
|
0 | 865 |
|
141 | 866 |
ignoreWarnings |
867 |
"turn off notification of warnings" |
|
868 |
||
869 |
ignoreWarnings := true |
|
870 |
! |
|
0 | 871 |
|
141 | 872 |
notifying:anObject |
873 |
"set the requestor to be notified" |
|
874 |
||
875 |
requestor := anObject |
|
426
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
876 |
! |
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
877 |
|
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
878 |
setNameSpace:aNameSpace |
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
879 |
"/ ignored here |
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
880 |
|
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
881 |
"Created: 8.11.1996 / 13:33:10 / cg" |
141 | 882 |
! ! |
883 |
||
884 |
!Scanner methodsFor:'reading next token'! |
|
885 |
||
886 |
nextCharacter |
|
887 |
"a $ has been read - return a character token" |
|
888 |
||
889 |
|nextChar| |
|
890 |
||
0 | 891 |
source next. |
141 | 892 |
nextChar := source next. |
893 |
nextChar notNil ifTrue:[ |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
894 |
tokenValue := token := nextChar. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
895 |
tokenType := #Character |
141 | 896 |
] ifFalse:[ |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
897 |
tokenType := #EOF |
141 | 898 |
]. |
0 | 899 |
^ tokenType |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
900 |
|
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
901 |
"Modified: 20.6.1997 / 17:51:39 / cg" |
0 | 902 |
! |
903 |
||
904 |
nextColonOrAssign |
|
905 |
"colon has been read - look for = to make it an assign" |
|
906 |
||
120 | 907 |
"/ special kludge for identifier:= (without spaces inbetween) |
908 |
"/ here we needed two characters lookahead after the identifier ... |
|
909 |
||
910 |
peekChar == $= ifTrue:[ |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
911 |
source next. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
912 |
peekChar := nil. |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
913 |
tokenType := token := #':='. |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
914 |
^ tokenType |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
915 |
]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
916 |
|
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
917 |
"/ special kludge for nameSpace:: (without spaces inbetween) |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
918 |
"/ here we needed two characters lookahead after the identifier ... |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
919 |
|
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
920 |
peekChar == $: ifTrue:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
921 |
source next. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
922 |
peekChar := nil. |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
923 |
tokenType := token :=#'::'. |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
924 |
^ tokenType |
120 | 925 |
]. |
926 |
||
0 | 927 |
(source nextPeek == $=) ifTrue:[ |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
928 |
source next. |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
929 |
tokenType := token :=$_ |
0 | 930 |
] ifFalse:[ |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
931 |
tokenType := token :=$: |
0 | 932 |
]. |
933 |
^ tokenType |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
934 |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
935 |
"Modified: 20.6.1997 / 17:52:10 / cg" |
0 | 936 |
! |
937 |
||
141 | 938 |
nextHash |
500 | 939 |
|nextChar string part| |
0 | 940 |
|
141 | 941 |
nextChar := source nextPeek. |
942 |
nextChar notNil ifTrue:[ |
|
620 | 943 |
(nextChar isLetterOrDigit |
944 |
or:[(AllowUnderscoreInIdentifier == true) and:[nextChar == $_]]) ifTrue:[ |
|
500 | 945 |
string := ''. |
946 |
[nextChar notNil |
|
947 |
and:[nextChar isLetterOrDigit |
|
948 |
or:[AllowUnderscoreInIdentifier == true |
|
949 |
and:[nextChar == $_]] |
|
950 |
] |
|
951 |
] whileTrue:[ |
|
952 |
part := source nextAlphaNumericWord. |
|
953 |
part notNil ifTrue:[ |
|
954 |
string := string , part. |
|
955 |
]. |
|
956 |
nextChar := source peek. |
|
957 |
AllowUnderscoreInIdentifier == true ifTrue:[ |
|
958 |
nextChar == $_ ifTrue:[ |
|
959 |
self warnUnderscoreAt:source position. |
|
960 |
]. |
|
961 |
[nextChar == $_] whileTrue:[ |
|
962 |
string := string copyWith:nextChar. |
|
963 |
nextChar := source nextPeek. |
|
964 |
(nextChar isAlphaNumeric) ifTrue:[ |
|
965 |
string := string , source nextAlphaNumericWord. |
|
966 |
nextChar := source peek. |
|
967 |
] |
|
968 |
]. |
|
969 |
]. |
|
970 |
(nextChar == $:) ifFalse:[ |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
971 |
tokenValue := token := string asSymbol. |
500 | 972 |
tokenType := #Symbol. |
973 |
^ tokenType |
|
974 |
]. |
|
975 |
string := string copyWith:nextChar. |
|
976 |
nextChar := source nextPeek |
|
977 |
]. |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
978 |
tokenValue := token := string asSymbol. |
500 | 979 |
tokenType := #Symbol. |
980 |
^ tokenType |
|
981 |
]. |
|
982 |
(nextChar == $( ) ifTrue:[ |
|
983 |
source next. |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
984 |
token := '#('. |
500 | 985 |
tokenType := #HashLeftParen. |
986 |
^ tokenType |
|
987 |
]. |
|
988 |
(nextChar == $[ ) ifTrue:[ |
|
989 |
"it seems that ST-80 supports Constant ByteArrays as #[...] |
|
990 |
(seen in a PD program)" |
|
991 |
source next. |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
992 |
token := '#['. |
500 | 993 |
tokenType := #HashLeftBrack. |
994 |
^ tokenType |
|
995 |
]. |
|
996 |
(nextChar == $' ) ifTrue:[ |
|
997 |
"it seems that ST-80 supports arbitrary symbols as #'...' |
|
998 |
(seen in a PD program)" |
|
999 |
self nextString. |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1000 |
tokenValue := token := tokenValue asSymbol. |
500 | 1001 |
tokenType := #Symbol. |
1002 |
^ tokenType |
|
1003 |
]. |
|
1004 |
((TypeArray at:(nextChar asciiValue)) == #special) ifTrue:[ |
|
1005 |
string := source next asString. |
|
1006 |
nextChar := source peek. |
|
1007 |
nextChar notNil ifTrue:[ |
|
1008 |
((TypeArray at:(nextChar asciiValue)) == #special) ifTrue:[ |
|
1009 |
source next. |
|
1010 |
string := string copyWith:nextChar |
|
1011 |
] |
|
1012 |
]. |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1013 |
tokenValue := token := string asSymbol. |
500 | 1014 |
tokenType := #Symbol. |
1015 |
^ tokenType |
|
1016 |
] |
|
0 | 1017 |
]. |
141 | 1018 |
"this allows hash to be used as binop - |
1019 |
I dont know, if this is correct ..." |
|
1020 |
||
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1021 |
tokenName := token := '#'. |
0 | 1022 |
tokenType := #BinaryOperator. |
1023 |
^ tokenType |
|
141 | 1024 |
" |
1025 |
self syntaxError:'unexpected end-of-input in Symbol' |
|
500 | 1026 |
position:tokenPosition to:(tokenPosition + 1). |
141 | 1027 |
^ #Error |
1028 |
" |
|
500 | 1029 |
|
620 | 1030 |
"Modified: 14.10.1997 / 17:14:56 / cg" |
0 | 1031 |
! |
1032 |
||
1033 |
nextId |
|
1034 |
|nextChar string oldString |
|
1035 |
index "{ Class: SmallInteger }" |
|
1036 |
max "{ Class: SmallInteger }" | |
|
1037 |
||
1038 |
nextChar := source peek. |
|
96 | 1039 |
string := String basicNew:20. |
0 | 1040 |
index := 0. |
1041 |
max := 10. |
|
1042 |
[true] whileTrue:[ |
|
45 | 1043 |
(nextChar notNil and:[nextChar isLetterOrDigit]) ifFalse:[ |
1044 |
^ string copyTo:index |
|
1045 |
]. |
|
1046 |
(index == max) ifTrue:[ |
|
1047 |
oldString := string. |
|
96 | 1048 |
string := String basicNew:(max * 2). |
45 | 1049 |
string replaceFrom:1 to:max with:oldString. |
1050 |
max := max * 2 |
|
1051 |
]. |
|
1052 |
index := index + 1. |
|
1053 |
string at:index put:nextChar. |
|
1054 |
nextChar := source nextPeek |
|
0 | 1055 |
] |
1056 |
! |
|
1057 |
||
1058 |
nextIdentifier |
|
610 | 1059 |
|nextChar string firstChar ok pos| |
0 | 1060 |
|
87 | 1061 |
hereChar == $_ ifTrue:[ |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1062 |
"/ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1063 |
"/ no need to check for AllowUnderscoreInIdentifier here; |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1064 |
"/ could not arrive here if it was off |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1065 |
"/ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1066 |
nextChar := source nextPeek. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1067 |
(nextChar isAlphaNumeric or:[nextChar == $_]) ifFalse:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1068 |
"oops: a single underscore is an old-style assignement" |
467
feaacb47b0b5
allow degenerated keyword '_:'
Claus Gittinger <cg@exept.de>
parents:
462
diff
changeset
|
1069 |
nextChar ~~ $: ifTrue:[ |
feaacb47b0b5
allow degenerated keyword '_:'
Claus Gittinger <cg@exept.de>
parents:
462
diff
changeset
|
1070 |
self warnOldStyleAssignmentAt:tokenPosition. |
feaacb47b0b5
allow degenerated keyword '_:'
Claus Gittinger <cg@exept.de>
parents:
462
diff
changeset
|
1071 |
source next. |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1072 |
tokenType := token := $_. |
467
feaacb47b0b5
allow degenerated keyword '_:'
Claus Gittinger <cg@exept.de>
parents:
462
diff
changeset
|
1073 |
^ tokenType |
feaacb47b0b5
allow degenerated keyword '_:'
Claus Gittinger <cg@exept.de>
parents:
462
diff
changeset
|
1074 |
] |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1075 |
]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1076 |
string := '_'. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1077 |
self warnUnderscoreAt:tokenPosition. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1078 |
[nextChar == $_] whileTrue:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1079 |
string := string copyWith:$_. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1080 |
nextChar := source nextPeek. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1081 |
]. |
467
feaacb47b0b5
allow degenerated keyword '_:'
Claus Gittinger <cg@exept.de>
parents:
462
diff
changeset
|
1082 |
nextChar isAlphaNumeric ifTrue:[ |
feaacb47b0b5
allow degenerated keyword '_:'
Claus Gittinger <cg@exept.de>
parents:
462
diff
changeset
|
1083 |
string := string , source nextAlphaNumericWord. |
feaacb47b0b5
allow degenerated keyword '_:'
Claus Gittinger <cg@exept.de>
parents:
462
diff
changeset
|
1084 |
] |
87 | 1085 |
] ifFalse:[ |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1086 |
string := source nextAlphaNumericWord "self nextId". |
87 | 1087 |
]. |
0 | 1088 |
nextChar := source peek. |
87 | 1089 |
|
608 | 1090 |
(nextChar == $_ |
1091 |
or:[nextChar == $$]) ifTrue:[ |
|
1092 |
ok := (nextChar == $_) ifTrue:[AllowUnderscoreInIdentifier] ifFalse:[AllowDollarInIdentifier]. |
|
1093 |
ok ifTrue:[ |
|
610 | 1094 |
pos := source position. |
608 | 1095 |
nextChar == $_ ifTrue:[ |
610 | 1096 |
self warnUnderscoreAt:pos. |
608 | 1097 |
] ifFalse:[ |
610 | 1098 |
self warnDollarAt:pos. |
608 | 1099 |
]. |
1100 |
[ok] whileTrue:[ |
|
1101 |
string := string copyWith:nextChar. |
|
1102 |
nextChar := source nextPeek. |
|
1103 |
(nextChar isAlphaNumeric) ifTrue:[ |
|
1104 |
string := string , source nextAlphaNumericWord. |
|
1105 |
nextChar := source peek. |
|
1106 |
]. |
|
1107 |
(nextChar == $_) ifTrue:[ |
|
1108 |
ok := AllowUnderscoreInIdentifier |
|
1109 |
] ifFalse:[ |
|
1110 |
(nextChar == $$) ifTrue:[ |
|
1111 |
ok := AllowDollarInIdentifier |
|
1112 |
] ifFalse:[ |
|
1113 |
ok := false |
|
1114 |
] |
|
1115 |
] |
|
1116 |
]. |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1117 |
]. |
60 | 1118 |
]. |
1119 |
||
0 | 1120 |
(nextChar == $:) ifTrue:[ |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1121 |
source next. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1122 |
(source peek == $=) ifFalse:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1123 |
(source peek == $:) ifFalse:[ |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1124 |
tokenName := token := string copyWith:nextChar. |
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1125 |
tokenType := #Keyword. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1126 |
^ self |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1127 |
]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1128 |
peekChar := $:. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1129 |
peekChar2 := $:. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1130 |
] ifTrue:[ |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1131 |
peekChar := $:. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1132 |
peekChar2 := $=. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1133 |
] |
0 | 1134 |
]. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1135 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1136 |
nextChar == $- ifTrue:[ |
610 | 1137 |
pos := source position. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1138 |
self |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1139 |
warnPossibleIncompatibility:'add a space before ''-'' for compatibility with other systems' |
610 | 1140 |
position:pos to:pos. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1141 |
]. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1142 |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1143 |
tokenName := token := string. |
0 | 1144 |
firstChar := string at:1. |
1145 |
(firstChar == $s) ifTrue:[ |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1146 |
(string = 'self') ifTrue:[tokenType := #Self. ^self]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1147 |
(string = 'super') ifTrue:[tokenType := #Super. ^self] |
0 | 1148 |
]. |
1149 |
(firstChar == $n) ifTrue:[ |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1150 |
(string = 'nil') ifTrue:[tokenType := #Nil. ^self] |
0 | 1151 |
]. |
1152 |
(firstChar == $t) ifTrue:[ |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1153 |
(string = 'true') ifTrue:[tokenType := #True. ^self]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1154 |
(string = 'thisContext') ifTrue:[tokenType := #ThisContext. ^self] |
0 | 1155 |
]. |
1156 |
(firstChar == $f) ifTrue:[ |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1157 |
(string = 'false') ifTrue:[tokenType := #False. ^self] |
0 | 1158 |
]. |
1159 |
tokenType := #Identifier. |
|
1160 |
^ tokenType |
|
120 | 1161 |
|
1162 |
"Created: 13.9.1995 / 12:56:42 / claus" |
|
608 | 1163 |
"Modified: 7.9.1997 / 01:49:44 / cg" |
0 | 1164 |
! |
1165 |
||
141 | 1166 |
nextMantissa:radix |
1167 |
|nextChar value factor| |
|
1168 |
||
1169 |
value := 0. |
|
1170 |
factor := 1.0 / radix. |
|
1171 |
nextChar := source peek. |
|
1172 |
[(nextChar notNil and:[nextChar isDigitRadix:radix])] whileTrue:[ |
|
1173 |
value := value + (nextChar digitValue * factor). |
|
1174 |
factor := factor / radix. |
|
1175 |
nextChar := source nextPeek |
|
1176 |
]. |
|
1177 |
^ value |
|
1178 |
! |
|
1179 |
||
1180 |
nextNumber |
|
441 | 1181 |
|nextChar value s tokenRadix| |
141 | 1182 |
|
1183 |
tokenRadix := 10. |
|
1184 |
value := Integer readFrom:source radix:tokenRadix. |
|
1185 |
nextChar := source peek. |
|
1186 |
(nextChar == $r) ifTrue:[ |
|
313
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1187 |
tokenRadix := value. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1188 |
source next. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1189 |
s := 1. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1190 |
source peek == $- ifTrue:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1191 |
source next. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1192 |
s := -1 |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1193 |
]. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1194 |
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
|
1195 |
value := value * s. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1196 |
nextChar := source peek |
141 | 1197 |
]. |
1198 |
(nextChar == $.) ifTrue:[ |
|
313
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1199 |
nextChar := source nextPeek. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1200 |
(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
|
1201 |
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
|
1202 |
nextChar := source peek |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1203 |
] ifFalse:[ |
610 | 1204 |
"/ nextChar == (Character cr) ifTrue:[ |
1205 |
"/ lineNr := lineNr + 1. |
|
1206 |
"/ ]. |
|
499 | 1207 |
nextChar := peekChar := $.. |
313
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1208 |
] |
141 | 1209 |
]. |
1210 |
((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
|
1211 |
nextChar := source nextPeek. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1212 |
(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
|
1213 |
s := 1. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1214 |
(nextChar == $+) ifTrue:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1215 |
nextChar := source nextPeek |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1216 |
] ifFalse:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1217 |
(nextChar == $-) ifTrue:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1218 |
nextChar := source nextPeek. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1219 |
s := s negated |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1220 |
] |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1221 |
]. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1222 |
value := value asFloat |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1223 |
* (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
|
1224 |
] |
141 | 1225 |
]. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1226 |
nextChar == $- ifTrue:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1227 |
self |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1228 |
warnPossibleIncompatibility:'add a space before ''-'' for compatibility with other systems' |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1229 |
position:(source position) to:source position. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1230 |
]. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1231 |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1232 |
tokenValue := token := value. |
141 | 1233 |
(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
|
1234 |
(nextChar == $d) ifTrue:[ |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1235 |
source next |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1236 |
]. |
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1237 |
tokenType := #Float |
141 | 1238 |
] ifFalse:[ |
313
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1239 |
tokenType := #Integer |
141 | 1240 |
]. |
1241 |
^ tokenType |
|
313
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
1242 |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1243 |
"Modified: 20.6.1997 / 17:53:55 / cg" |
141 | 1244 |
! |
1245 |
||
0 | 1246 |
nextPrimitive |
1247 |
|nextChar inPrimitive string |
|
1248 |
index "{ Class: SmallInteger }" |
|
1249 |
len "{ Class: SmallInteger }" | |
|
1250 |
||
1251 |
nextChar := source nextPeek. |
|
1252 |
string := String new:500. |
|
1253 |
len := 500. |
|
1254 |
index := 1. |
|
1255 |
(nextChar == ${) ifTrue:[ |
|
505
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1256 |
nextChar := source nextPeek. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1257 |
inPrimitive := true. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1258 |
[inPrimitive] whileTrue:[ |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1259 |
[nextChar == $%] whileFalse:[ |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1260 |
nextChar isNil ifTrue:[ |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1261 |
self syntaxError:'unterminated primitive' |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1262 |
position:tokenPosition to:source position. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1263 |
^ #Error |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1264 |
]. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1265 |
string at:index put:nextChar. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1266 |
(index == len) ifTrue:[ |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1267 |
string := string , (String new:len). |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1268 |
len := len * 2 |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1269 |
]. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1270 |
index := index + 1. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1271 |
nextChar := source next |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1272 |
]. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1273 |
(source peek == $}) ifTrue:[ |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1274 |
inPrimitive := false |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1275 |
] ifFalse:[ |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1276 |
string at:index put:nextChar. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1277 |
(index == len) ifTrue:[ |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1278 |
string := string , (String new:len). |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1279 |
len := len * 2 |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1280 |
]. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1281 |
index := index + 1. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1282 |
nextChar := source next |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1283 |
] |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1284 |
]. |
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1285 |
source next. |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1286 |
tokenValue := token := string copyTo:(index - 1). |
505
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1287 |
tokenType := #Primitive. |
610 | 1288 |
lineNr := lineNr + (tokenValue occurrencesOf:(Character cr)). |
505
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1289 |
^ tokenType |
0 | 1290 |
]. |
1291 |
||
1292 |
"a % alone is a binary operator" |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1293 |
tokenName := token := '%'. |
0 | 1294 |
tokenType := #BinaryOperator. |
1295 |
^ tokenType. |
|
1296 |
" |
|
1297 |
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
|
1298 |
position:tokenPosition to:(tokenPosition + 1). |
0 | 1299 |
^ #Error |
1300 |
" |
|
505
793f88ee6269
handle end of input while scanning a primitive
Claus Gittinger <cg@exept.de>
parents:
500
diff
changeset
|
1301 |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1302 |
"Modified: 20.6.1997 / 17:54:08 / cg" |
0 | 1303 |
! |
1304 |
||
141 | 1305 |
nextSpecial |
1306 |
"a special character has been read, look for another one. |
|
1307 |
also -number is handled here" |
|
1308 |
||
1309 |
|firstChar secondChar thirdChar string p| |
|
0 | 1310 |
|
141 | 1311 |
firstChar := source next. |
1312 |
secondChar := source peek. |
|
241
418eb41350d3
no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
1313 |
((firstChar == $-) and:[secondChar notNil]) ifTrue:[ |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1314 |
secondChar isDigit ifTrue:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1315 |
self nextNumber. |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1316 |
tokenValue := token := tokenValue negated. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1317 |
^ tokenType |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1318 |
] |
0 | 1319 |
]. |
141 | 1320 |
string := firstChar asString. |
1321 |
secondChar notNil ifTrue:[ |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1322 |
((TypeArray at:(secondChar asciiValue)) == #special) ifTrue:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1323 |
(secondChar == $-) ifTrue:[ |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1324 |
"special- look if minus belongs to number following" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1325 |
p := source position. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1326 |
source next. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1327 |
thirdChar := source peek. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1328 |
source position:p. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1329 |
thirdChar isDigit ifTrue:[ |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1330 |
tokenName := token := string. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1331 |
tokenType := #BinaryOperator. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1332 |
self |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1333 |
warnPossibleIncompatibility:'add a space before ''-'' for compatibility with other ST systems' |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1334 |
position:p-1 |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1335 |
to:p. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1336 |
^ tokenType |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1337 |
] |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1338 |
]. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1339 |
source next. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1340 |
string := string copyWith:secondChar |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1341 |
]. |
141 | 1342 |
]. |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1343 |
tokenName := token := string. |
45 | 1344 |
tokenType := #BinaryOperator. |
3 | 1345 |
^ tokenType |
241
418eb41350d3
no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
1346 |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1347 |
"Modified: 20.6.1997 / 17:54:22 / cg" |
0 | 1348 |
! |
1349 |
||
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1350 |
nextString |
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1351 |
|nextChar string pos |
0 | 1352 |
index "{ Class: SmallInteger }" |
1353 |
len "{ Class: SmallInteger }" |
|
1354 |
inString| |
|
1355 |
||
96 | 1356 |
string := String basicNew:20. |
0 | 1357 |
len := 20. |
1358 |
index := 1. |
|
1359 |
pos := source position. |
|
1360 |
source next. |
|
1361 |
nextChar := source next. |
|
1362 |
inString := true. |
|
1363 |
||
1364 |
[inString] whileTrue:[ |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1365 |
nextChar isNil ifTrue:[ |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1366 |
self syntaxError:'unexpected end-of-input in String' |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1367 |
position:pos to:(source position - 1). |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1368 |
token := nil. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1369 |
tokenType := #EOF. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1370 |
^ tokenType |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1371 |
]. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1372 |
(nextChar == Character cr) ifTrue:[ |
610 | 1373 |
lineNr := lineNr + 1 |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1374 |
]. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1375 |
(nextChar == Character quote) ifTrue:[ |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1376 |
(source peek == Character quote) ifTrue:[ |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1377 |
source next |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1378 |
] ifFalse:[ |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1379 |
inString := false |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1380 |
] |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1381 |
]. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1382 |
inString ifTrue:[ |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1383 |
string at:index put:nextChar. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1384 |
(index == len) ifTrue:[ |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1385 |
string := string , (String new:len). |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1386 |
len := len * 2 |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1387 |
]. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1388 |
index := index + 1. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1389 |
nextChar := source next |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1390 |
] |
0 | 1391 |
]. |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1392 |
tokenValue := token := string copyTo:(index - 1). |
0 | 1393 |
tokenType := #String. |
1394 |
^ tokenType |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1395 |
|
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1396 |
"Modified: 20.6.1997 / 17:54:38 / cg" |
141 | 1397 |
! |
1398 |
||
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1399 |
nextToken |
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1400 |
"return the next token from the source-stream" |
141 | 1401 |
|
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1402 |
|skipping actionBlock v ch| |
141 | 1403 |
|
1404 |
peekChar notNil ifTrue:[ |
|
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1405 |
peekChar isSeparator ifTrue:[ |
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1406 |
peekChar == (Character cr) ifTrue:[ |
610 | 1407 |
lineNr := lineNr + 1. |
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1408 |
]. |
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1409 |
peekChar := peekChar2. |
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1410 |
peekChar2 := nil. |
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1411 |
]. |
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1412 |
]. |
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1413 |
|
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1414 |
peekChar notNil ifTrue:[ |
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1415 |
ch := peekChar. |
449
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1416 |
peekChar := peekChar2. |
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1417 |
peekChar2 := nil. |
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1418 |
hereChar := nil. |
141 | 1419 |
] ifFalse:[ |
449
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1420 |
skipping := true. |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1421 |
[skipping] whileTrue:[ |
487
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1422 |
|
449
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1423 |
outStream notNil ifTrue:[ |
487
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1424 |
hereChar := source peek. |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1425 |
[(hereChar == Character space) |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1426 |
or:[hereChar isSeparator] |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1427 |
] whileTrue:[ |
449
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1428 |
source next. |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1429 |
outStream space. |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1430 |
outCol := outCol + 1. |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1431 |
] |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1432 |
] ifFalse:[ |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1433 |
hereChar := source skipSeparatorsExceptCR. |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1434 |
]. |
487
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1435 |
|
449
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1436 |
hereChar == (Character cr) ifTrue:[ |
610 | 1437 |
lineNr := lineNr + 1. |
449
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1438 |
source next. |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1439 |
outStream notNil ifTrue:[ |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1440 |
outStream cr. |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1441 |
outCol := 1 |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1442 |
] |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1443 |
] ifFalse:[ |
487
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1444 |
hereChar == (Character return) ifTrue:[ |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1445 |
outStream notNil ifTrue:[ |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1446 |
outStream nextPut:hereChar. |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1447 |
outCol := 1 |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1448 |
]. |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1449 |
source next. |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1450 |
] ifFalse:[ |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1451 |
hereChar == (Character doubleQuote) ifTrue:[ |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1452 |
"start of a comment" |
141 | 1453 |
|
487
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1454 |
self skipComment. |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1455 |
hereChar := source peek. |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1456 |
] ifFalse:[ |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1457 |
skipping := false |
4bc6586a7d67
oops - did not treat return as whiteSpace
Claus Gittinger <cg@exept.de>
parents:
467
diff
changeset
|
1458 |
] |
449
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1459 |
] |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1460 |
] |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1461 |
]. |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1462 |
hereChar isNil ifTrue:[ |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
1463 |
token := nil. |
449
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1464 |
tokenType := #EOF. |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1465 |
^ tokenType |
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1466 |
]. |
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1467 |
ch := hereChar |
141 | 1468 |
]. |
1469 |
tokenPosition := source position. |
|
610 | 1470 |
tokenLineNr := lineNr. |
141 | 1471 |
|
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1472 |
(v := ch asciiValue) == 0 ifTrue:[ |
449
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1473 |
v := Character space asciiValue |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1474 |
]. |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1475 |
actionBlock := ActionArray at:v. |
141 | 1476 |
actionBlock notNil ifTrue:[ |
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1477 |
^ actionBlock value:self value:ch |
141 | 1478 |
]. |
1479 |
||
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1480 |
self syntaxError:('invalid character: ''' , ch asString , ''' ', |
449
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1481 |
'(' , v printString , ')') |
6ad7a414ea5d
just to make certain: handle 0-characters in input
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
1482 |
position:tokenPosition to:tokenPosition. |
141 | 1483 |
tokenType := #Error. |
1484 |
^ #Error |
|
1485 |
||
1486 |
"Modified: 13.9.1995 / 12:56:14 / claus" |
|
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1487 |
"Modified: 30.8.1997 / 00:56:08 / cg" |
141 | 1488 |
! |
1489 |
||
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1490 |
nextToken:aCharacter |
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1491 |
tokenType := aCharacter. |
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1492 |
hereChar notNil ifTrue:[source next]. |
141 | 1493 |
^ tokenType |
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1494 |
|
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
546
diff
changeset
|
1495 |
"Modified: 30.8.1997 / 00:56:23 / cg" |
141 | 1496 |
! |
1497 |
||
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1498 |
skipComment |
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1499 |
|commentStream startPos| |
141 | 1500 |
|
1501 |
saveComments ifTrue:[ |
|
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1502 |
commentStream := WriteStream on:''. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1503 |
self beginComment. |
141 | 1504 |
]. |
1505 |
||
1506 |
outStream notNil ifTrue:[ |
|
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1507 |
outStream nextPut:Character doubleQuote. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1508 |
outCol := outCol + 1 |
141 | 1509 |
]. |
1510 |
||
1511 |
startPos := source position. |
|
1512 |
source next. |
|
1513 |
hereChar := source peek. |
|
1514 |
||
1515 |
" |
|
1516 |
special ST/X addition: |
|
1517 |
a $/ right after the initial double quote makes it an up-to-end-of-line comment, |
|
1518 |
which is very useful to comment out parts of filed-in source code. |
|
1519 |
Since this is non-standard, use it in very rare cases only. |
|
1520 |
(maybe the upcoming ansi-standard adds something similar - in this case, I will |
|
1521 |
change it without notice)" |
|
1522 |
||
1523 |
hereChar == $/ ifTrue:[ |
|
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1524 |
[hereChar notNil and:[hereChar ~~ Character cr]] whileTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1525 |
saveComments ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1526 |
commentStream nextPut:hereChar |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1527 |
]. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1528 |
outStream notNil ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1529 |
outStream nextPut:hereChar. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1530 |
outCol := outCol + 1 |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1531 |
]. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1532 |
hereChar := source nextPeek. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1533 |
]. |
610 | 1534 |
lineNr := lineNr + 1. |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1535 |
ignoreWarnings ifFalse:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1536 |
warnSTXSpecialComment ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1537 |
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
|
1538 |
position:startPos to:(source position). |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1539 |
" |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1540 |
only warn once |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1541 |
" |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1542 |
warnSTXSpecialComment := false |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1543 |
] |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1544 |
]. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1545 |
outStream notNil ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1546 |
outStream cr. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1547 |
outCol := 1 |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1548 |
]. |
141 | 1549 |
] ifFalse:[ |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1550 |
hereChar == ${ ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1551 |
" |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1552 |
special ST/X addition: |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1553 |
a ${ right after the initial double quote starts a directive |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1554 |
" |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1555 |
self parseDirective |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1556 |
]. |
141 | 1557 |
|
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1558 |
[hereChar notNil and:[hereChar ~~ (Character doubleQuote)]] whileTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1559 |
hereChar == (Character cr) ifTrue:[ |
610 | 1560 |
lineNr := lineNr + 1. |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1561 |
]. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1562 |
saveComments ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1563 |
commentStream nextPut:hereChar |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1564 |
]. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1565 |
outStream notNil ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1566 |
outStream nextPut:hereChar. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1567 |
outCol := outCol + 1 |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1568 |
]. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1569 |
hereChar := source nextPeek |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1570 |
]. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1571 |
hereChar isNil ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1572 |
self warning:'unclosed comment' position:startPos to:(source position) |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1573 |
] ifFalse:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1574 |
outStream notNil ifTrue:[ |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1575 |
outStream nextPut:(Character doubleQuote). |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1576 |
outCol := outCol + 1 |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1577 |
]. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1578 |
] |
141 | 1579 |
]. |
1580 |
||
1581 |
"skip final dQuote or cr" |
|
1582 |
source next. |
|
1583 |
||
1584 |
saveComments ifTrue:[ |
|
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1585 |
self endComment:commentStream contents. |
141 | 1586 |
]. |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1587 |
|
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1588 |
"Modified: 3.1.1997 / 13:44:43 / cg" |
0 | 1589 |
! ! |
141 | 1590 |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
1591 |
!Scanner class methodsFor:'documentation'! |
148 | 1592 |
|
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1593 |
version |
620 | 1594 |
^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.71 1997-10-15 11:15:08 cg Exp $' |
148 | 1595 |
! ! |
141 | 1596 |
Scanner initialize! |