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