author | Claus Gittinger <cg@exept.de> |
Tue, 25 Feb 2020 13:47:30 +0100 | |
changeset 4646 | 023f2d14b83d |
parent 4637 | 1f1869c7b7ad |
child 4675 | 40b4f76e9d34 |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
4611 | 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 |
" |
|
1073 | 12 |
"{ Package: 'stx:libcomp' }" |
13 |
||
3551 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
0 | 16 |
Object subclass:#Scanner |
4592 | 17 |
instanceVariableNames:'typeArray actionArray source lineNr token tokenType tokenPosition |
18 |
tokenValue tokenName tokenLineNr tokenLastEndPosition hereChar |
|
19 |
peekChar peekChar2 requestor exitBlock errorFlag ignoreErrors |
|
20 |
ignoreWarnings saveComments currentComments collectedSource |
|
21 |
scanColonAsKeyword outStream outCol inArrayLiteral lastDirective |
|
22 |
parserFlags didWarnAboutSTXSpecialComment |
|
23 |
didWarnAboutUnderscoreInIdentifier didWarnAboutOldStyleAssignment |
|
24 |
didWarnAboutDollarInIdentifier didWarnAboutPeriodInSymbol |
|
25 |
unicodeActions' |
|
26 |
classVariableNames:'DefaultActionArray DefaultTypeArray DefaultUnicodeActions |
|
27 |
EmptySourceNotificationSignal' |
|
28 |
poolDictionaries:'' |
|
29 |
category:'System-Compiler' |
|
0 | 30 |
! |
31 |
||
2484 | 32 |
Scanner class instanceVariableNames:'TypeArray ActionArray UnicodeActions' |
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
33 |
|
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
34 |
" |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
35 |
No other class instance variables are inherited by this class. |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
36 |
" |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
37 |
! |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
38 |
|
648 | 39 |
Object subclass:#Comment |
4592 | 40 |
instanceVariableNames:'commentType commentString startPosition endPosition' |
41 |
classVariableNames:'' |
|
42 |
poolDictionaries:'' |
|
43 |
privateIn:Scanner |
|
648 | 44 |
! |
45 |
||
1596 | 46 |
Object subclass:#Directive |
4592 | 47 |
instanceVariableNames:'' |
48 |
classVariableNames:'' |
|
49 |
poolDictionaries:'' |
|
50 |
privateIn:Scanner |
|
1596 | 51 |
! |
52 |
||
53 |
Scanner::Directive subclass:#ClassDirective |
|
4592 | 54 |
instanceVariableNames:'className' |
55 |
classVariableNames:'' |
|
56 |
poolDictionaries:'' |
|
57 |
privateIn:Scanner::Directive |
|
1596 | 58 |
! |
59 |
||
60 |
Scanner::Directive::ClassDirective subclass:#ClassHintDirective |
|
4592 | 61 |
instanceVariableNames:'' |
62 |
classVariableNames:'' |
|
63 |
poolDictionaries:'' |
|
64 |
privateIn:Scanner::Directive |
|
1596 | 65 |
! |
66 |
||
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
67 |
!Scanner class methodsFor:'documentation'! |
20 | 68 |
|
901 | 69 |
bugs |
70 |
" |
|
71 |
array constant containing keywords as in: |
|
4611 | 72 |
#( |
73 |
foo:bar: |
|
74 |
fee:baz: |
|
75 |
) |
|
901 | 76 |
|
77 |
is scanned as 4-element array containing ( #foo: #bar: #fee: #baz: ) |
|
78 |
this MUST be fixed. |
|
79 |
||
80 |
workaround: |
|
4611 | 81 |
#( |
82 |
#'foo:bar:' |
|
83 |
#'fee:baz:' |
|
84 |
) |
|
4188 | 85 |
|
901 | 86 |
" |
87 |
! |
|
88 |
||
20 | 89 |
copyright |
90 |
" |
|
91 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
4611 | 92 |
All Rights Reserved |
20 | 93 |
|
94 |
This software is furnished under a license and may be used |
|
95 |
only in accordance with the terms of that license and with the |
|
96 |
inclusion of the above copyright notice. This software may not |
|
97 |
be provided or otherwise made available to, or used by, any |
|
98 |
other person. No title to or ownership of the software is |
|
99 |
hereby transferred. |
|
100 |
" |
|
101 |
! |
|
102 |
||
103 |
documentation |
|
104 |
" |
|
105 |
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
|
106 |
Its main method is #nextToken, which reads and returns the next token |
4188 | 107 |
Possibly placing additional information (such as tokenValue) into |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
108 |
instance variables as a side effect. |
75 | 109 |
|
4188 | 110 |
TODO: |
4611 | 111 |
some testers noticed that ST-80's scanner methods are called |
112 |
xLetter, xDigit etc. For code using these (internals), the nextNumber, |
|
113 |
nextIdentifier etc. methods should be renamed. |
|
114 |
(to me, these seem to be internal private methods; |
|
115 |
their public use is not a good idea ..) |
|
116 |
||
117 |
Scanner is typically subclassed for parsing and #nextToken |
|
118 |
invoked via #self-sends. |
|
119 |
This should be changed and scanner ought to be an instance variable |
|
120 |
of Parser - this allows more flexible use of the scanner/parser |
|
121 |
framework (i.e. changing the scanner without affecting the parser). |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
122 |
|
1302 | 123 |
Extensions: |
4611 | 124 |
this scanner allows for 3-character binary selectors. |
125 |
also, # is a valid selector. (however, ## is currently scanned as a symbol literal). |
|
1302 | 126 |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
127 |
[author:] |
4611 | 128 |
Claus Gittinger |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
129 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
130 |
[see also:] |
4611 | 131 |
Parser |
20 | 132 |
" |
41 | 133 |
! ! |
134 |
||
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
135 |
!Scanner class methodsFor:'initialization'! |
33 | 136 |
|
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
137 |
binarySelectorCharacters |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
138 |
"return a collection of characters which are allowed in binary selectors" |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
139 |
|
3643 | 140 |
^ Method binarySelectorCharacters. |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
141 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
142 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
143 |
extendedBinarySelectorCharacters |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
144 |
"return a collection of characters which are optionally allowed in binary selectors" |
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
145 |
|
4610 | 146 |
"/ ^ '±×·÷«»'. |
2487 | 147 |
^ String |
4611 | 148 |
with:(Character value:16rB1) "/ plus-minus |
149 |
with:(Character value:16rD7) "/ times |
|
150 |
with:(Character value:16rB7) "/ centered dot |
|
151 |
with:(Character value:16rF7) "/ divide |
|
152 |
with:(Character value:16rAB) "/ << |
|
153 |
with:(Character value:16rBB). "/ >> |
|
4042 | 154 |
|
155 |
"Modified (comment): / 17-11-2016 / 09:22:42 / cg" |
|
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
156 |
! |
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
157 |
|
33 | 158 |
setupActions |
4042 | 159 |
"initialize the scanner's actionTables - these are used to dispatch |
2141 | 160 |
into scanner methods as characters are read. |
161 |
Compatibility note: in previous versions, these tables used to be kept |
|
162 |
in classVariables, which made reuse hard as subclasses had no easy way of |
|
163 |
defining their own tables. These are now class instance variables." |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
164 |
|
4157 | 165 |
|block actionArray typeArray unicodeActions unicodeTypes| |
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
166 |
|
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
167 |
actionArray := Array new:256. |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
168 |
typeArray := Array new:256. |
2484 | 169 |
unicodeActions := Dictionary new. |
4157 | 170 |
unicodeTypes := Dictionary new. |
33 | 171 |
|
1303 | 172 |
"/ TODO: later versions should be configurable w.r.t separators. |
173 |
"/ #(9 10 12 13 26 32) do: [:i | TypeArray at:(i+1) put: #separator]. |
|
33 | 174 |
block := [:s :char | s nextNumber]. |
3521 | 175 |
actionArray from:($0 codePoint) to:($9 codePoint) put:block. |
33 | 176 |
|
87 | 177 |
block := [:s :char | s nextSpecial]. |
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
178 |
self binarySelectorCharacters do:[:binop | |
4611 | 179 |
|codePoint| |
180 |
codePoint := binop codePoint. |
|
181 |
codePoint <= typeArray size ifTrue:[ |
|
182 |
typeArray at:codePoint put:#special. |
|
183 |
actionArray at:codePoint put:block |
|
184 |
] ifFalse:[ |
|
185 |
unicodeTypes at:codePoint put:#extendedSpecial. |
|
186 |
unicodeActions at:codePoint put:block |
|
187 |
]. |
|
87 | 188 |
]. |
4188 | 189 |
|
2146 | 190 |
block := [:s :char | s nextExtendedSpecial:char]. |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
191 |
self extendedBinarySelectorCharacters do:[:binop | |
4611 | 192 |
|codePoint| |
193 |
codePoint := binop codePoint. |
|
194 |
codePoint <= typeArray size ifTrue:[ |
|
195 |
typeArray at:codePoint put:#extendedSpecial. |
|
196 |
actionArray at:codePoint put:block |
|
197 |
] ifFalse:[ |
|
198 |
unicodeTypes at:codePoint put:#extendedSpecial. |
|
199 |
unicodeActions at:codePoint put:block |
|
200 |
]. |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
201 |
]. |
87 | 202 |
|
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
203 |
"/ that one is a special case (both binarySelector AND syntax). |
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
204 |
typeArray at:($| codePoint) put:nil. |
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
205 |
|
87 | 206 |
block := [:s :char | s nextToken:char]. |
1510
875c90576897
Fix duplicate assignment to ActionArray for sh
Stefan Vogel <sv@exept.de>
parents:
1509
diff
changeset
|
207 |
';.^|()[]{}' do:[:ch | |
4611 | 208 |
actionArray at:(ch codePoint) put:block |
87 | 209 |
]. |
210 |
||
33 | 211 |
block := [:s :char | s nextIdentifier]. |
3521 | 212 |
actionArray from:($a codePoint) to:($z codePoint) put:block. |
213 |
actionArray from:($A codePoint) to:($Z codePoint) put:block. |
|
33 | 214 |
|
215 |
"kludge: action is characterToken, but type is special" |
|
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
216 |
typeArray at:($| codePoint) put:#special. |
33 | 217 |
|
80 | 218 |
"kludge: action is nextColonOrAssign, but type is special" |
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
219 |
typeArray at:($: codePoint) put:#special. |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
220 |
|
4334 | 221 |
actionArray at:($' codePoint) put:[:s :char | s nextString:char escapeStyle:nil]. |
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
222 |
actionArray at:($$ codePoint) put:[:s :char | s nextCharacter]. |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
223 |
actionArray at:($# codePoint) put:[:s :char | s nextHash]. |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
224 |
actionArray at:($!! codePoint) put:[:s :char | s nextExcla]. |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
225 |
actionArray at:($% codePoint) put:[:s :char | s nextPrimitive]. |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
226 |
actionArray at:($: codePoint) put:[:s :char | s nextColonOrAssign]. |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
227 |
actionArray at:($_ codePoint) put:[:s :char | s nextUnderline]. |
4291 | 228 |
"/ an experiment to allow 'special' identifiers (in backticks, allowing arbitrary characters inside) |
229 |
"/ actionArray at:($` codePoint) put:[:s :char | s nextBacktickIdentifier]. |
|
4611 | 230 |
|
2486 | 231 |
unicodeActions at:2190 "<- left arrow" put:[:s :char | s nextAssignmentArrow]. |
2484 | 232 |
|
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
233 |
ActionArray := DefaultActionArray := actionArray. |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
234 |
TypeArray := DefaultTypeArray := typeArray. |
2484 | 235 |
UnicodeActions := DefaultUnicodeActions := unicodeActions. |
33 | 236 |
|
237 |
" |
|
238 |
Scanner setupActions |
|
2182 | 239 |
Scanner withAllSubclassesDo:[:cls | cls setupActions ] |
33 | 240 |
" |
462
6a29b0b356fc
added query for valid binarySelector characters
Claus Gittinger <cg@exept.de>
parents:
460
diff
changeset
|
241 |
|
4157 | 242 |
"Modified: / 02-07-2017 / 01:11:27 / cg" |
4334 | 243 |
"Modified: / 08-02-2019 / 19:13:32 / Claus Gittinger" |
33 | 244 |
! ! |
245 |
||
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
246 |
!Scanner class methodsFor:'instance creation'! |
141 | 247 |
|
248 |
for:aStringOrStream |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
249 |
"create & return a new scanner reading from aStringOrStream" |
141 | 250 |
|
1235
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
251 |
^ self basicNew initializeFor:aStringOrStream |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
252 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
253 |
"Modified: 23.5.1997 / 12:08:42 / cg" |
854 | 254 |
! |
255 |
||
4188 | 256 |
new |
854 | 257 |
"create & return a new scanner" |
258 |
||
859 | 259 |
^ self basicNew initialize. |
854 | 260 |
|
261 |
"Modified: / 23.5.1997 / 12:08:42 / cg" |
|
262 |
"Created: / 26.5.1999 / 12:02:16 / stefan" |
|
141 | 263 |
! ! |
264 |
||
717 | 265 |
!Scanner class methodsFor:'Signal constants'! |
266 |
||
1454
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
267 |
doNotShowCompilerWarningAgainActionQuery |
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
268 |
^ DoNotShowCompilerWarningAgainActionQuery |
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
269 |
! |
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
270 |
|
717 | 271 |
emptySourceNotificationSignal |
272 |
^ EmptySourceNotificationSignal |
|
273 |
||
274 |
"Created: / 16.5.1998 / 15:55:14 / cg" |
|
275 |
! ! |
|
276 |
||
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
277 |
!Scanner class methodsFor:'accessing'! |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
278 |
|
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
279 |
actionArray |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
280 |
ActionArray isNil ifTrue:[ |
4611 | 281 |
self setupActions |
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
282 |
]. |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
283 |
^ ActionArray ? DefaultActionArray |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
284 |
! |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
285 |
|
2146 | 286 |
flushActionArray |
287 |
ActionArray := DefaultActionArray := nil. |
|
288 |
TypeArray := DefaultTypeArray := nil. |
|
4320 | 289 |
UnicodeActions := DefaultUnicodeActions := nil. |
4611 | 290 |
|
2146 | 291 |
" |
292 |
Scanner flushActionArray |
|
293 |
Parser flushActionArray |
|
294 |
ByteCodeCompiler flushActionArray |
|
295 |
Explainer flushActionArray |
|
296 |
" |
|
4320 | 297 |
|
298 |
"Modified: / 11-12-2018 / 11:25:53 / Claus Gittinger" |
|
2146 | 299 |
! |
300 |
||
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
301 |
typeArray |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
302 |
TypeArray isNil ifTrue:[ |
4611 | 303 |
self setupActions |
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
304 |
]. |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
305 |
^ TypeArray ? DefaultTypeArray |
2484 | 306 |
! |
307 |
||
308 |
unicodeActions |
|
309 |
UnicodeActions isNil ifTrue:[ |
|
4611 | 310 |
self setupActions |
2484 | 311 |
]. |
312 |
^ UnicodeActions ? DefaultUnicodeActions |
|
313 |
||
314 |
"Created: / 25-03-2011 / 13:57:34 / cg" |
|
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
315 |
! ! |
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
316 |
|
717 | 317 |
!Scanner class methodsFor:'class initialization'! |
318 |
||
319 |
initialize |
|
320 |
"initialize the classes defaults. Typically, these are changed |
|
321 |
later in the 'private.rc' file." |
|
322 |
||
323 |
EmptySourceNotificationSignal isNil ifTrue:[ |
|
4611 | 324 |
EmptySourceNotificationSignal := QuerySignal new mayProceed:true. |
325 |
EmptySourceNotificationSignal notifierString:'empty source given to evaluate'. |
|
326 |
EmptySourceNotificationSignal nameClass:self message:#emptySourceNotificationSignal. |
|
717 | 327 |
]. |
328 |
||
329 |
" |
|
330 |
self initialize |
|
331 |
" |
|
332 |
||
333 |
"Modified: / 16.5.1998 / 15:55:41 / cg" |
|
334 |
! ! |
|
335 |
||
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
336 |
!Scanner class methodsFor:'defaults'! |
141 | 337 |
|
608 | 338 |
allowDollarInIdentifier |
4304 | 339 |
<resource: #obsolete> |
608 | 340 |
"return true, if $-characters are allowed in identifiers. |
341 |
Notice, that dollars are NEVER allowed as the first character in an identifier." |
|
342 |
||
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
343 |
^ ParserFlags allowDollarInIdentifier |
608 | 344 |
|
345 |
"Created: 7.9.1997 / 01:32:18 / cg" |
|
346 |
"Modified: 7.9.1997 / 01:39:44 / cg" |
|
347 |
! |
|
348 |
||
349 |
allowDollarInIdentifier:aBoolean |
|
350 |
"this allows turning on/off $-characters in identifiers. |
|
351 |
Notice, that dollars are NEVER allowed as the first character in an identifier. |
|
352 |
If turned off (the default), dollars are not allowed in identifiers, |
|
353 |
but instead are scanned as character-constant prefix. |
|
354 |
If turned on, dollars are in identifiers are allowed, while extra |
|
355 |
dollars are still scanned as constant character prefix. |
|
356 |
If you have to fileIn old VW-Vsn2.x classes, turn this off |
|
357 |
before filing them in; i.e.: |
|
4611 | 358 |
Compiler allowDollarInIdentifiers:false" |
608 | 359 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
360 |
ParserFlags allowDollarInIdentifier:aBoolean. |
608 | 361 |
|
362 |
"Created: 7.9.1997 / 01:34:49 / cg" |
|
363 |
"Modified: 7.9.1997 / 01:39:30 / cg" |
|
364 |
! |
|
365 |
||
1226 | 366 |
allowDolphinExtensions |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
367 |
"return true, if ##(..) computed literal Arrays are allowed" |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
368 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
369 |
^ ParserFlags allowDolphinExtensions |
1226 | 370 |
! |
371 |
||
372 |
allowDolphinExtensions:aBoolean |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
373 |
"this allows turning on/off support for computed literal Arrays ##(..) as in dolphin. |
1226 | 374 |
If you want to fileIn Dolphin classes, enable this with: |
4611 | 375 |
Compiler allowDolphinComputedArrays:true" |
1226 | 376 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
377 |
ParserFlags allowDolphinExtensions:aBoolean. |
1226 | 378 |
|
379 |
" |
|
380 |
self allowDolphinExtensions:true |
|
381 |
self allowDolphinExtensions:false |
|
382 |
" |
|
383 |
! |
|
384 |
||
1572 | 385 |
allowLiteralNameSpaceSymbols |
4304 | 386 |
<resource: #obsolete> |
1572 | 387 |
"return true, if literal nameSpace symbols are allowed (#foo::bar) are allowed" |
388 |
||
3327 | 389 |
^ ParserFlags allowLiteralNameSpaceSymbols |
1572 | 390 |
! |
391 |
||
1261
3de89ad9de69
allow oldStyleAssignment setting added
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
392 |
allowOldStyleAssignment |
3de89ad9de69
allow oldStyleAssignment setting added
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
393 |
"return true, if underscore-assignment (pre ST-80v4 syntax) are to be allowed" |
3de89ad9de69
allow oldStyleAssignment setting added
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
394 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
395 |
^ ParserFlags allowOldStyleAssignment |
1261
3de89ad9de69
allow oldStyleAssignment setting added
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
396 |
! |
3de89ad9de69
allow oldStyleAssignment setting added
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
397 |
|
3de89ad9de69
allow oldStyleAssignment setting added
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
398 |
allowOldStyleAssignment:aBoolean |
3de89ad9de69
allow oldStyleAssignment setting added
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
399 |
"this allows turning on/off recognition of underscore-assignment (pre ST-80v4 syntax). |
3de89ad9de69
allow oldStyleAssignment setting added
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
400 |
You must turn this off, if code with variables named '_' is to be filedIn" |
3de89ad9de69
allow oldStyleAssignment setting added
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
401 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
402 |
ParserFlags allowOldStyleAssignment:aBoolean |
1261
3de89ad9de69
allow oldStyleAssignment setting added
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
403 |
! |
3de89ad9de69
allow oldStyleAssignment setting added
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
404 |
|
922
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
405 |
allowQualifiedNames |
4304 | 406 |
<resource: #obsolete> |
4303 | 407 |
"return true, if '#{..}' and 'namespace.varName' qualified names are allowed" |
922
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
408 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
409 |
^ ParserFlags allowQualifiedNames |
4303 | 410 |
|
411 |
"Modified (comment): / 23-09-2018 / 01:08:26 / Claus Gittinger" |
|
922
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
412 |
! |
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
413 |
|
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
414 |
allowQualifiedNames:aBoolean |
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
415 |
"this allows turning on/off support for qualifiedNames #{ .., } as in vw3. |
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
416 |
If you want to fileIn vw3 or later classes, enable this with: |
4611 | 417 |
Compiler allowQualifiedNames:true |
922
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
418 |
Notice, that qualified names are not really supported semantically |
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
419 |
(they are parsed, but treated like regular globals) |
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
420 |
" |
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
421 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
422 |
ParserFlags allowQualifiedNames:aBoolean. |
922
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
423 |
|
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
424 |
" |
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
425 |
self allowQualifiedNames:true |
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
426 |
self allowQualifiedNames:false |
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
427 |
" |
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
428 |
! |
77c58cc5bebc
support for vw3 qualifiedNames
Claus Gittinger <cg@exept.de>
parents:
921
diff
changeset
|
429 |
|
895 | 430 |
allowSqueakExtensions |
4304 | 431 |
<resource: #obsolete> |
1530 | 432 |
"return true, if support for squeak extensions |
4611 | 433 |
computed arrays { .., } |
434 |
c/java style arguments in message sends rec foo(arg1, ... argN) |
|
1530 | 435 |
is enabled." |
893
9fcb0294a51e
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
874
diff
changeset
|
436 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
437 |
^ ParserFlags allowSqueakExtensions |
893
9fcb0294a51e
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
874
diff
changeset
|
438 |
! |
9fcb0294a51e
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
874
diff
changeset
|
439 |
|
895 | 440 |
allowSqueakExtensions:aBoolean |
1530 | 441 |
"this allows turning on/off support for squeak extensions: |
4611 | 442 |
computed arrays { .., } |
443 |
c/java style arguments in message sends rec foo(arg1, ... argN) |
|
1530 | 444 |
|
893
9fcb0294a51e
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
874
diff
changeset
|
445 |
If you want to fileIn Squeak classes, enable this with: |
4611 | 446 |
Compiler allowSqueakComputedArrays:true" |
893
9fcb0294a51e
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
874
diff
changeset
|
447 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
448 |
ParserFlags allowSqueakExtensions:aBoolean. |
893
9fcb0294a51e
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
874
diff
changeset
|
449 |
|
9fcb0294a51e
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
874
diff
changeset
|
450 |
" |
895 | 451 |
self allowSqueakExtensions:true |
452 |
self allowSqueakExtensions:false |
|
893
9fcb0294a51e
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
874
diff
changeset
|
453 |
" |
9fcb0294a51e
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
874
diff
changeset
|
454 |
! |
9fcb0294a51e
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
874
diff
changeset
|
455 |
|
141 | 456 |
allowUnderscoreInIdentifier |
4304 | 457 |
<resource: #obsolete> |
141 | 458 |
"return true, if underscores are allowed in identifiers" |
459 |
||
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
460 |
^ ParserFlags allowUnderscoreInIdentifier |
141 | 461 |
! |
462 |
||
463 |
allowUnderscoreInIdentifier:aBoolean |
|
464 |
"this allows turning on/off underscores in identifiers. |
|
465 |
If turned off (the default), underscores are not allowed in identifiers, |
|
466 |
but instead scanned as assignment character (old ST/80 syntax). |
|
467 |
If turned on, underscores are in identifiers are allowed, while extra |
|
468 |
underscores are still scanned as assignment. |
|
4188 | 469 |
If you have to fileIn old VW-Vsn2.x classes, |
608 | 470 |
turn them off with: |
4611 | 471 |
Compiler allowUnderscoreInIdentifiers:false" |
141 | 472 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
473 |
ParserFlags allowUnderscoreInIdentifier:aBoolean. |
608 | 474 |
|
475 |
"Modified: 7.9.1997 / 01:35:19 / cg" |
|
141 | 476 |
! |
477 |
||
1644
1991a9e37aef
numArgs fixed (binOps can now be longer)
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
478 |
maxBinarySelectorSize |
3643 | 479 |
^ Method maxBinarySelectorSize |
1644
1991a9e37aef
numArgs fixed (binOps can now be longer)
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
480 |
! |
1991a9e37aef
numArgs fixed (binOps can now be longer)
Claus Gittinger <cg@exept.de>
parents:
1636
diff
changeset
|
481 |
|
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
482 |
warnCommonMistakes |
4304 | 483 |
<resource: #obsolete> |
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
484 |
"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
|
485 |
|
1663 | 486 |
^ ParserFlags warnCommonMistakes |
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
487 |
! |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
488 |
|
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
489 |
warnCommonMistakes:aBoolean |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
490 |
"this allows turning on/off warnings about common beginners mistakes. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
491 |
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
|
492 |
run time errors later. |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
493 |
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
|
494 |
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
|
495 |
a line as: |
4611 | 496 |
Compiler warnCommonMistakes:false |
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
497 |
in your 'private.rc' file" |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
498 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
499 |
ParserFlags warnCommonMistakes:aBoolean |
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
500 |
! |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
501 |
|
608 | 502 |
warnDollarInIdentifier |
4304 | 503 |
<resource: #obsolete> |
608 | 504 |
"return true, if $-characters in identifiers are to be warned about" |
505 |
||
1663 | 506 |
^ ParserFlags warnDollarInIdentifier |
608 | 507 |
|
508 |
"Created: 7.9.1997 / 01:36:17 / cg" |
|
509 |
! |
|
510 |
||
511 |
warnDollarInIdentifier:aBoolean |
|
512 |
"this allows turning on/off warnings about $-characters in identifiers. |
|
513 |
You may find those warnings useful, to make certain that your code |
|
514 |
is portable to other smalltalk versions, which do not allow this |
|
515 |
(i.e. VW releases 2.x and maybe others). |
|
516 |
Notice, that dollars are NEVER allowed as the first character in an identifier. |
|
517 |
If you get bored by those warnings, turn them off by adding |
|
518 |
a line as: |
|
4611 | 519 |
Compiler warnDollarInIdentifier:false |
608 | 520 |
in your 'private.rc' file" |
521 |
||
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
522 |
ParserFlags warnDollarInIdentifier:aBoolean |
608 | 523 |
|
524 |
"Created: 7.9.1997 / 01:37:42 / cg" |
|
525 |
"Modified: 7.9.1997 / 01:40:02 / cg" |
|
526 |
! |
|
527 |
||
141 | 528 |
warnOldStyleAssignment |
4304 | 529 |
<resource: #obsolete> |
141 | 530 |
"return true, if underscore-assignment (pre ST-80v4 syntax) are to be warned about" |
531 |
||
1663 | 532 |
^ ParserFlags warnOldStyleAssignment |
141 | 533 |
! |
534 |
||
535 |
warnOldStyleAssignment:aBoolean |
|
536 |
"this allows turning on/off warnings about underscore-assignment (pre ST-80v4 syntax). |
|
537 |
If you get bored by those warnings, turn them off by adding |
|
538 |
a line as: |
|
4611 | 539 |
Compiler warnOldStyleAssignment:false |
141 | 540 |
in your 'private.rc' file" |
541 |
||
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
542 |
ParserFlags warnOldStyleAssignment:aBoolean |
141 | 543 |
! |
544 |
||
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
545 |
warnPossibleIncompatibilities |
4304 | 546 |
<resource: #obsolete> |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
547 |
"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
|
548 |
are to be warned about" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
549 |
|
1663 | 550 |
^ ParserFlags warnPossibleIncompatibilities |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
551 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
552 |
"Modified: 23.5.1997 / 12:02:02 / cg" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
553 |
! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
554 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
555 |
warnPossibleIncompatibilities:aBoolean |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
556 |
"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
|
557 |
on or off. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
558 |
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
|
559 |
a line as: |
4611 | 560 |
Compiler warnPossibleIncompatibilities:false |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
561 |
in your 'private.rc' file." |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
562 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
563 |
ParserFlags warnPossibleIncompatibilities:aBoolean |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
564 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
565 |
"Created: 23.5.1997 / 12:02:45 / cg" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
566 |
! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
567 |
|
141 | 568 |
warnSTXSpecials |
4304 | 569 |
<resource: #obsolete> |
141 | 570 |
"return true, if ST/X specials are to be warned about" |
571 |
||
1663 | 572 |
^ ParserFlags warnSTXSpecials |
141 | 573 |
! |
574 |
||
575 |
warnSTXSpecials:aBoolean |
|
576 |
"this allows turning on/off warnings about stx specials. |
|
577 |
If you get bored by those warnings, turn them off by adding |
|
578 |
a line as: |
|
4611 | 579 |
Compiler warnSTXSpecials:false |
141 | 580 |
in your 'private.rc' file" |
581 |
||
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
582 |
ParserFlags warnSTXSpecials:aBoolean |
141 | 583 |
! |
584 |
||
585 |
warnUnderscoreInIdentifier |
|
4304 | 586 |
<resource: #obsolete> |
141 | 587 |
"return true, if underscores in identifiers are to be warned about" |
588 |
||
1663 | 589 |
^ ParserFlags warnUnderscoreInIdentifier |
141 | 590 |
! |
591 |
||
592 |
warnUnderscoreInIdentifier:aBoolean |
|
593 |
"this allows turning on/off warnings about underscores in identifiers. |
|
608 | 594 |
You may find those warnings useful, to make certain that your code |
595 |
is portable to other smalltalk versions, which do not allow this |
|
596 |
(i.e. VW releases 2.x). |
|
141 | 597 |
If you get bored by those warnings, turn them off by adding |
598 |
a line as: |
|
4611 | 599 |
Compiler warnUnderscoreInIdentifier:false |
141 | 600 |
in your 'private.rc' file" |
601 |
||
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
602 |
ParserFlags warnUnderscoreInIdentifier:aBoolean |
608 | 603 |
|
604 |
"Modified: 7.9.1997 / 01:37:13 / cg" |
|
141 | 605 |
! |
606 |
||
607 |
warnings |
|
608 |
"return true, if any warnings are to be shown" |
|
609 |
||
1663 | 610 |
^ ParserFlags warnings |
141 | 611 |
! |
612 |
||
613 |
warnings:aBoolean |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
614 |
"this allows turning on/off all warnings; the default is on. |
141 | 615 |
You can turn off warnings in your 'private.rc' file with |
4611 | 616 |
Compiler warnings:false |
141 | 617 |
" |
618 |
||
1663 | 619 |
ParserFlags warnings:aBoolean |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
620 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
621 |
"Modified: 23.5.1997 / 12:03:05 / cg" |
141 | 622 |
! ! |
623 |
||
737
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
624 |
!Scanner class methodsFor:'utility scanning'! |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
625 |
|
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
626 |
scanNumberFrom:aStream |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
627 |
"utility - helper for Number>>readSmalltalkSyntaxFrom:" |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
628 |
|
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
629 |
^ self basicNew scanNumberFrom:aStream |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
630 |
|
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
631 |
" |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
632 |
|s| |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
633 |
|
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
634 |
s := '12345abcd' readStream. |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
635 |
Transcript showCR:(self scanNumberFrom:s). |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
636 |
Transcript showCR:(s upToEnd). |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
637 |
" |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
638 |
" |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
639 |
|s| |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
640 |
|
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
641 |
s := '16rffffxabcd' readStream. |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
642 |
Transcript showCR:(self scanNumberFrom:s). |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
643 |
Transcript showCR:(s upToEnd). |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
644 |
" |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
645 |
" |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
646 |
|s| |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
647 |
|
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
648 |
s := '1.2345abcd' readStream. |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
649 |
Transcript showCR:(self scanNumberFrom:s). |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
650 |
Transcript showCR:(s upToEnd). |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
651 |
" |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
652 |
" |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
653 |
|s| |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
654 |
|
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
655 |
s := '1.abcd' readStream. |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
656 |
Transcript showCR:(self scanNumberFrom:s). |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
657 |
Transcript showCR:(s upToEnd). |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
658 |
" |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
659 |
|
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
660 |
"Modified: / 18.6.1998 / 23:10:39 / cg" |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
661 |
! ! |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
662 |
|
1417 | 663 |
!Scanner methodsFor:'Compatibility-ST80'! |
98 | 664 |
|
665 |
endOfLastToken |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
666 |
"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
|
667 |
This method was required by some PD program. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
668 |
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
|
669 |
|
3268 | 670 |
^ source position + 1 |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
671 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
672 |
"Modified: 23.5.1997 / 12:14:27 / cg" |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
673 |
! |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
674 |
|
4188 | 675 |
scan:aStringOrStream |
630 | 676 |
"initialize the scanner: set the source-stream and |
677 |
preread the first token" |
|
678 |
||
679 |
self initializeFor:aStringOrStream. |
|
680 |
self nextToken |
|
681 |
||
682 |
"Created: / 30.10.1997 / 16:59:39 / cg" |
|
683 |
! |
|
684 |
||
2139 | 685 |
scanDoing:aBlock |
686 |
"scan, evaluating aBlock for every scanned token." |
|
687 |
||
688 |
|t| |
|
689 |
||
690 |
[(t := self nextToken) ~~ #EOF] whileTrue:[ |
|
4611 | 691 |
aBlock value:t. |
2139 | 692 |
]. |
693 |
! |
|
694 |
||
630 | 695 |
scanToken |
696 |
"read the next token from my input stream" |
|
697 |
||
698 |
^ self nextToken |
|
699 |
||
700 |
"Created: / 30.10.1997 / 17:00:16 / cg" |
|
701 |
! |
|
702 |
||
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
703 |
scanTokens:aStringOrStream |
3056 | 704 |
"return a collection of symbolic tokens from the passed input, |
705 |
similar to what would be read when reading '#( <string> )'" |
|
706 |
||
707 |
|tokens readArray| |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
708 |
|
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
709 |
self initializeFor:aStringOrStream. |
3056 | 710 |
|
4188 | 711 |
readArray := |
4611 | 712 |
[ |
713 |
|elements| |
|
714 |
||
715 |
elements := OrderedCollection new. |
|
716 |
[ (token ~~ $) ) and:[ token notNil ] ] whileTrue:[ |
|
717 |
token == $( ifTrue:[ |
|
718 |
self nextToken. |
|
719 |
elements add:(readArray value) |
|
720 |
] ifFalse:[ |
|
721 |
elements add:token. |
|
722 |
]. |
|
723 |
self nextToken. |
|
724 |
]. |
|
725 |
elements asArray |
|
726 |
]. |
|
3056 | 727 |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
728 |
tokens := OrderedCollection new. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
729 |
self nextToken. |
3056 | 730 |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
731 |
[token notNil] whileTrue:[ |
4611 | 732 |
token == $( ifTrue:[ |
733 |
self nextToken. |
|
734 |
tokens add:(readArray value) |
|
735 |
] ifFalse:[ |
|
736 |
tokens add:token |
|
737 |
]. |
|
738 |
self nextToken |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
739 |
]. |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
740 |
^ tokens |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
741 |
|
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
742 |
" |
4188 | 743 |
Scanner new scanTokens:'name ident #sym ''string'' 8r12' |
744 |
||
745 |
Scanner new scanTokens:'translate (200px 100px)' |
|
3056 | 746 |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
747 |
Scanner new |
4611 | 748 |
scanTokens:'Boolean subclass:#True |
749 |
instanceVariableNames:'''' |
|
750 |
classVariableNames:'''' |
|
751 |
poolDictionaries:'''' |
|
752 |
category:''Kernel-Objects'' |
|
753 |
' |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
754 |
" |
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
755 |
|
4188 | 756 |
"Modified: / 23-08-2017 / 23:58:03 / cg" |
98 | 757 |
! ! |
758 |
||
3730 | 759 |
!Scanner methodsFor:'Compatibility-Squeak'! |
760 |
||
761 |
notify:message at:codeStreamPosition |
|
762 |
"Squeak compatibility" |
|
4188 | 763 |
|
3730 | 764 |
^ self notifyWarning:message position:codeStreamPosition to:nil |
765 |
! ! |
|
766 |
||
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
767 |
!Scanner methodsFor:'accessing'! |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
768 |
|
3755 | 769 |
atEnd |
770 |
"true if the scanned source stream's end has been reached" |
|
771 |
||
772 |
^ source atEnd |
|
773 |
! |
|
774 |
||
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
775 |
comments |
1584 | 776 |
^ currentComments ? #() |
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
777 |
! |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
778 |
|
1509 | 779 |
exitBlock:aBlock |
780 |
exitBlock := aBlock |
|
781 |
! |
|
782 |
||
4418 | 783 |
expectToken:expectedToken |
784 |
token = expectedToken ifFalse:[ |
|
4611 | 785 |
self parseError:('expected "',expectedToken asString,'"'). |
786 |
^ false. |
|
4418 | 787 |
]. |
788 |
self nextToken. |
|
789 |
^ true. |
|
790 |
||
791 |
"Created: / 25-05-2019 / 23:32:54 / Claus Gittinger" |
|
792 |
! |
|
793 |
||
2742
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
794 |
getCollectedComments |
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
795 |
"retrieve the so far collected comments, reset comment collection" |
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
796 |
|
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
797 |
|comments| |
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
798 |
|
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
799 |
(comments := currentComments) isEmptyOrNil ifTrue:[^ nil]. |
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
800 |
currentComments := nil. |
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
801 |
^ comments |
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
802 |
|
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
803 |
"Created: / 05-10-2011 / 10:09:01 / cg" |
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
804 |
! |
1da09935db64
added: #getCollectedComments
Claus Gittinger <cg@exept.de>
parents:
2741
diff
changeset
|
805 |
|
4414 | 806 |
hasError |
807 |
"return true if there where any errors (valid after parsing)" |
|
808 |
||
809 |
^ errorFlag |
|
810 |
||
811 |
"Created: / 23-05-2019 / 09:26:39 / Claus Gittinger" |
|
812 |
! |
|
813 |
||
1202
95abdd4272cd
scanning of keyword symbols in array consts fixed
Claus Gittinger <cg@exept.de>
parents:
1195
diff
changeset
|
814 |
inArrayLiteral:aBoolean |
95abdd4272cd
scanning of keyword symbols in array consts fixed
Claus Gittinger <cg@exept.de>
parents:
1195
diff
changeset
|
815 |
inArrayLiteral := aBoolean |
95abdd4272cd
scanning of keyword symbols in array consts fixed
Claus Gittinger <cg@exept.de>
parents:
1195
diff
changeset
|
816 |
! |
95abdd4272cd
scanning of keyword symbols in array consts fixed
Claus Gittinger <cg@exept.de>
parents:
1195
diff
changeset
|
817 |
|
859 | 818 |
lineNumber |
819 |
^ lineNr |
|
820 |
! |
|
821 |
||
795 | 822 |
newSourceStream:aStream |
823 |
source := aStream. |
|
824 |
self nextToken. |
|
825 |
||
826 |
"Created: / 29.10.1998 / 21:59:33 / cg" |
|
827 |
! |
|
828 |
||
1497 | 829 |
outStream:aStream |
4419 | 830 |
"if set, this stream gets the parsed comments as it is read. |
831 |
Useful to collect comments while reading" |
|
4611 | 832 |
|
1497 | 833 |
outStream := aStream. |
834 |
outCol := outCol ? 1. |
|
4418 | 835 |
|
4419 | 836 |
"Modified (comment): / 25-05-2019 / 23:45:57 / Claus Gittinger" |
1497 | 837 |
! |
838 |
||
3283 | 839 |
requestor |
840 |
^ requestor |
|
841 |
! |
|
842 |
||
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
843 |
saveComments:aBoolean |
1582
701f40070c8a
comments returns a collection
Claus Gittinger <cg@exept.de>
parents:
1580
diff
changeset
|
844 |
saveComments := aBoolean. |
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
845 |
|
2737 | 846 |
"Created: / 20-04-1996 / 20:03:56 / cg" |
847 |
"Modified: / 23-05-1997 / 12:14:49 / cg" |
|
848 |
"Modified (comment): / 04-10-2011 / 15:35:51 / cg" |
|
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
849 |
! |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
850 |
|
1242 | 851 |
sourcePosition |
3268 | 852 |
^ source position + 1 |
1242 | 853 |
! |
854 |
||
2678
fc0df237f01e
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
855 |
sourcePositionWithoutPeeks |
fc0df237f01e
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
856 |
| pos | |
4569 | 857 |
|
2678
fc0df237f01e
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
858 |
pos := self sourcePosition. |
fc0df237f01e
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
859 |
peekChar2 notNil ifTrue:[^ pos - 2]. |
fc0df237f01e
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
860 |
peekChar notNil ifTrue:[^ pos - 1]. |
fc0df237f01e
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
861 |
^pos |
fc0df237f01e
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
862 |
|
fc0df237f01e
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
863 |
"Created: / 25-08-2011 / 11:19:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
fc0df237f01e
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
864 |
! |
fc0df237f01e
Fixes in start/endPosition for Variable node
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2612
diff
changeset
|
865 |
|
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
866 |
sourceStream |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
867 |
^ source |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
868 |
|
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
869 |
"Created: 20.4.1996 / 19:59:58 / cg" |
1235
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
870 |
! |
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
871 |
|
3334 | 872 |
tokenEndPosition |
3335 | 873 |
^ tokenPosition + tokenName size - 1. |
3334 | 874 |
|
875 |
"Created: / 22-10-2013 / 00:30:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3335 | 876 |
"Modified: / 22-10-2013 / 03:11:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
3334 | 877 |
! |
878 |
||
1235
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
879 |
tokenLineNr |
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
880 |
^ tokenLineNr |
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
881 |
! |
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
882 |
|
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
883 |
tokenName |
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
884 |
^ tokenName |
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
885 |
! |
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
886 |
|
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
887 |
tokenPosition |
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
888 |
^ tokenPosition |
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
889 |
! |
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
890 |
|
3334 | 891 |
tokenStartPosition |
892 |
^ tokenPosition |
|
893 |
||
894 |
"Created: / 22-10-2013 / 00:29:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
895 |
! |
|
896 |
||
1235
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
897 |
tokenType |
fc0ccb509f4e
accessors (to allow using scanner as instVar in parser)
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
898 |
^ tokenType |
1238 | 899 |
! |
900 |
||
901 |
tokenValue |
|
902 |
^ tokenValue |
|
903 |
||
904 |
"Created: / 21.12.2001 / 22:38:08 / cg" |
|
1362 | 905 |
! ! |
906 |
||
907 |
!Scanner methodsFor:'accessing-flags'! |
|
908 |
||
909 |
allowDollarInIdentifier |
|
4304 | 910 |
<resource: #obsolete> |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
911 |
^ parserFlags allowDollarInIdentifier |
1362 | 912 |
! |
913 |
||
1511 | 914 |
allowDollarInIdentifier:something |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
915 |
parserFlags allowDollarInIdentifier:something |
1511 | 916 |
! |
917 |
||
1572 | 918 |
allowLiteralNameSpaceSymbols |
4304 | 919 |
<resource: #obsolete> |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
920 |
^ parserFlags allowLiteralNameSpaceSymbols |
1572 | 921 |
! |
922 |
||
923 |
allowLiteralNameSpaceSymbols:aBoolean |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
924 |
parserFlags allowLiteralNameSpaceSymbols:aBoolean |
1572 | 925 |
! |
926 |
||
1362 | 927 |
allowOldStyleAssignment |
4304 | 928 |
<resource: #obsolete> |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
929 |
^ parserFlags allowOldStyleAssignment |
1362 | 930 |
! |
931 |
||
1501
ca87aed7eb82
allowUnderline etc. are inst-flags
Claus Gittinger <cg@exept.de>
parents:
1497
diff
changeset
|
932 |
allowOldStyleAssignment:aBoolean |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
933 |
parserFlags allowOldStyleAssignment:aBoolean |
1501
ca87aed7eb82
allowUnderline etc. are inst-flags
Claus Gittinger <cg@exept.de>
parents:
1497
diff
changeset
|
934 |
! |
ca87aed7eb82
allowUnderline etc. are inst-flags
Claus Gittinger <cg@exept.de>
parents:
1497
diff
changeset
|
935 |
|
1362 | 936 |
allowSqueakExtensions |
4304 | 937 |
<resource: #obsolete> |
1530 | 938 |
"return true, if support for squeak extensions |
4611 | 939 |
computed arrays { .., } |
940 |
c/java style arguments in message sends rec foo(arg1, ... argN) |
|
1530 | 941 |
is enabled." |
942 |
||
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
943 |
^ parserFlags allowSqueakExtensions |
1362 | 944 |
! |
945 |
||
946 |
allowSqueakExtensions:aBoolean |
|
1530 | 947 |
"this allows turning on/off support for squeak extensions: |
4611 | 948 |
computed arrays { .., } |
949 |
c/java style arguments in message sends rec foo(arg1, ... argN) |
|
1530 | 950 |
" |
951 |
||
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
952 |
parserFlags allowSqueakExtensions:aBoolean |
1362 | 953 |
! |
954 |
||
955 |
allowUnderscoreInIdentifier |
|
4304 | 956 |
<resource: #obsolete> |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
957 |
^ parserFlags allowUnderscoreInIdentifier |
1362 | 958 |
! |
959 |
||
1501
ca87aed7eb82
allowUnderline etc. are inst-flags
Claus Gittinger <cg@exept.de>
parents:
1497
diff
changeset
|
960 |
allowUnderscoreInIdentifier:aBoolean |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
961 |
parserFlags allowUnderscoreInIdentifier:aBoolean |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
962 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
963 |
|
4188 | 964 |
didWarnAboutOldStyleAssignment |
3571 | 965 |
^ didWarnAboutOldStyleAssignment ? false |
966 |
! |
|
967 |
||
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
968 |
parserFlags |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
969 |
^ parserFlags |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
970 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
971 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
972 |
parserFlags:aParserFlagsInstance |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
973 |
parserFlags := aParserFlagsInstance |
1501
ca87aed7eb82
allowUnderline etc. are inst-flags
Claus Gittinger <cg@exept.de>
parents:
1497
diff
changeset
|
974 |
! |
ca87aed7eb82
allowUnderline etc. are inst-flags
Claus Gittinger <cg@exept.de>
parents:
1497
diff
changeset
|
975 |
|
1362 | 976 |
scanColonAsKeyword |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
977 |
"/ not used here, but eases subclassing for other languages. |
1362 | 978 |
^ scanColonAsKeyword |
979 |
! |
|
980 |
||
981 |
warnCommonMistakes |
|
4304 | 982 |
<resource: #obsolete> |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
983 |
^ parserFlags warnCommonMistakes |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
984 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
985 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
986 |
warnCommonMistakes:aBoolean |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
987 |
parserFlags warnCommonMistakes:aBoolean |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
988 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
989 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
990 |
warnDollarInIdentifier |
4304 | 991 |
<resource: #obsolete> |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
992 |
^ parserFlags warnDollarInIdentifier |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
993 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
994 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
995 |
warnDollarInIdentifier:aBoolean |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
996 |
parserFlags warnDollarInIdentifier:aBoolean |
1362 | 997 |
! |
998 |
||
999 |
warnOldStyleAssignment |
|
4304 | 1000 |
<resource: #obsolete> |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1001 |
^ parserFlags warnOldStyleAssignment |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1002 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1003 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1004 |
warnOldStyleAssignment:aBoolean |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1005 |
parserFlags warnOldStyleAssignment:aBoolean |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1006 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1007 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1008 |
warnPossibleIncompatibilities |
4304 | 1009 |
<resource: #obsolete> |
2058 | 1010 |
"return true, if possible incompatibilities (with other ST systems) |
1011 |
are to be warned about" |
|
1012 |
||
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1013 |
^ parserFlags warnPossibleIncompatibilities |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1014 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1015 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1016 |
warnPossibleIncompatibilities:aBoolean |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1017 |
parserFlags warnPossibleIncompatibilities:aBoolean |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1018 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1019 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1020 |
warnSTXNameSpaceUse |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1021 |
^ parserFlags warnSTXNameSpaceUse |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1022 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1023 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1024 |
warnSTXNameSpaceUse:aBoolean |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1025 |
parserFlags warnSTXNameSpaceUse:aBoolean |
1362 | 1026 |
! |
1027 |
||
1028 |
warnSTXSpecialComment |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1029 |
^ parserFlags warnSTXSpecialComment |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1030 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1031 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1032 |
warnSTXSpecialComment:aBoolean |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1033 |
parserFlags warnSTXSpecialComment:aBoolean |
1362 | 1034 |
! |
1035 |
||
1036 |
warnUnderscoreInIdentifier |
|
4304 | 1037 |
<resource: #obsolete> |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1038 |
^ parserFlags warnUnderscoreInIdentifier |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1039 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1040 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1041 |
warnUnderscoreInIdentifier:aBoolean |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1042 |
parserFlags warnUnderscoreInIdentifier:aBoolean |
254
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
1043 |
! ! |
edfcf93d821f
changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents:
241
diff
changeset
|
1044 |
|
81 | 1045 |
!Scanner methodsFor:'directives'! |
1046 |
||
1596 | 1047 |
parseClassDirective |
1048 |
" |
|
1049 |
Class: className |
|
1050 |
" |
|
4188 | 1051 |
|
1596 | 1052 |
|className| |
1053 |
||
1054 |
className := self parseDirectiveClassNameArg. |
|
1055 |
className isNil ifTrue:[ |
|
4611 | 1056 |
Transcript showCR:'Scanner [warning]: unrecognized ''Class'' directive'. |
1057 |
^ false |
|
1596 | 1058 |
]. |
1059 |
lastDirective := Directive newClassDirective className:className. |
|
1060 |
^ true |
|
1061 |
! |
|
1062 |
||
1063 |
parseClassHintDirective |
|
1064 |
" |
|
1065 |
ClassHint: className |
|
1066 |
" |
|
4188 | 1067 |
|
1596 | 1068 |
|className| |
1069 |
||
1070 |
className := self parseDirectiveClassNameArg. |
|
1071 |
className isNil ifTrue:[ |
|
4611 | 1072 |
Transcript showCR:'Scanner [warning]: unrecognized ''ClassHint'' directive'. |
1073 |
^ false |
|
1596 | 1074 |
]. |
1075 |
lastDirective := Directive newClassHintDirective className:className. |
|
1076 |
^ true |
|
1077 |
! |
|
1078 |
||
74 | 1079 |
parseDirective |
1596 | 1080 |
"parse a directive inside a comment (introduced with '{'). |
1081 |
This is an ST/X special" |
|
1082 |
||
1083 |
|directive| |
|
74 | 1084 |
|
1085 |
source next. |
|
1086 |
source skipSeparatorsExceptCR. |
|
656
e4249b285fd8
using #peekOrNil makes it some 10% faster when scanning
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
1087 |
hereChar := source peekOrNil. |
74 | 1088 |
hereChar isLetter ifTrue:[ |
4611 | 1089 |
directive := source nextAlphaNumericWord asLowercase. |
1090 |
source peekOrNil == $: ifTrue:[ |
|
1091 |
source next. |
|
1092 |
source skipSeparatorsExceptCR. |
|
1093 |
hereChar := source peekOrNil. |
|
1094 |
||
1095 |
" |
|
1096 |
Package: 'name-of-package' |
|
1097 |
Package: packageId |
|
1098 |
" |
|
1099 |
directive = 'package' ifTrue:[ |
|
1100 |
self parsePackageDirective. |
|
1101 |
]. |
|
1102 |
||
1103 |
" |
|
1104 |
Namespace: 'nameSpaceIdentifier' |
|
1105 |
Namespace: nameSpaceIdentifier |
|
1106 |
" |
|
1107 |
(directive = 'namespace') ifTrue:[ |
|
1108 |
self parseNamespaceDirective. |
|
1109 |
]. |
|
1110 |
||
1111 |
" |
|
1112 |
Uses: 'nameSpace1', ... , 'nameSpaceN' |
|
1113 |
Uses: nameSpaceId1, ... , nameSpaceIdN |
|
1114 |
" |
|
1115 |
directive = 'uses' ifTrue:[ |
|
1116 |
self parseUsesDirective. |
|
1117 |
]. |
|
1118 |
||
1119 |
" |
|
1120 |
reuires: 'name-of-feature' |
|
1121 |
" |
|
1122 |
directive = 'requires' ifTrue:[ |
|
1123 |
self parseRequiresDirective. |
|
1124 |
]. |
|
1125 |
||
1126 |
" |
|
1127 |
Prerequisites: 'name-of-package', ... , 'name-of-package' |
|
1128 |
" |
|
1129 |
directive = 'prerequisites' ifTrue:[ |
|
1130 |
self parsePrerequisitesDirective. |
|
1131 |
]. |
|
1132 |
||
1133 |
" |
|
1134 |
Syntax: 'name-of-dialect' |
|
1135 |
" |
|
1136 |
directive = 'syntax' ifTrue:[ |
|
1137 |
self parseSyntaxDirective. |
|
1138 |
]. |
|
1139 |
||
1140 |
" |
|
1141 |
Class: className |
|
1142 |
" |
|
1143 |
directive = 'class' ifTrue:[ |
|
1144 |
self parseClassDirective. |
|
1145 |
]. |
|
1146 |
" |
|
1147 |
ClassHint: className |
|
1148 |
" |
|
1149 |
directive = 'classhint' ifTrue:[ |
|
1150 |
self parseClassHintDirective. |
|
1151 |
]. |
|
1152 |
] |
|
74 | 1153 |
]. |
656
e4249b285fd8
using #peekOrNil makes it some 10% faster when scanning
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
1154 |
hereChar := source peekOrNil. |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1155 |
^ true. |
413 | 1156 |
|
1960 | 1157 |
"Modified: / 06-12-2006 / 16:14:54 / cg" |
141 | 1158 |
! |
1159 |
||
1596 | 1160 |
parseDirectiveClassNameArg |
1161 |
"helper for parsing a directive" |
|
1162 |
||
4188 | 1163 |
^ self |
4611 | 1164 |
parseDirectiveStringArg:[:ch | ch isLetterOrUnderline] |
1165 |
rest:[:ch | ch isLetterOrDigit or:[ch == $_ or:[ch == $:]]] |
|
1949
709ca062cf98
oops: namespace directive scanned the ns-argument wrong (ignored digits)
Claus Gittinger <cg@exept.de>
parents:
1948
diff
changeset
|
1166 |
|
709ca062cf98
oops: namespace directive scanned the ns-argument wrong (ignored digits)
Claus Gittinger <cg@exept.de>
parents:
1948
diff
changeset
|
1167 |
"Modified: / 18-11-2006 / 14:48:07 / cg" |
1596 | 1168 |
! |
1169 |
||
141 | 1170 |
parseDirectiveStringArg |
3624 | 1171 |
"helper for parsing a directive. |
1172 |
scans a word starting with a letter or underline, |
|
1173 |
and consisting of letters, digits, underlines or dots." |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1174 |
|
3577 | 1175 |
^ self parseDirectiveStringArg:[:ch | ch isLetterOrUnderline] |
4611 | 1176 |
rest:[:ch | ch isLetterOrDigit or:[ch == $_ or:[ch == $.]]] |
1949
709ca062cf98
oops: namespace directive scanned the ns-argument wrong (ignored digits)
Claus Gittinger <cg@exept.de>
parents:
1948
diff
changeset
|
1177 |
|
709ca062cf98
oops: namespace directive scanned the ns-argument wrong (ignored digits)
Claus Gittinger <cg@exept.de>
parents:
1948
diff
changeset
|
1178 |
"Modified: / 18-11-2006 / 14:47:12 / cg" |
1596 | 1179 |
! |
1180 |
||
1949
709ca062cf98
oops: namespace directive scanned the ns-argument wrong (ignored digits)
Claus Gittinger <cg@exept.de>
parents:
1948
diff
changeset
|
1181 |
parseDirectiveStringArg:firstCharacterCheckBlock rest:restCharacterCheckBlock |
1596 | 1182 |
"helper for parsing a directive" |
1183 |
||
1184 |
|strBuffer| |
|
1185 |
||
3994 | 1186 |
strBuffer := WriteStream on:''. |
1596 | 1187 |
|
141 | 1188 |
hereChar == $' ifTrue:[ |
4611 | 1189 |
hereChar := source nextPeek. |
1190 |
[hereChar ~~ $'] whileTrue:[ |
|
1191 |
strBuffer nextPut:hereChar. |
|
1192 |
hereChar := source nextPeek. |
|
1193 |
]. |
|
1194 |
hereChar := source nextPeek. |
|
1195 |
^ strBuffer contents |
|
141 | 1196 |
]. |
1596 | 1197 |
|
1949
709ca062cf98
oops: namespace directive scanned the ns-argument wrong (ignored digits)
Claus Gittinger <cg@exept.de>
parents:
1948
diff
changeset
|
1198 |
(firstCharacterCheckBlock value:hereChar) ifTrue:[ |
4611 | 1199 |
strBuffer nextPut:hereChar. |
1200 |
hereChar := source nextPeek. |
|
1201 |
[restCharacterCheckBlock value:hereChar] whileTrue:[ |
|
1202 |
strBuffer nextPut:hereChar. |
|
1203 |
hereChar := source nextPeek. |
|
1204 |
]. |
|
1205 |
^ strBuffer contents |
|
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1206 |
]. |
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1207 |
|
141 | 1208 |
^ nil |
460
c023e3713433
handle identifier in directives;
Claus Gittinger <cg@exept.de>
parents:
453
diff
changeset
|
1209 |
|
1949
709ca062cf98
oops: namespace directive scanned the ns-argument wrong (ignored digits)
Claus Gittinger <cg@exept.de>
parents:
1948
diff
changeset
|
1210 |
"Created: / 18-11-2006 / 14:46:09 / cg" |
141 | 1211 |
! |
1212 |
||
1213 |
parseDirectiveStringListArg |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1214 |
"helper for parsing a directive" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1215 |
|
141 | 1216 |
|list| |
1217 |
||
1218 |
list := OrderedCollection new. |
|
1219 |
||
1220 |
[hereChar == $'] whileTrue:[ |
|
4611 | 1221 |
list addLast:self parseDirectiveStringArg. |
1222 |
source skipSeparatorsExceptCR. |
|
1223 |
hereChar := source peekOrNil. |
|
1224 |
(hereChar == $,) ifTrue:[ |
|
1225 |
source next. |
|
1226 |
source skipSeparatorsExceptCR. |
|
1227 |
hereChar := source peekOrNil. |
|
1228 |
]. |
|
141 | 1229 |
]. |
1230 |
^ list |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1231 |
|
656
e4249b285fd8
using #peekOrNil makes it some 10% faster when scanning
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
1232 |
"Modified: / 5.3.1998 / 02:55:40 / cg" |
1596 | 1233 |
! |
1234 |
||
1235 |
parseNamespaceDirective |
|
1236 |
" |
|
1237 |
Namespace: 'nameSpace' |
|
1238 |
Namespace: nameSpace |
|
1239 |
" |
|
4188 | 1240 |
|
1596 | 1241 |
|namespace target| |
1242 |
||
1243 |
namespace := self parseDirectiveStringArg. |
|
1244 |
namespace isNil ifTrue:[ |
|
4611 | 1245 |
Transcript showCR:'Scanner [warning]: unrecognized ''Namespace'' directive'. |
1246 |
^ false |
|
1596 | 1247 |
]. |
1649 | 1248 |
target := (requestor notNil and:[ requestor respondsTo:#setNameSpace: ]) ifTrue:[requestor] ifFalse:[self]. |
3360 | 1249 |
Error handle:[:ex | |
4611 | 1250 |
ParseError raiseErrorString:ex description |
3360 | 1251 |
] do:[ |
4611 | 1252 |
target setNameSpace:namespace. |
3360 | 1253 |
]. |
1596 | 1254 |
^ true |
1255 |
! |
|
1256 |
||
1257 |
parsePackageDirective |
|
1258 |
" |
|
1259 |
Package: 'name-of-package' |
|
1260 |
Package: packageId |
|
1261 |
" |
|
4188 | 1262 |
|
1596 | 1263 |
|packageName target| |
1264 |
||
1265 |
packageName := self parseDirectiveStringArg. |
|
1266 |
packageName isNil ifTrue:[ |
|
4611 | 1267 |
Transcript showCR:'Scanner [warning]: unrecognized ''Package'' directive'. |
1268 |
^ false |
|
1596 | 1269 |
]. |
1270 |
packageName := packageName asSymbol. |
|
1649 | 1271 |
target := (requestor notNil and:[ requestor respondsTo:#setPackage: ]) ifTrue:[requestor] ifFalse:[self]. |
1596 | 1272 |
target setPackage:packageName. |
1273 |
^ true |
|
1274 |
! |
|
1275 |
||
1276 |
parsePrerequisitesDirective |
|
1277 |
" |
|
1278 |
Prerequisites: 'name-of-package1', ... , 'name-of-packageN' |
|
1279 |
" |
|
4188 | 1280 |
|
1596 | 1281 |
|list| |
1282 |
||
1283 |
list := self parseDirectiveStringListArg. |
|
1284 |
list isNil ifTrue:[ |
|
4611 | 1285 |
Transcript showCR:'Scanner [warning]: unrecognized ''Prerequisites'' directive'. |
1286 |
^ false |
|
1596 | 1287 |
]. |
1288 |
(requestor notNil and:[requestor respondsTo:#requirePackages:]) ifTrue:[ |
|
4611 | 1289 |
requestor requirePackages:list |
1596 | 1290 |
]. |
1291 |
^ true |
|
1292 |
! |
|
1293 |
||
1960 | 1294 |
parseRequiresDirective |
1295 |
" |
|
1296 |
Require: 'name-of-feature', ... , 'name-of-featureN' |
|
1297 |
" |
|
4188 | 1298 |
|
1960 | 1299 |
|list| |
1300 |
||
1301 |
list := self parseDirectiveStringListArg. |
|
1302 |
list isNil ifTrue:[ |
|
4611 | 1303 |
Transcript showCR:'Scanner [warning]: unrecognized ''Requires'' directive'. |
1304 |
^ false |
|
1960 | 1305 |
]. |
2064 | 1306 |
"/ self halt. |
1960 | 1307 |
(requestor notNil and:[requestor respondsTo:#requireFeatures:]) ifTrue:[ |
4611 | 1308 |
requestor requireFeatures:list |
1960 | 1309 |
]. |
1310 |
^ true |
|
1311 |
||
1312 |
"Created: / 06-12-2006 / 16:14:43 / cg" |
|
1313 |
! |
|
1314 |
||
1596 | 1315 |
parseSyntaxDirective |
1316 |
" |
|
1317 |
Syntax: 'st-syntax-id' |
|
1318 |
" |
|
4188 | 1319 |
|
1596 | 1320 |
|syntax target| |
1321 |
||
1322 |
syntax := self parseDirectiveStringArg. |
|
1323 |
syntax isNil ifTrue:[ |
|
4611 | 1324 |
Transcript showCR:'Scanner [warning]: unrecognized ''Syntax'' directive'. |
1325 |
^ false |
|
1596 | 1326 |
]. |
1649 | 1327 |
target := (requestor notNil and:[ requestor respondsTo:#setSyntax: ]) ifTrue:[requestor] ifFalse:[self]. |
1596 | 1328 |
target setSyntax:syntax. |
1329 |
^ true |
|
1330 |
! |
|
1331 |
||
1332 |
parseUsesDirective |
|
1333 |
" |
|
1334 |
Uses: 'nameSpace1', ... , 'nameSpaceN' |
|
1335 |
Uses: nameSpaceId1, ... , nameSpaceIdN |
|
1336 |
" |
|
4188 | 1337 |
|
1596 | 1338 |
|list| |
1339 |
||
1340 |
list := self parseDirectiveStringListArg. |
|
1341 |
list isNil ifTrue:[ |
|
4611 | 1342 |
Transcript showCR:'Scanner [warning]: unrecognized ''Uses'' directive'. |
1343 |
^ false |
|
1596 | 1344 |
]. |
1345 |
(requestor notNil and:[requestor respondsTo:#addNameSpaces:]) ifTrue:[ |
|
4611 | 1346 |
requestor addNameSpaces:list |
1596 | 1347 |
]. |
1348 |
^ true |
|
0 | 1349 |
! ! |
1350 |
||
1418 | 1351 |
!Scanner methodsFor:'dummy-syntax highlighting'! |
659
2bbc270156c7
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
656
diff
changeset
|
1352 |
|
2bbc270156c7
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
656
diff
changeset
|
1353 |
markCommentFrom:pos1 to:pos2 |
2bbc270156c7
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
656
diff
changeset
|
1354 |
|
2bbc270156c7
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
656
diff
changeset
|
1355 |
"Created: / 31.3.1998 / 13:34:45 / cg" |
661 | 1356 |
! |
1357 |
||
671 | 1358 |
markConstantFrom:pos1 to:pos2 |
1359 |
||
1360 |
"Created: / 1.4.1998 / 13:02:56 / cg" |
|
1361 |
! |
|
1362 |
||
4262 | 1363 |
markErrorFrom:pos1 to:pos2 |
1364 |
||
1365 |
"Created: / 31.3.1998 / 13:34:45 / cg" |
|
1366 |
! |
|
1367 |
||
661 | 1368 |
markStringFrom:pos1 to:pos2 |
1369 |
||
1370 |
"Created: / 31.3.1998 / 16:37:18 / cg" |
|
671 | 1371 |
! |
1372 |
||
1373 |
markSymbolFrom:pos1 to:pos2 |
|
1374 |
||
1375 |
"Created: / 1.4.1998 / 12:58:42 / cg" |
|
659
2bbc270156c7
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
656
diff
changeset
|
1376 |
! ! |
2bbc270156c7
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
656
diff
changeset
|
1377 |
|
0 | 1378 |
!Scanner methodsFor:'error handling'! |
1379 |
||
3449 | 1380 |
clearErrorFlag |
1381 |
errorFlag := false. |
|
1382 |
! |
|
1383 |
||
709 | 1384 |
correctableError:message position:pos1 to:pos2 |
1385 |
"report an error which can be corrected by compiler - |
|
4188 | 1386 |
return non-false, if correction is wanted |
3449 | 1387 |
(there is more than true/false returned here)" |
709 | 1388 |
|
1389 |
|correctIt| |
|
1390 |
||
1391 |
requestor isNil ifTrue:[ |
|
4611 | 1392 |
"/ self showErrorMessage:message position:pos1. |
1393 |
correctIt := false |
|
709 | 1394 |
] ifFalse:[ |
4611 | 1395 |
self isDoIt ifTrue:[ |
1396 |
requestor warning:message position:pos1 to:pos2 from:self. |
|
1397 |
correctIt := false. |
|
1398 |
] ifFalse:[ |
|
1399 |
correctIt := requestor correctableError:message position:pos1 to:pos2 from:self |
|
1400 |
]. |
|
709 | 1401 |
]. |
1492 | 1402 |
|
3449 | 1403 |
("correctIt == false or:["correctIt == #Error"]") ifTrue:[ |
4611 | 1404 |
self setErrorFlag. |
1405 |
exitBlock value |
|
709 | 1406 |
]. |
1407 |
^ correctIt |
|
1408 |
||
2877
8575935bb3b5
changed: #correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
2876
diff
changeset
|
1409 |
"Created: / 13-05-1998 / 16:45:56 / cg" |
4274 | 1410 |
"Modified: / 13-06-2018 / 12:46:32 / Claus Gittinger" |
4276 | 1411 |
"Modified: / 15-06-2018 / 14:55:26 / Stefan Vogel" |
709 | 1412 |
! |
1413 |
||
1023 | 1414 |
correctableSelectorWarning:message position:pos1 to:pos2 |
1415 |
"report a warning which can be corrected by compiler - |
|
1416 |
return non-false, if correction is wanted (there is more than |
|
1417 |
true/false returned here)" |
|
1418 |
||
1419 |
|correctIt| |
|
1420 |
||
1421 |
requestor isNil ifTrue:[ |
|
4611 | 1422 |
correctIt := false |
1023 | 1423 |
] ifFalse:[ |
4611 | 1424 |
DoNotShowCompilerWarningAgainActionQuery handle:[:ex | |
1425 |
parserFlags warnAboutPossiblyUnimplementedSelectors:false. |
|
1426 |
ParserFlags warnAboutPossiblyUnimplementedSelectors:false. |
|
1427 |
ex proceed. |
|
1428 |
] do:[ |
|
1429 |
correctIt := requestor correctableSelectorWarning:message position:pos1 to:pos2 from:self |
|
1430 |
] |
|
1023 | 1431 |
]. |
1432 |
correctIt == false ifTrue:[ |
|
4611 | 1433 |
exitBlock value |
1023 | 1434 |
]. |
1435 |
^ correctIt |
|
1436 |
||
2831 | 1437 |
"Created: / 19-01-2000 / 16:28:03 / cg" |
1023 | 1438 |
! |
1439 |
||
3283 | 1440 |
correctableWarning:aMessage doNotShowAgainAction:doNotShowAgainAction doNotShowAgainForThisMethodAction:doNotShowAgainForThisMethodAction position:position to:endPos |
1441 |
"notify requestor of a warning - if there is no requestor, just ignore it. |
|
1442 |
Return the result passed back from the requestor (or false, if there is none)." |
|
1443 |
||
1444 |
|answer warnAction realAction real2Action| |
|
1445 |
||
1446 |
ignoreWarnings ifTrue:[ ^ false ]. |
|
1447 |
parserFlags warnings ifFalse:[^ false]. |
|
1448 |
||
1449 |
requestor isNil ifTrue:[ |
|
4611 | 1450 |
^ false |
3283 | 1451 |
]. |
1452 |
||
1453 |
warnAction := [ answer := requestor correctableWarning:aMessage position:position to:endPos from:self ]. |
|
1454 |
||
1455 |
doNotShowAgainAction notNil ifTrue:[ |
|
4611 | 1456 |
realAction := warnAction. |
1457 |
warnAction := |
|
1458 |
[ |
|
1459 |
DoNotShowCompilerWarningAgainActionQuery |
|
1460 |
answer:doNotShowAgainAction |
|
1461 |
do:realAction |
|
1462 |
]. |
|
3283 | 1463 |
]. |
1464 |
(doNotShowAgainForThisMethodAction notNil and:[ self isDoIt not ]) ifTrue:[ |
|
4611 | 1465 |
real2Action := warnAction. |
1466 |
warnAction := |
|
1467 |
[ |
|
1468 |
DoNotShowCompilerWarningAgainForThisMethodActionQuery |
|
1469 |
answer:doNotShowAgainForThisMethodAction |
|
1470 |
do:real2Action |
|
1471 |
]. |
|
3283 | 1472 |
]. |
1473 |
||
1474 |
warnAction value. |
|
1475 |
^ answer |
|
1476 |
||
1477 |
"Created: / 28-02-2012 / 08:42:01 / cg" |
|
1478 |
! |
|
1479 |
||
2452
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1480 |
correctableWarning:message position:pos1 to:pos2 |
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1481 |
"report an error which can be corrected by compiler - |
4188 | 1482 |
return non-false, if correction is wanted |
3283 | 1483 |
(there is more than true/false returned here - i.e. a symbol, describing how to fix it)" |
2452
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1484 |
|
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1485 |
|correctIt| |
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1486 |
|
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1487 |
requestor isNil ifTrue:[ |
4611 | 1488 |
"/ self showErrorMessage:message position:pos1. |
1489 |
correctIt := false |
|
2452
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1490 |
] ifFalse:[ |
4611 | 1491 |
correctIt := requestor correctableWarning:message position:pos1 to:pos2 from:self |
2452
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1492 |
]. |
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1493 |
|
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1494 |
(correctIt == false or:[correctIt == #Error]) ifTrue:[ |
4611 | 1495 |
exitBlock value |
2452
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1496 |
]. |
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1497 |
^ correctIt |
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1498 |
|
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1499 |
"Created: / 02-11-2010 / 13:32:32 / cg" |
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1500 |
! |
68a907bd9bd1
added: #correctableWarning:position:to:
Claus Gittinger <cg@exept.de>
parents:
2395
diff
changeset
|
1501 |
|
2831 | 1502 |
disableWarningsOnCurrentMethodFor:flagName |
1503 |
"ignored here" |
|
1504 |
||
1505 |
"Created: / 28-02-2012 / 14:44:43 / cg" |
|
1506 |
! |
|
1507 |
||
3449 | 1508 |
errorFlag:flagArg |
1509 |
errorFlag := flagArg |
|
1510 |
! |
|
1511 |
||
1073 | 1512 |
errorMessagePrefix |
1513 |
^ 'Error:' |
|
1514 |
! |
|
1515 |
||
1705
19fff84a354a
more support for filein of ST/V code
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
1516 |
ignorableParseError:message |
19fff84a354a
more support for filein of ST/V code
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
1517 |
self parseError:message. |
19fff84a354a
more support for filein of ST/V code
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
1518 |
"/ if proceeded, install method anyway (used with non-st/x primitives) |
3449 | 1519 |
self clearErrorFlag |
1705
19fff84a354a
more support for filein of ST/V code
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
1520 |
! |
19fff84a354a
more support for filein of ST/V code
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
1521 |
|
1856
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1522 |
invalidCharacter:ch |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1523 |
|errMsg v| |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1524 |
|
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1525 |
v := ch codePoint. |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1526 |
ch isPrintable ifTrue:[ |
4611 | 1527 |
errMsg := 'Invalid character: ''' , ch asString , ''' ', '(' , (v radixPrintStringRadix:16) , ').'. |
1856
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1528 |
] ifFalse:[ |
4611 | 1529 |
errMsg := 'Invalid character: ' , (v radixPrintStringRadix:16) , '.'. |
1856
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1530 |
]. |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1531 |
v > 16r7F ifTrue:[ |
4611 | 1532 |
errMsg := errMsg , ' |
4042 | 1533 |
|
1534 |
Notice: |
|
1535 |
Only 7-bit ascii allowed (for compatibility with other Smalltalk dialects). |
|
4441 | 1536 |
You can enable some of the special characters via the compiler-settings dialog |
1537 |
or by setting "allowNationalCharactersInIdentifier" / "allowGreekCharactersInIdentifier" |
|
1538 |
in the ParserFlags.'. |
|
1856
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1539 |
]. |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1540 |
self syntaxError:errMsg position:tokenPosition to:tokenPosition. |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1541 |
source next. |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1542 |
tokenName := token := nil. |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1543 |
tokenType := #Error. |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1544 |
^ #Error |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1545 |
|
4042 | 1546 |
"Modified: / 17-11-2016 / 09:37:52 / cg" |
4441 | 1547 |
"Modified: / 08-06-2019 / 18:14:06 / Claus Gittinger" |
1856
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1548 |
! |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1549 |
|
431
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
1550 |
lastTokenLineNumber |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1551 |
"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
|
1552 |
|
431
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
1553 |
^ tokenLineNr |
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
1554 |
|
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
1555 |
"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
|
1556 |
"Modified: 23.5.1997 / 12:16:12 / cg" |
431
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
1557 |
! |
058e1ce760ea
added access to lastTokenLineNr
Claus Gittinger <cg@exept.de>
parents:
426
diff
changeset
|
1558 |
|
4562 | 1559 |
notifyError:aMessage as:errorClassOrNil position:position to:endPos lineNr:lineNrOrNil |
4331 | 1560 |
"notify requestor of an error - if there is no requestor |
1561 |
put it on the transcript. Requestor is typically the CodeView |
|
1562 |
in which the accept/doIt was triggered, or the PositionableStream |
|
1563 |
which does the fileIn. The requestor may decide how to highlight the |
|
1564 |
error (and/or to abort the compile). |
|
1565 |
Return the result passed back by the requestor." |
|
1566 |
||
4228 | 1567 |
(Smalltalk isInitialized not and:[Smalltalk isDebuggableApp]) ifTrue:[ |
4611 | 1568 |
"/ error during startup, but sometimes we expect an error and want to suppress it |
1569 |
Parser parseWarningSignal query ~~ #ignore ifTrue:[ |
|
1570 |
(self className,' [error]: error during initialization:') errorPrint. |
|
1571 |
aMessage errorPrintCR. |
|
1572 |
thisContext fullPrintAll. |
|
1573 |
]. |
|
2785 | 1574 |
]. |
1575 |
||
3066 | 1576 |
ignoreErrors ifTrue:[ |
4611 | 1577 |
"/ usually done, when syntax highlighting or looking for used variables |
1578 |
"/ self halt. |
|
3066 | 1579 |
] ifFalse:[ |
4611 | 1580 |
"/ Raise an error. |
1581 |
"/ For backward compatibility, if requestor |
|
1582 |
"/ IS set, then dispatch to requestor. |
|
1583 |
||
1584 |
"/ backward compatibility - will vanish eventually (use a handler, Luke) |
|
1585 |
requestor notNil ifTrue:[ |
|
1586 |
requestor error:aMessage position:position to:endPos from:self. |
|
1587 |
^ self |
|
1588 |
]. |
|
1589 |
(errorClassOrNil ? ParseError) new |
|
1590 |
errorMessage:aMessage startPosition:position endPosition:endPos; |
|
1591 |
parameter:self; |
|
1592 |
lineNumber:(lineNrOrNil ? tokenLineNr); "lineNr" |
|
1593 |
raiseRequest. |
|
0 | 1594 |
]. |
1856
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1595 |
|
4331 | 1596 |
"Created: / 08-02-2019 / 11:15:37 / Claus Gittinger" |
4453 | 1597 |
"Modified: / 28-06-2019 / 09:11:44 / Claus Gittinger" |
0 | 1598 |
! |
1599 |
||
4562 | 1600 |
notifyError:aMessage position:position to:endPos |
1601 |
"notify requestor of an error - if there is no requestor |
|
1602 |
put it on the transcript. Requestor is typically the CodeView |
|
1603 |
in which the accept/doIt was triggered, or the PositionableStream |
|
1604 |
which does the fileIn. The requestor may decide how to highlight the |
|
1605 |
error (and/or to abort the compile). |
|
1606 |
Return the result passed back by the requestor." |
|
1607 |
||
1608 |
^ self notifyError:aMessage position:position to:endPos lineNr:nil |
|
1609 |
||
1610 |
"Modified: / 18-01-2012 / 14:54:22 / Alexander Zottnick" |
|
1611 |
"Modified: / 19-01-2012 / 10:18:36 / cg" |
|
1612 |
"Modified: / 02-05-2014 / 14:51:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1613 |
"Modified: / 19-04-2018 / 10:39:56 / stefan" |
|
1614 |
"Modified: / 08-02-2019 / 11:15:59 / Claus Gittinger" |
|
1615 |
! |
|
1616 |
||
1617 |
notifyError:aMessage position:position to:endPos lineNr:lineNrOrNil |
|
1618 |
"notify requestor of an error - if there is no requestor |
|
1619 |
put it on the transcript. Requestor is typically the CodeView |
|
1620 |
in which the accept/doIt was triggered, or the PositionableStream |
|
1621 |
which does the fileIn. The requestor may decide how to highlight the |
|
1622 |
error (and/or to abort the compile). |
|
1623 |
Return the result passed back by the requestor." |
|
1624 |
||
1625 |
self notifyError:aMessage as:nil position:position to:endPos lineNr:lineNrOrNil |
|
1626 |
! |
|
1627 |
||
2831 | 1628 |
notifyWarning:aMessage doNotShowAgainAction:doNotShowAgainAction doNotShowAgainForThisMethodAction:doNotShowAgainForThisMethodAction position:position to:endPos |
2455
acdcc9b42d41
comment/format in: #notifyWarning:doNotShowAgainAction:position:to:
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1629 |
"notify requestor of a warning - if there is no requestor, just ignore it. |
1681 | 1630 |
Return the result passed back from the requestor (or false, if there is none)." |
1454
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1631 |
|
2831 | 1632 |
|answer warnAction realAction real2Action| |
1454
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1633 |
|
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1634 |
ignoreWarnings ifTrue:[ ^ false ]. |
2478
21ef13183fb5
changed: #notifyWarning:doNotShowAgainAction:position:to:
Claus Gittinger <cg@exept.de>
parents:
2455
diff
changeset
|
1635 |
parserFlags warnings ifFalse:[^ false]. |
21ef13183fb5
changed: #notifyWarning:doNotShowAgainAction:position:to:
Claus Gittinger <cg@exept.de>
parents:
2455
diff
changeset
|
1636 |
|
1454
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1637 |
requestor isNil ifTrue:[ |
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1638 |
"/ self showErrorMessage:aMessage position:position. |
4611 | 1639 |
^ false |
1454
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1640 |
]. |
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1641 |
|
2831 | 1642 |
warnAction := [ answer := requestor warning:aMessage position:position to:endPos from:self ]. |
1643 |
||
1457 | 1644 |
doNotShowAgainAction notNil ifTrue:[ |
4611 | 1645 |
realAction := warnAction. |
1646 |
warnAction := |
|
1647 |
[ |
|
1648 |
DoNotShowCompilerWarningAgainActionQuery |
|
1649 |
answer:doNotShowAgainAction |
|
1650 |
do:realAction |
|
1651 |
]. |
|
1454
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1652 |
]. |
2846
d7ddf430ff69
changed: #notifyWarning:doNotShowAgainAction:doNotShowAgainForThisMethodAction:position:to:
Claus Gittinger <cg@exept.de>
parents:
2833
diff
changeset
|
1653 |
(doNotShowAgainForThisMethodAction notNil and:[ self isDoIt not ]) ifTrue:[ |
4611 | 1654 |
real2Action := warnAction. |
1655 |
warnAction := |
|
1656 |
[ |
|
1657 |
DoNotShowCompilerWarningAgainForThisMethodActionQuery |
|
1658 |
answer:doNotShowAgainForThisMethodAction |
|
1659 |
do:real2Action |
|
1660 |
]. |
|
2831 | 1661 |
]. |
1662 |
||
1663 |
warnAction value. |
|
1454
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1664 |
^ answer |
2455
acdcc9b42d41
comment/format in: #notifyWarning:doNotShowAgainAction:position:to:
Claus Gittinger <cg@exept.de>
parents:
2452
diff
changeset
|
1665 |
|
2831 | 1666 |
"Created: / 28-02-2012 / 08:42:01 / cg" |
1667 |
! |
|
1668 |
||
1669 |
notifyWarning:aMessage doNotShowAgainAction:doNotShowAgainAction position:position to:endPos |
|
1670 |
"notify requestor of a warning - if there is no requestor, just ignore it. |
|
1671 |
Return the result passed back from the requestor (or false, if there is none)." |
|
1672 |
||
1673 |
^ self |
|
4611 | 1674 |
notifyWarning:aMessage |
1675 |
doNotShowAgainAction:doNotShowAgainAction |
|
1676 |
doNotShowAgainForThisMethodAction:nil |
|
1677 |
position:position to:endPos |
|
2831 | 1678 |
|
1679 |
"Modified: / 28-02-2012 / 08:44:45 / cg" |
|
1454
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1680 |
! |
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1681 |
|
0 | 1682 |
notifyWarning:aMessage position:position to:endPos |
1683 |
"notify requestor of an warning - if there is no requestor |
|
1684 |
put it on the transcript. |
|
1685 |
Return the result passed back by the requestor." |
|
1686 |
||
4188 | 1687 |
^ self |
4611 | 1688 |
notifyWarning:aMessage |
1689 |
doNotShowAgainAction:nil |
|
1690 |
position:position to:endPos. |
|
2831 | 1691 |
|
1692 |
"Modified (format): / 28-02-2012 / 08:44:13 / cg" |
|
0 | 1693 |
! |
1694 |
||
709 | 1695 |
parseError:aMessage |
1696 |
"report an error" |
|
1697 |
||
1698 |
^ self parseError:aMessage position:tokenPosition to:nil |
|
1699 |
||
1700 |
"Created: / 13.5.1998 / 16:45:13 / cg" |
|
1701 |
! |
|
1702 |
||
4562 | 1703 |
parseError:aMessage as:errorClassOrNil position:position to:endPos |
1704 |
"report an error" |
|
1705 |
||
1706 |
|fullMessage| |
|
1707 |
||
1708 |
Smalltalk isInitialized ifFalse:[ |
|
4611 | 1709 |
(self className,' [error]: error during initialization:') errorPrint. |
1710 |
aMessage errorPrintCR. |
|
1711 |
thisContext fullPrintAll. |
|
4562 | 1712 |
]. |
1713 |
||
1714 |
"/ fullMessage := (self errorMessagePrefix) , ' ' , (aMessage ? '???'). |
|
1715 |
fullMessage := (aMessage ? 'Unspecified error'). |
|
1716 |
self setErrorFlag. |
|
1717 |
self notifyError:fullMessage as:errorClassOrNil position:position to:endPos lineNr:nil. |
|
1718 |
exitBlock value. |
|
1719 |
^ false |
|
1720 |
||
1721 |
"Created: / 13-05-1998 / 16:44:55 / cg" |
|
1722 |
"Modified: / 22-08-2006 / 14:13:11 / cg" |
|
1723 |
"Modified: / 28-06-2019 / 09:11:48 / Claus Gittinger" |
|
1724 |
! |
|
1725 |
||
1900 | 1726 |
parseError:aMessage line:lNr |
1727 |
"report an error" |
|
1728 |
||
1729 |
|position| |
|
1730 |
||
1731 |
tokenLineNr := lNr. |
|
1948 | 1732 |
position := self positionFromLineNumber:lNr. |
1733 |
^ self parseError:aMessage position:position to:nil |
|
1734 |
||
1735 |
"Created: / 13-05-1998 / 16:45:05 / cg" |
|
1736 |
"Modified: / 16-11-2006 / 14:29:00 / cg" |
|
1900 | 1737 |
! |
1738 |
||
709 | 1739 |
parseError:aMessage position:position |
1740 |
"report an error" |
|
1741 |
||
1742 |
^ self parseError:aMessage position:position to:nil |
|
1743 |
||
1744 |
"Created: / 13.5.1998 / 16:45:05 / cg" |
|
1745 |
! |
|
1746 |
||
1747 |
parseError:aMessage position:position to:endPos |
|
1748 |
"report an error" |
|
1749 |
||
4562 | 1750 |
self parseError:aMessage as:nil position:position to:endPos |
709 | 1751 |
! |
1752 |
||
1948 | 1753 |
positionFromLineNumber:lNr |
1754 |
(requestor notNil and:[requestor isTextView]) ifTrue:[ |
|
4611 | 1755 |
^ requestor characterPositionOfLine:lNr col:1. |
1948 | 1756 |
]. |
1757 |
^ nil |
|
1758 |
||
1759 |
"Created: / 16-11-2006 / 14:28:37 / cg" |
|
1760 |
! |
|
1761 |
||
3449 | 1762 |
setErrorFlag |
1763 |
errorFlag := true. |
|
1764 |
! |
|
1765 |
||
141 | 1766 |
showErrorMessage:aMessage position:pos |
1767 |
"show an errormessage on the Transcript" |
|
0 | 1768 |
|
1976
d335a3fa358f
When writing error messages to Transcript, say who generated them
Stefan Vogel <sv@exept.de>
parents:
1972
diff
changeset
|
1769 |
(ignoreErrors or:[Smalltalk silentLoading]) ifFalse:[ |
4611 | 1770 |
Transcript showCR:('Scanner [<4p> line:<1p> off:<2p>]: <3p>' |
1771 |
expandMacrosWith:tokenLineNr |
|
1772 |
with:pos with:aMessage with:source). |
|
141 | 1773 |
] |
274 | 1774 |
|
4331 | 1775 |
"Modified: / 18-05-1996 / 15:44:35 / cg" |
1776 |
"Modified (format): / 08-02-2019 / 11:05:35 / Claus Gittinger" |
|
141 | 1777 |
! |
1778 |
||
1779 |
syntaxError:aMessage |
|
1780 |
"a syntax error happened - position is not known" |
|
1781 |
||
1782 |
^ self syntaxError:aMessage position:tokenPosition |
|
0 | 1783 |
! |
1784 |
||
1785 |
syntaxError:aMessage position:position |
|
1786 |
"a syntax error happened - only start position is known" |
|
1787 |
||
1788 |
^ self syntaxError:aMessage position:position to:nil |
|
1789 |
! |
|
1790 |
||
141 | 1791 |
syntaxError:aMessage position:position to:endPos |
2523
4fc32fe8edc7
changed: #syntaxError:position:to:
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
1792 |
"a syntax error happened. |
4fc32fe8edc7
changed: #syntaxError:position:to:
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
1793 |
Return true for correction, false if not" |
4fc32fe8edc7
changed: #syntaxError:position:to:
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
1794 |
|
4fc32fe8edc7
changed: #syntaxError:position:to:
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
1795 |
|fullMessage ret| |
1856
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1796 |
|
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1797 |
"/ fullMessage := self errorMessagePrefix , ' ' , aMessage. |
209089a85ed3
error messages shortened and cleanup
Claus Gittinger <cg@exept.de>
parents:
1781
diff
changeset
|
1798 |
fullMessage := aMessage. |
2523
4fc32fe8edc7
changed: #syntaxError:position:to:
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
1799 |
ret := self notifyError:fullMessage position:position to:endPos. |
4fc32fe8edc7
changed: #syntaxError:position:to:
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
1800 |
"/ exitBlock value. |
4fc32fe8edc7
changed: #syntaxError:position:to:
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
1801 |
"/ ^ false |
3449 | 1802 |
self setErrorFlag. |
2523
4fc32fe8edc7
changed: #syntaxError:position:to:
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
1803 |
^ ret. |
4fc32fe8edc7
changed: #syntaxError:position:to:
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
1804 |
|
4fc32fe8edc7
changed: #syntaxError:position:to:
Claus Gittinger <cg@exept.de>
parents:
2487
diff
changeset
|
1805 |
"Modified: / 30-06-2011 / 19:49:19 / cg" |
87 | 1806 |
! |
1807 |
||
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1808 |
warnCommonMistake:msg at:position |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1809 |
"warn about a common beginners mistake" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1810 |
|
311 | 1811 |
self warnCommonMistake:msg position:position to:position |
1812 |
||
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1813 |
"Modified: 23.5.1997 / 12:16:34 / cg" |
311 | 1814 |
! |
1815 |
||
1816 |
warnCommonMistake:msg position:pos1 to:pos2 |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1817 |
"warn about a common beginners mistake" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1818 |
|
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1819 |
ignoreWarnings ifFalse:[ |
4611 | 1820 |
parserFlags warnings ifTrue:[ |
1821 |
parserFlags warnCommonMistakes ifTrue:[ |
|
1822 |
self |
|
1823 |
warning:msg |
|
1824 |
position:pos1 to:pos2. |
|
1825 |
] |
|
1826 |
] |
|
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1827 |
] |
311 | 1828 |
|
1829 |
"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
|
1830 |
"Modified: 23.5.1997 / 12:16:39 / cg" |
310
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1831 |
! |
27ed956b591e
beginners common error warnings
Claus Gittinger <cg@exept.de>
parents:
288
diff
changeset
|
1832 |
|
608 | 1833 |
warnDollarAt:position |
1834 |
"warn about $-character in an identifier" |
|
1835 |
||
1836 |
ignoreWarnings ifFalse:[ |
|
4611 | 1837 |
didWarnAboutDollarInIdentifier ifFalse:[ |
1838 |
parserFlags warnDollarInIdentifier ifTrue:[ |
|
1839 |
self |
|
1840 |
warning:'$-characters in identifiers/symbols are nonportable' |
|
1841 |
doNotShowAgainAction:[ ParserFlags warnDollarInIdentifier:false ] |
|
1842 |
position:position to:position. |
|
1843 |
" |
|
1844 |
only warn once (per method) |
|
1845 |
" |
|
1846 |
didWarnAboutDollarInIdentifier := true |
|
1847 |
] |
|
1848 |
] |
|
608 | 1849 |
] |
1850 |
||
1851 |
"Created: 7.9.1997 / 01:50:24 / cg" |
|
1852 |
"Modified: 7.9.1997 / 01:51:13 / cg" |
|
1853 |
! |
|
1854 |
||
87 | 1855 |
warnOldStyleAssignmentAt:position |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1856 |
"warn about an oldStyle assignment" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1857 |
|
87 | 1858 |
ignoreWarnings ifFalse:[ |
4611 | 1859 |
didWarnAboutOldStyleAssignment ifFalse:[ |
1860 |
parserFlags warnOldStyleAssignment ifTrue:[ |
|
1861 |
self |
|
1862 |
warning:'Old style assignment - please change to use '':=''' |
|
1863 |
doNotShowAgainAction:[ ParserFlags warnOldStyleAssignment:false ] |
|
1864 |
position:position to:position. |
|
1865 |
]. |
|
1866 |
" |
|
1867 |
only warn once (per method) |
|
1868 |
" |
|
1869 |
didWarnAboutOldStyleAssignment := true |
|
1870 |
] |
|
87 | 1871 |
] |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1872 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1873 |
"Modified: 23.5.1997 / 12:16:48 / cg" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1874 |
! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1875 |
|
4042 | 1876 |
warnParagraphAt:position |
4610 | 1877 |
"warn about §-character in an identifier" |
4042 | 1878 |
|
1879 |
ignoreWarnings ifFalse:[ |
|
4611 | 1880 |
"/ didWarnAboutParagraphInIdentifier ifFalse:[ |
1881 |
parserFlags warnParagraphInIdentifier ifTrue:[ |
|
1882 |
self |
|
1883 |
warning:'§-characters in identifiers/symbols are nonportable' |
|
1884 |
doNotShowAgainAction:[ ParserFlags warnParagraphInIdentifier:false ] |
|
1885 |
position:position to:position. |
|
1886 |
" |
|
1887 |
only warn once (per method) |
|
1888 |
" |
|
1889 |
parserFlags := parserFlags copy. |
|
1890 |
parserFlags warnParagraphInIdentifier:false. |
|
1891 |
"/ didWarnAboutParagraphInIdentifier := true |
|
1892 |
] |
|
1893 |
"/ ] |
|
4042 | 1894 |
] |
1895 |
||
1896 |
"Created: / 17-11-2016 / 09:16:22 / cg" |
|
1897 |
! |
|
1898 |
||
2180
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
1899 |
warnPeriodAt:position |
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
1900 |
"warn about a period in an identifier" |
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
1901 |
|
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
1902 |
ignoreWarnings ifFalse:[ |
4611 | 1903 |
didWarnAboutPeriodInSymbol ifFalse:[ |
1904 |
parserFlags warnAboutPeriodInSymbol ifTrue:[ |
|
1905 |
self |
|
1906 |
warning:'Period in symbols are nonportable' |
|
1907 |
doNotShowAgainAction:[ ParserFlags warnAboutPeriodInSymbol:false ] |
|
1908 |
position:position to:position. |
|
1909 |
" |
|
1910 |
only warn once (per method) |
|
1911 |
" |
|
1912 |
didWarnAboutPeriodInSymbol := true |
|
1913 |
] |
|
1914 |
] |
|
2180
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
1915 |
] |
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
1916 |
! |
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
1917 |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1918 |
warnPossibleIncompatibility:msg position:pos1 to:pos2 |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1919 |
"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
|
1920 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1921 |
ignoreWarnings ifFalse:[ |
4611 | 1922 |
parserFlags warnPossibleIncompatibilities ifTrue:[ |
1923 |
self |
|
1924 |
warning:('Possible incompatibility.\\' , msg) withCRs |
|
1925 |
doNotShowAgainAction:[ ParserFlags warnPossibleIncompatibilities:false. |
|
1926 |
parserFlags warnPossibleIncompatibilities:false ] |
|
1927 |
position:pos1 to:pos2. |
|
1928 |
] |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1929 |
] |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1930 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1931 |
"Created: 23.5.1997 / 12:17:54 / cg" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1932 |
"Modified: 23.5.1997 / 12:22:37 / cg" |
87 | 1933 |
! |
1934 |
||
1653 | 1935 |
warnSTXSpecialCommentAt:position to:endPosition |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1936 |
ignoreWarnings ifFalse:[ |
4611 | 1937 |
"/ dfo |
1938 |
didWarnAboutSTXSpecialComment ifFalse:[ |
|
1939 |
parserFlags warnSTXSpecialComment ifTrue:[ |
|
1940 |
self |
|
1941 |
warning:'End-of-line comments are a nonstandard feature of ST/X' |
|
1942 |
doNotShowAgainAction:[ parserFlags warnSTXSpecialComment:false. ParserFlags warnSTXSpecials:false. ] |
|
1943 |
doNotShowAgainForThisMethodAction: [ self disableWarningsOnCurrentMethodFor: #warnSTXSpecials ] |
|
1944 |
position:position to:endPosition. |
|
1945 |
" |
|
1946 |
only warn once |
|
1947 |
" |
|
1948 |
didWarnAboutSTXSpecialComment := true |
|
1949 |
] |
|
1950 |
] |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1951 |
]. |
2831 | 1952 |
|
2854
64b0decefcec
changed: #warnSTXSpecialCommentAt:to:
Claus Gittinger <cg@exept.de>
parents:
2846
diff
changeset
|
1953 |
"Modified: / 16-03-2012 / 18:37:11 / cg" |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1954 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
1955 |
|
87 | 1956 |
warnUnderscoreAt:position |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1957 |
"warn about an underscore in an identifier" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1958 |
|
87 | 1959 |
ignoreWarnings ifFalse:[ |
4611 | 1960 |
didWarnAboutUnderscoreInIdentifier ifFalse:[ |
1961 |
parserFlags warnUnderscoreInIdentifier ifTrue:[ |
|
1962 |
self |
|
1963 |
warning:'Underscores in identifiers/symbols are nonportable' |
|
1964 |
doNotShowAgainAction:[ ParserFlags warnUnderscoreInIdentifier:false ] |
|
1965 |
position:position to:position. |
|
1966 |
" |
|
1967 |
only warn once (per method) |
|
1968 |
" |
|
1969 |
didWarnAboutUnderscoreInIdentifier := true |
|
1970 |
] |
|
1971 |
] |
|
87 | 1972 |
] |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1973 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
1974 |
"Modified: 23.5.1997 / 12:17:06 / cg" |
141 | 1975 |
! |
1976 |
||
1977 |
warning:aMessage |
|
1978 |
"a warning - position is not known" |
|
1979 |
||
1980 |
^ self warning:aMessage position:tokenPosition |
|
1981 |
! |
|
1982 |
||
2831 | 1983 |
warning:aMessage doNotShowAgainAction:doNotShowAgainAction doNotShowAgainForThisMethodAction:doNotShowAgainForThisMethodAction position:position to:endPos |
1454
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1984 |
"a warning" |
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
1985 |
|
4188 | 1986 |
^ self |
4611 | 1987 |
notifyWarning:((self warningMessagePrefix) , ' ' , aMessage) |
1988 |
doNotShowAgainAction:doNotShowAgainAction |
|
1989 |
doNotShowAgainForThisMethodAction:doNotShowAgainForThisMethodAction |
|
1990 |
position:position to:endPos |
|
2831 | 1991 |
|
1992 |
"Created: / 28-02-2012 / 08:38:16 / cg" |
|
1993 |
! |
|
1994 |
||
1995 |
warning:aMessage doNotShowAgainAction:doNotShowAgainAction position:position to:endPos |
|
1996 |
"a warning" |
|
1997 |
||
4188 | 1998 |
^ self |
4611 | 1999 |
warning:aMessage |
2000 |
doNotShowAgainAction:doNotShowAgainAction |
|
2001 |
doNotShowAgainForThisMethodAction:nil |
|
2002 |
position:position to:endPos |
|
2831 | 2003 |
|
2004 |
"Modified: / 28-02-2012 / 08:43:00 / cg" |
|
1454
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
2005 |
! |
d3c4be472930
support doNotSHowThisWarningDialogAgain
Claus Gittinger <cg@exept.de>
parents:
1434
diff
changeset
|
2006 |
|
1948 | 2007 |
warning:aMessage line:lNr |
2008 |
"a warning - only start position is known" |
|
2009 |
||
2010 |
|position| |
|
2011 |
||
2012 |
position := self positionFromLineNumber:lNr. |
|
2013 |
^ self warning:aMessage position:position to:nil |
|
2014 |
||
2015 |
"Created: / 16-11-2006 / 14:29:30 / cg" |
|
2016 |
! |
|
2017 |
||
141 | 2018 |
warning:aMessage position:position |
2019 |
"a warning - only start position is known" |
|
2020 |
||
2021 |
^ self warning:aMessage position:position to:nil |
|
2022 |
! |
|
2023 |
||
2024 |
warning:aMessage position:position to:endPos |
|
2025 |
"a warning" |
|
2026 |
||
4188 | 2027 |
^ self |
4611 | 2028 |
notifyWarning:((self warningMessagePrefix) , ' ' , aMessage) |
2029 |
doNotShowAgainAction:nil |
|
2030 |
position:position to:endPos |
|
1073 | 2031 |
! |
2032 |
||
2033 |
warningMessagePrefix |
|
2034 |
^ 'Warning:' |
|
0 | 2035 |
! ! |
2036 |
||
17 | 2037 |
!Scanner methodsFor:'general scanning'! |
2038 |
||
737
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
2039 |
scanNumberFrom:aStringOrStream |
3143 | 2040 |
"scan aSourceString for the next number in smalltalk syntax. |
3144 | 2041 |
Return the number or nil. Leave the position of the stream after the number |
3143 | 2042 |
or unchanged (if no number is coming) |
4188 | 2043 |
Extension: |
4611 | 2044 |
since constant fractions (int/int) are treated like lexical tokens (not messages) |
2045 |
in Smalltalk/X, this also reads fractions." |
|
3143 | 2046 |
|
3144 | 2047 |
|oldPos posAfter denominator numerator parentized sign| |
737
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
2048 |
|
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
2049 |
self initializeFor:aStringOrStream. |
1430 | 2050 |
oldPos := source position. |
737
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
2051 |
self nextToken. |
3144 | 2052 |
|
2053 |
sign := 1. |
|
2054 |
tokenType == #BinaryOperator ifTrue:[ |
|
4611 | 2055 |
tokenName = '+' ifTrue:[ |
2056 |
self nextToken. |
|
2057 |
] ifFalse:[ |
|
2058 |
tokenName = '-' ifTrue:[ |
|
2059 |
sign := -1. |
|
2060 |
self nextToken. |
|
2061 |
]. |
|
2062 |
]. |
|
3144 | 2063 |
]. |
2064 |
(parentized := tokenType == $( ) ifTrue:[ |
|
4611 | 2065 |
self nextToken. |
2066 |
tokenType == #BinaryOperator ifTrue:[ |
|
2067 |
tokenName = '+' ifTrue:[ |
|
2068 |
self nextToken. |
|
2069 |
] ifFalse:[ |
|
2070 |
tokenName = '-' ifTrue:[ |
|
2071 |
sign := sign negated. |
|
2072 |
self nextToken. |
|
2073 |
]. |
|
2074 |
]. |
|
2075 |
]. |
|
3144 | 2076 |
]. |
2077 |
||
3143 | 2078 |
(tokenValue isNumber) ifTrue:[ |
4611 | 2079 |
"/ must keep stream positioned correctly |
2080 |
"/ (undo lookahead) |
|
2081 |
posAfter := source position. |
|
2082 |
peekChar notNil ifTrue:[ |
|
2083 |
peekChar2 notNil ifTrue:[ |
|
2084 |
posAfter := posAfter - 1 |
|
2085 |
]. |
|
2086 |
posAfter := posAfter - 1 |
|
2087 |
]. |
|
2088 |
tokenValue isInteger ifTrue:[ |
|
2089 |
source skipSeparators == $/ ifTrue:[ |
|
2090 |
numerator := tokenValue. |
|
2091 |
self nextToken. "/ skip / |
|
2092 |
"/ oops - must check for // |
|
2093 |
tokenName = '/' ifFalse:[ |
|
2094 |
parentized ifTrue:[ |
|
2095 |
"/ nothing at all |
|
2096 |
source position:oldPos. |
|
2097 |
^ nil. |
|
2098 |
]. |
|
2099 |
"/ only an integer |
|
2100 |
source position:posAfter. |
|
2101 |
^ tokenValue |
|
2102 |
]. |
|
2103 |
||
2104 |
self nextToken. "/ get denominator |
|
2105 |
tokenType == #BinaryOperator ifTrue:[ |
|
2106 |
tokenName = '+' ifTrue:[ |
|
2107 |
self nextToken. |
|
2108 |
] ifFalse:[ |
|
2109 |
tokenName = '-' ifTrue:[ |
|
2110 |
sign := sign negated. |
|
2111 |
self nextToken. |
|
2112 |
]. |
|
2113 |
]. |
|
2114 |
]. |
|
2115 |
(tokenType == #Integer and:[tokenValue isInteger]) ifTrue:[ |
|
2116 |
denominator := tokenValue. |
|
2117 |
tokenValue := Fraction numerator:numerator denominator:denominator. |
|
2118 |
posAfter := source position. |
|
2119 |
peekChar notNil ifTrue:[ |
|
2120 |
peekChar2 notNil ifTrue:[ |
|
2121 |
posAfter := posAfter - 1 |
|
2122 |
]. |
|
2123 |
posAfter := posAfter - 1 |
|
2124 |
]. |
|
2125 |
]. |
|
2126 |
]. |
|
2127 |
]. |
|
2128 |
parentized ifTrue:[ |
|
2129 |
tokenType == $) ifTrue:[ |
|
2130 |
self nextToken |
|
2131 |
] |
|
2132 |
] ifFalse:[ |
|
2133 |
source position:posAfter. |
|
2134 |
]. |
|
2135 |
sign == -1 ifTrue:[^ tokenValue negated]. |
|
2136 |
^ tokenValue |
|
737
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
2137 |
]. |
996
53dbf13d1aa0
keep stream positioned correctly after scanNumberFrom:
Claus Gittinger <cg@exept.de>
parents:
983
diff
changeset
|
2138 |
"/ backup in case of error; return nil |
1430 | 2139 |
source position:oldPos. |
737
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
2140 |
^ nil. |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
2141 |
|
4415 | 2142 |
"Created: / 18-06-1998 / 23:05:22 / cg" |
2143 |
"Modified: / 19-11-1999 / 18:25:52 / cg" |
|
2144 |
"Modified (comment): / 23-05-2019 / 11:06:51 / Claus Gittinger" |
|
4572 | 2145 |
"Modified: / 28-09-2019 / 15:21:32 / Stefan Vogel" |
737
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
2146 |
! |
4062aa740959
support for readSmalltalkSyntax
Claus Gittinger <cg@exept.de>
parents:
717
diff
changeset
|
2147 |
|
17 | 2148 |
scanPositionsFor:aTokenString inString:aSourceString |
3712 | 2149 |
"scan aSourceString for occurrences of aTokenString. |
17 | 2150 |
Return a collection of start positions. |
1577 | 2151 |
Added for VW compatibility (to support simple syntax-highlight)." |
17 | 2152 |
|
2153 |
|searchType searchName searchValue positions t| |
|
2154 |
||
1577 | 2155 |
aTokenString notNil ifTrue:[ |
4611 | 2156 |
" |
2157 |
first, look what kind of token we have to search for |
|
2158 |
" |
|
2159 |
self initializeFor:(ReadStream on:aTokenString). |
|
2160 |
self nextToken. |
|
2161 |
searchType := tokenType. |
|
2162 |
searchName := tokenName. |
|
2163 |
searchValue := tokenValue. |
|
1577 | 2164 |
]. |
17 | 2165 |
|
2166 |
" |
|
2167 |
start the real work ... |
|
2168 |
" |
|
2169 |
self initializeFor:(ReadStream on:aSourceString). |
|
2170 |
positions := OrderedCollection new. |
|
2171 |
||
2172 |
[(t := self nextToken) ~~ #EOF] whileTrue:[ |
|
4611 | 2173 |
searchType == t ifTrue:[ |
2174 |
(searchName isNil or:[tokenName = searchName]) ifTrue:[ |
|
2175 |
(searchValue isNil or:[tokenValue = searchValue]) ifTrue:[ |
|
2176 |
positions add:tokenPosition. |
|
2177 |
] |
|
2178 |
] |
|
2179 |
] |
|
17 | 2180 |
]. |
2181 |
||
2182 |
^ positions |
|
2183 |
||
2184 |
" |
|
4188 | 2185 |
Scanner new scanPositionsFor:'hello' inString:'foo bar hello baz hello' |
2186 |
Scanner new scanPositionsFor:'3.14' inString:'foo 3.145 bar hello 3.14 baz hello 3.14' |
|
2187 |
Scanner new scanPositionsFor:'16' inString:'foo 16 bar hello 16r10 baz hello 2r10000' |
|
17 | 2188 |
" |
2189 |
! ! |
|
2190 |
||
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2191 |
!Scanner methodsFor:'initialization'! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2192 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2193 |
initialize |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2194 |
"initialize the scanner" |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2195 |
|
4121 | 2196 |
"/ <modifier: #super> "must be called if redefined" |
4112 | 2197 |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2198 |
errorFlag := false. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2199 |
tokenPosition := 1. |
610 | 2200 |
tokenLineNr := lineNr := 1. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2201 |
currentComments := nil. |
2740 | 2202 |
"/ allow for these to be already set (kludge) |
2203 |
saveComments isNil ifTrue:[ saveComments := false ]. |
|
2204 |
parserFlags isNil ifTrue:[ parserFlags := ParserFlags new ]. |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2205 |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2206 |
ignoreErrors := false. |
1930 | 2207 |
ignoreWarnings := parserFlags warnings not. |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2208 |
didWarnAboutSTXSpecialComment := false. |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2209 |
didWarnAboutUnderscoreInIdentifier := false. |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2210 |
didWarnAboutDollarInIdentifier := false. |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2211 |
didWarnAboutOldStyleAssignment := false. |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2212 |
|
900 | 2213 |
"/ not used here, but eases subclassing for other languages. |
4188 | 2214 |
scanColonAsKeyword isNil ifTrue:[ scanColonAsKeyword := true ]. |
1930 | 2215 |
self initializeActionTable. |
2216 |
||
4121 | 2217 |
"Modified: / 13-02-2017 / 13:45:51 / cg" |
1930 | 2218 |
! |
2219 |
||
2220 |
initializeActionTable |
|
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
2221 |
actionArray := self class actionArray. |
2484 | 2222 |
unicodeActions := self class unicodeActions. |
2140
f9b4ef3e9368
type- and actionArray are now class-instance variables
Claus Gittinger <cg@exept.de>
parents:
2139
diff
changeset
|
2223 |
typeArray := self class typeArray. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2224 |
|
1930 | 2225 |
"Created: / 18-10-2006 / 23:10:55 / cg" |
2484 | 2226 |
"Modified: / 25-03-2011 / 13:57:50 / cg" |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2227 |
! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2228 |
|
1362 | 2229 |
initializeFlagsFrom:aScanner |
2230 |
"initialize flags from another scanner" |
|
2231 |
||
2232 |
ignoreErrors := aScanner ignoreErrors. |
|
2233 |
ignoreWarnings := aScanner ignoreWarnings. |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2234 |
parserFlags := aScanner parserFlags copy. |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2235 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2236 |
"/ not used here, but eases subclassing for other languages. |
4188 | 2237 |
scanColonAsKeyword := aScanner scanColonAsKeyword. |
1362 | 2238 |
! |
2239 |
||
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2240 |
initializeFor:aStringOrStream |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2241 |
"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
|
2242 |
|
2741 | 2243 |
actionArray isNil ifTrue:[ |
4611 | 2244 |
"/ if not already initialized... |
2245 |
self initialize. |
|
2741 | 2246 |
]. |
847 | 2247 |
self source:aStringOrStream. |
2741 | 2248 |
|
2249 |
"Modified: / 05-10-2011 / 09:24:00 / cg" |
|
847 | 2250 |
! |
2251 |
||
1962 | 2252 |
requestor:anObject |
2253 |
"set the requestor to be notified" |
|
2254 |
||
2255 |
requestor := anObject |
|
2256 |
||
2257 |
"Created: / 07-12-2006 / 18:13:13 / cg" |
|
2258 |
! |
|
2259 |
||
4420 | 2260 |
setSource:newSourceStream |
2261 |
source := newSourceStream |
|
1242 | 2262 |
|
4291 | 2263 |
"Modified: / 07-08-2018 / 07:46:57 / Claus Gittinger" |
4420 | 2264 |
"Modified (format): / 25-05-2019 / 23:47:16 / Claus Gittinger" |
1242 | 2265 |
! |
2266 |
||
847 | 2267 |
source:aStringOrStream |
2766 | 2268 |
"prepare for reading from aStringOrStream; |
2269 |
notice: if token is nonNil, it is preserved. This allows for scanning |
|
2270 |
across streams." |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2271 |
|
854 | 2272 |
errorFlag := false. |
2273 |
tokenPosition := 1. |
|
2274 |
tokenLineNr := lineNr := 1. |
|
2275 |
currentComments := nil. |
|
2276 |
||
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2277 |
aStringOrStream isStream ifFalse:[ |
4611 | 2278 |
source := ReadStream on:aStringOrStream string |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2279 |
] ifTrue:[ |
4611 | 2280 |
source := aStringOrStream. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2281 |
]. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2282 |
|
2762 | 2283 |
"Modified: / 26-05-1999 / 12:02:16 / stefan" |
2766 | 2284 |
"Modified: / 06-12-2011 / 00:45:50 / cg" |
4341 | 2285 |
"Modified: / 10-02-2019 / 15:49:28 / Claus Gittinger" |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2286 |
! ! |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
2287 |
|
1237
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2288 |
!Scanner methodsFor:'parser interface'! |
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2289 |
|
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2290 |
token |
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2291 |
^ token |
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2292 |
! |
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2293 |
|
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2294 |
tokenLineNr:lineNumberArg |
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2295 |
tokenLineNr := lineNumberArg |
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2296 |
! |
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2297 |
|
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2298 |
tokenPosition:positionArg |
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2299 |
tokenPosition := positionArg |
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2300 |
! ! |
4c8cd98c5778
more refactorings for easier subclassing
Claus Gittinger <cg@exept.de>
parents:
1236
diff
changeset
|
2301 |
|
141 | 2302 |
!Scanner methodsFor:'private'! |
3 | 2303 |
|
141 | 2304 |
backupPosition |
2305 |
"if reading from a stream, at the end we might have read |
|
2306 |
one token too many" |
|
20 | 2307 |
|
141 | 2308 |
(tokenType == #EOF) ifFalse:[ |
4611 | 2309 |
source position:tokenPosition-1 |
141 | 2310 |
] |
2311 |
! |
|
15 | 2312 |
|
141 | 2313 |
beginComment |
2314 |
^ self |
|
2315 |
! |
|
2316 |
||
4334 | 2317 |
characterNamed:name |
2318 |
|idx| |
|
2319 |
||
2320 |
idx := #( |
|
4611 | 2321 |
'nul' 'soh' 'stx' 'etx' 'eot' 'enq' 'ack' 'bel' |
2322 |
'bs' 'ht' 'lf' 'vt' 'ff' 'cr' 'so' 'si' |
|
2323 |
'dle' 'dc1' 'dc2' 'dc3' 'dc4' 'nak' 'syn' 'etb' |
|
2324 |
'can' 'em' 'sub' 'esc' 'fs' 'gs' 'rs' 'us' ) indexOf:name. |
|
4334 | 2325 |
idx == 0 ifTrue:[ |
4611 | 2326 |
name = 'tab' ifTrue:[ ^ Character tab ]. |
2327 |
^ nil |
|
4334 | 2328 |
]. |
2329 |
^ Character value:idx-1 |
|
2330 |
||
2331 |
"Created: / 08-02-2019 / 19:12:23 / Claus Gittinger" |
|
2332 |
! |
|
2333 |
||
707
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2334 |
checkForKeyword:string |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2335 |
"check if string is a keyword (as opposed to an identifier). |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2336 |
That is, its one of 'self', 'super', 'nil', 'true', 'false', |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2337 |
or 'thisContext'. |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2338 |
'here' is handled elsewhere (since it must be treated as an |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2339 |
identifier, if declared locally." |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2340 |
|
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2341 |
|firstChar| |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2342 |
|
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2343 |
firstChar := string at:1. |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2344 |
(firstChar == $s) ifTrue:[ |
4611 | 2345 |
(string = 'self') ifTrue:[tokenType := #Self. ^true]. |
2346 |
(string = 'super') ifTrue:[tokenType := #Super. ^true] |
|
707
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2347 |
]. |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2348 |
(firstChar == $n) ifTrue:[ |
4611 | 2349 |
(string = 'nil') ifTrue:[tokenType := #Nil. tokenValue := nil. ^true] |
707
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2350 |
]. |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2351 |
(firstChar == $t) ifTrue:[ |
4611 | 2352 |
(string = 'true') ifTrue:[tokenType := #True. tokenValue := true. ^true]. |
2353 |
(string = 'thisContext') ifTrue:[tokenType := #ThisContext. ^true] |
|
707
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2354 |
]. |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2355 |
(firstChar == $f) ifTrue:[ |
4611 | 2356 |
(string = 'false') ifTrue:[tokenType := #False. tokenValue := false. ^true] |
707
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2357 |
]. |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2358 |
^ false |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2359 |
|
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2360 |
"Modified: / 13.5.1998 / 14:59:55 / cg" |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2361 |
! |
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2362 |
|
141 | 2363 |
collectedSource |
2364 |
^ collectedSource |
|
2365 |
! |
|
74 | 2366 |
|
1236 | 2367 |
eatPeekChar |
2368 |
peekChar isNil ifTrue:[ |
|
4611 | 2369 |
source next. |
1236 | 2370 |
] ifFalse:[ |
4611 | 2371 |
peekChar := nil. |
1236 | 2372 |
]. |
2373 |
||
2374 |
"Created: / 24.10.1998 / 17:25:39 / cg" |
|
2375 |
! |
|
2376 |
||
141 | 2377 |
endComment:comment |
2378 |
saveComments ifTrue:[ |
|
4611 | 2379 |
currentComments isNil ifTrue:[ |
2380 |
currentComments := OrderedCollection with:comment |
|
2381 |
] ifFalse:[ |
|
2382 |
currentComments add:comment |
|
2383 |
] |
|
3 | 2384 |
]. |
2385 |
! |
|
2386 |
||
648 | 2387 |
endComment:commentString type:commentType |
3551 | 2388 |
"obsolete; left for backward compatibility" |
2389 |
||
2390 |
^ self endComment:commentString type:commentType start:nil end:nil |
|
2391 |
! |
|
2392 |
||
2393 |
endComment:commentString type:commentType start:startPos end:endPos |
|
648 | 2394 |
|comment| |
2395 |
||
2396 |
saveComments ifTrue:[ |
|
4611 | 2397 |
comment := Comment new commentString:commentString commentType:commentType. |
2398 |
comment startPosition:startPos endPosition:endPos. |
|
2399 |
||
2400 |
currentComments isNil ifTrue:[ |
|
2401 |
currentComments := OrderedCollection with:comment |
|
2402 |
] ifFalse:[ |
|
2403 |
currentComments add:comment |
|
2404 |
] |
|
648 | 2405 |
]. |
2406 |
||
2407 |
"Created: / 17.2.1998 / 14:48:49 / cg" |
|
2408 |
! |
|
2409 |
||
2481 | 2410 |
eolIsWhiteSpace |
2411 |
^ true |
|
2412 |
||
2413 |
"Created: / 14-03-2011 / 14:11:46 / cg" |
|
2414 |
! |
|
2415 |
||
4345 | 2416 |
escapeCharacterFor:aCharacter escapeStyle:escapeStyle |
4414 | 2417 |
"only if AllowExtendedSTXSyntax or AllowCStrings |
2418 |
or AllowEStrings is true |
|
4345 | 2419 |
For now: only use c-style, since stc does not support others. |
4611 | 2420 |
'c' - C-style escapes: |
2421 |
\n,\t,\r,\b,\xXX,\uXXXX,\UXXXXXX, |
|
1321 | 2422 |
|
2423 |
much like character escapes in C-literals; |
|
2424 |
expands: |
|
4611 | 2425 |
\n newLine |
2426 |
\r return |
|
2427 |
\t tab |
|
2428 |
\b backspace |
|
2429 |
\f formfeed |
|
2430 |
\g bell |
|
2431 |
\0 nul |
|
2432 |
||
2433 |
\\ backSlash |
|
2434 |
\ ...\ (backslash-separator) ignored up to next backslash |
|
2435 |
\xNN hexCharacter |
|
2436 |
\uNNNN hex UnicodeCharacter |
|
2437 |
\UNNNNNN hex UnicodeCharacter |
|
2438 |
\<name> named character |
|
1321 | 2439 |
" |
2440 |
||
4334 | 2441 |
|ascii nextChar fetchNext name pos1| |
1321 | 2442 |
|
2443 |
aCharacter == $n ifTrue:[^ Character nl]. |
|
2444 |
aCharacter == $r ifTrue:[^ Character return]. |
|
2445 |
aCharacter == $t ifTrue:[^ Character tab]. |
|
2446 |
aCharacter == $b ifTrue:[^ Character backspace]. |
|
2447 |
aCharacter == $f ifTrue:[^ Character ff]. |
|
2448 |
aCharacter == $g ifTrue:[^ Character bell]. |
|
4334 | 2449 |
aCharacter == $0 ifTrue:[^ Character null]. |
1681 | 2450 |
aCharacter == $\ ifTrue:[^ aCharacter]. |
4345 | 2451 |
|
4334 | 2452 |
aCharacter == $< ifTrue:[ |
4611 | 2453 |
pos1 := source position. |
2454 |
name := ''. |
|
2455 |
nextChar := source next. |
|
2456 |
[nextChar notNil and:[nextChar ~~ $>]] whileTrue:[ |
|
2457 |
nextChar isLetter ifFalse:[ |
|
2458 |
self syntaxError:'letter expected in character name escape in string literal' |
|
2459 |
position:pos1 to:(source position). |
|
2460 |
]. |
|
2461 |
name size > 10 ifTrue:[ |
|
2462 |
self syntaxError:'long character name escape in string literal' |
|
2463 |
position:pos1 to:(source position). |
|
2464 |
]. |
|
2465 |
name := name , nextChar. |
|
2466 |
nextChar := source next. |
|
2467 |
]. |
|
2468 |
nextChar := self characterNamed:name. |
|
2469 |
nextChar isNil ifTrue:[ |
|
2470 |
self syntaxError:'invalid character name escape in string literal' |
|
2471 |
position:pos1 to:(source position). |
|
2472 |
]. |
|
2473 |
^ nextChar |
|
1321 | 2474 |
]. |
4611 | 2475 |
|
4334 | 2476 |
aCharacter isSeparator ifTrue:[ |
4611 | 2477 |
nextChar := source next. |
2478 |
[nextChar notNil and:[nextChar ~~ $\]] whileTrue:[ |
|
2479 |
(nextChar == Character cr) ifTrue:[ |
|
2480 |
lineNr := lineNr + 1 |
|
2481 |
]. |
|
2482 |
nextChar := source next. |
|
2483 |
]. |
|
2484 |
^ nil |
|
4334 | 2485 |
]. |
2486 |
||
4611 | 2487 |
(aCharacter == $x |
4414 | 2488 |
or:[ (aCharacter == $u) |
2489 |
or:[ (aCharacter == $U) ]] |
|
2490 |
) ifTrue:[ |
|
4611 | 2491 |
pos1 := source position. |
2492 |
||
2493 |
fetchNext := |
|
2494 |
[ |
|
2495 |
nextChar := source next. |
|
2496 |
(nextChar notNil and:[nextChar isDigitRadix:16]) ifFalse:[ |
|
2497 |
self syntaxError:'hex digit expected in string literal' |
|
2498 |
position:pos1 to:(source position). |
|
2499 |
0 |
|
2500 |
] ifTrue:[ |
|
2501 |
nextChar digitValue |
|
2502 |
]. |
|
2503 |
]. |
|
2504 |
||
2505 |
ascii := fetchNext value. |
|
2506 |
ascii := (ascii bitShift:4) bitOr:(fetchNext value). |
|
2507 |
||
2508 |
((aCharacter == $u ) or:[(aCharacter == $U )]) ifTrue:[ |
|
2509 |
ascii := (ascii bitShift:4) bitOr:(fetchNext value). |
|
2510 |
ascii := (ascii bitShift:4) bitOr:(fetchNext value). |
|
2511 |
(aCharacter == $U) ifTrue:[ |
|
2512 |
ascii := (ascii bitShift:4) bitOr:(fetchNext value). |
|
2513 |
ascii := (ascii bitShift:4) bitOr:(fetchNext value). |
|
2514 |
]. |
|
2515 |
]. |
|
2516 |
^ Character value:ascii. |
|
1321 | 2517 |
]. |
2518 |
^ aCharacter |
|
2519 |
||
2520 |
" |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2521 |
ParserFlags allowExtendedSTXSyntax:true |
1321 | 2522 |
" |
2523 |
" |
|
4188 | 2524 |
'hello\nworld' |
2525 |
'hello\x0Dworld' |
|
2526 |
'hello\x08world' |
|
1681 | 2527 |
'hello\ |
4188 | 2528 |
\world' |
2529 |
" |
|
1681 | 2530 |
" |
2531 |
ParserFlags allowExtendedSTXSyntax:false |
|
2532 |
" |
|
4334 | 2533 |
|
4345 | 2534 |
"Created: / 11-02-2019 / 12:27:25 / Claus Gittinger" |
4460 | 2535 |
"Modified: / 21-07-2019 / 08:20:08 / Claus Gittinger" |
1321 | 2536 |
! |
2537 |
||
141 | 2538 |
ignoreErrors |
1365 | 2539 |
"return the flag which controls notification of errors" |
2540 |
||
2541 |
^ ignoreErrors |
|
2542 |
! |
|
2543 |
||
2544 |
ignoreErrors:aBoolean |
|
2545 |
"enable/disable notification of errors" |
|
2546 |
||
2547 |
ignoreErrors := aBoolean |
|
141 | 2548 |
! |
0 | 2549 |
|
141 | 2550 |
ignoreWarnings |
1365 | 2551 |
"return the flag which controls notification of warnings" |
2552 |
||
2553 |
^ ignoreWarnings |
|
2554 |
! |
|
2555 |
||
2556 |
ignoreWarnings:aBoolean |
|
2557 |
"enable/disable notification of warnings" |
|
2558 |
||
2559 |
ignoreWarnings := aBoolean |
|
141 | 2560 |
! |
0 | 2561 |
|
714 | 2562 |
isCommentCharacter:ch |
2563 |
"return true, if ch is the comment-start character. |
|
2564 |
Brought into a separate method to allow for easier subclassing" |
|
2565 |
||
2566 |
^ ch == $" |
|
2567 |
||
2568 |
"Created: / 14.5.1998 / 20:51:42 / cg" |
|
2569 |
"Modified: / 14.5.1998 / 20:53:01 / cg" |
|
2570 |
! |
|
2571 |
||
2983 | 2572 |
isDoIt |
2573 |
^ false |
|
2574 |
! |
|
2575 |
||
1722 | 2576 |
isSpecialOrExtendedSpecialCharacter:ch |
2027 | 2577 |
|code charType| |
2578 |
||
2579 |
code := ch codePoint. |
|
3621 | 2580 |
(code between:1 and: typeArray size) ifFalse:[^ false]. |
2027 | 2581 |
|
2582 |
charType := typeArray at:code. |
|
4188 | 2583 |
^ (charType == #special) |
2584 |
or:[ (charType == #extendedSpecial) and:[parserFlags allowExtendedBinarySelectors] ] |
|
2290 | 2585 |
|
2586 |
" |
|
2587 |
self basicNew isSpecialOrExtendedSpecialCharacter:$- |
|
2588 |
" |
|
1722 | 2589 |
! |
2590 |
||
141 | 2591 |
notifying:anObject |
2592 |
"set the requestor to be notified" |
|
2593 |
||
2594 |
requestor := anObject |
|
426
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
2595 |
! |
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
2596 |
|
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
2597 |
setNameSpace:aNameSpace |
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
2598 |
"/ ignored here |
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
2599 |
|
871231a532fc
remember nameSpace as scanned from directive
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
2600 |
"Created: 8.11.1996 / 13:33:10 / cg" |
1247
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
2601 |
! |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
2602 |
|
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
2603 |
setPackage:aNameSpace |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
2604 |
"/ ignored here |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
2605 |
|
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
2606 |
"Created: 8.11.1996 / 13:33:10 / cg" |
1572 | 2607 |
! |
2608 |
||
2609 |
setSyntax:aSyntax |
|
141 | 2610 |
! ! |
2611 |
||
2612 |
!Scanner methodsFor:'reading next token'! |
|
2613 |
||
4410 | 2614 |
continueEscapedString |
2615 |
"after escaping out of a string with \{, |
|
2616 |
an expression was read by the parser and it found the terminating $}. |
|
2617 |
It calls this to continue reading the string..." |
|
2618 |
||
2619 |
^ self xnextString:$' escapeStyle:'e' |
|
2620 |
||
2621 |
"Created: / 22-05-2019 / 20:24:51 / Claus Gittinger" |
|
2622 |
! |
|
2623 |
||
2484 | 2624 |
nextAssignmentArrow |
2625 |
"return a left-arrow" |
|
2626 |
||
2627 |
^ self nextToken:$_ |
|
2628 |
||
2629 |
"Created: / 25-03-2011 / 13:58:50 / cg" |
|
2630 |
! |
|
2631 |
||
4291 | 2632 |
nextBacktickIdentifier |
4611 | 2633 |
"a single back-quote has been scanned; |
4291 | 2634 |
scan up to the next back-tick, and return it as an identifier" |
2635 |
||
2636 |
self nextString:$`. |
|
2637 |
||
2638 |
tokenName := tokenValue. |
|
2639 |
tokenType := #Identifier. |
|
2640 |
^ tokenType |
|
2641 |
||
2642 |
"Created: / 07-08-2018 / 07:37:51 / Claus Gittinger" |
|
2643 |
! |
|
2644 |
||
141 | 2645 |
nextCharacter |
2646 |
"a $ has been read - return a character token" |
|
2647 |
||
1240 | 2648 |
|nextChar t| |
141 | 2649 |
|
0 | 2650 |
source next. |
141 | 2651 |
nextChar := source next. |
2652 |
nextChar notNil ifTrue:[ |
|
4611 | 2653 |
t := nextChar. |
2654 |
tokenType := #Character. |
|
141 | 2655 |
] ifFalse:[ |
4611 | 2656 |
t := nil. |
2657 |
tokenType := #EOF |
|
141 | 2658 |
]. |
1240 | 2659 |
tokenValue := token := t. |
0 | 2660 |
^ tokenType |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
2661 |
|
707
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2662 |
"Modified: / 13.5.1998 / 15:09:50 / cg" |
0 | 2663 |
! |
2664 |
||
2665 |
nextColonOrAssign |
|
2666 |
"colon has been read - look for = to make it an assign" |
|
2667 |
||
3181 | 2668 |
|thirdChar| |
1722 | 2669 |
|
120 | 2670 |
"/ special kludge for identifier:= (without spaces inbetween) |
2671 |
"/ here we needed two characters lookahead after the identifier ... |
|
2672 |
||
2673 |
peekChar == $= ifTrue:[ |
|
4611 | 2674 |
source next. |
2675 |
peekChar := nil. |
|
2676 |
tokenType := token := #':='. |
|
2677 |
||
2678 |
thirdChar := source peek. |
|
2679 |
thirdChar notNil ifTrue:[ |
|
2680 |
(self isSpecialOrExtendedSpecialCharacter:thirdChar) ifTrue:[ |
|
2681 |
||
2682 |
] |
|
2683 |
]. |
|
2684 |
||
2685 |
^ tokenType |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
2686 |
]. |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
2687 |
|
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
2688 |
"/ special kludge for nameSpace:: (without spaces inbetween) |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
2689 |
"/ here we needed two characters lookahead after the identifier ... |
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
2690 |
|
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
2691 |
peekChar == $: ifTrue:[ |
4611 | 2692 |
source next. |
2693 |
peekChar := nil. |
|
2694 |
tokenType := token := #'::'. |
|
2695 |
^ tokenType |
|
120 | 2696 |
]. |
2697 |
||
0 | 2698 |
(source nextPeek == $=) ifTrue:[ |
4611 | 2699 |
source next. |
2700 |
tokenType := token := #':=' |
|
0 | 2701 |
] ifFalse:[ |
4611 | 2702 |
tokenType := token := $: |
0 | 2703 |
]. |
2704 |
^ tokenType |
|
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
2705 |
|
707
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2706 |
"Modified: / 13.5.1998 / 15:10:04 / cg" |
0 | 2707 |
! |
2708 |
||
1298 | 2709 |
nextExcla |
2710 |
"a !! has been read - return either |
|
4611 | 2711 |
the !! binarySelector, |
2712 |
ExclaLeftParen (for '!!('), |
|
2713 |
ExclaLeftBrack (for '!!['), |
|
2714 |
ExclaLeftBrace (for '!!{') |
|
1298 | 2715 |
" |
2716 |
||
2717 |
|nextChar| |
|
2718 |
||
2719 |
nextChar := source nextPeek. |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2720 |
parserFlags allowExtendedSTXSyntax == true ifTrue:[ |
4611 | 2721 |
(nextChar == $( ) ifTrue:[ |
2722 |
source next. |
|
2723 |
token := '!!('. |
|
2724 |
tokenType := #ExclaLeftParen. |
|
2725 |
^ tokenType |
|
2726 |
]. |
|
2727 |
||
2728 |
(nextChar == $[ ) ifTrue:[ |
|
2729 |
source next. |
|
2730 |
token := '!!['. |
|
2731 |
tokenType := #ExclaLeftBrack. |
|
2732 |
^ tokenType |
|
2733 |
]. |
|
2734 |
||
2735 |
(nextChar == ${ ) ifTrue:[ |
|
2736 |
source next. |
|
2737 |
token := '!!{'. |
|
2738 |
tokenType := #ExclaLeftBrace. |
|
2739 |
^ tokenType |
|
2740 |
]. |
|
1298 | 2741 |
]. |
2742 |
||
2743 |
"this allows excla to be used as binop - |
|
4037 | 2744 |
I don't know, if this is correct ..." |
1298 | 2745 |
|
1307
a91664d148ad
also allow multi-character binary selectors starting with excla
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
2746 |
"/ tokenName := token := '!!'. |
a91664d148ad
also allow multi-character binary selectors starting with excla
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
2747 |
"/ tokenType := #BinaryOperator. |
a91664d148ad
also allow multi-character binary selectors starting with excla
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
2748 |
"/ ^ tokenType |
a91664d148ad
also allow multi-character binary selectors starting with excla
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
2749 |
|
a91664d148ad
also allow multi-character binary selectors starting with excla
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
2750 |
^ self nextSpecialWith:$!!. |
1298 | 2751 |
! |
2752 |
||
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2753 |
nextExtendedSpecial:ch |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2754 |
parserFlags allowExtendedBinarySelectors ifTrue:[ |
4611 | 2755 |
^ self nextSpecial |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2756 |
]. |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2757 |
^ self invalidCharacter:source peek. |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2758 |
! |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2759 |
|
141 | 2760 |
nextHash |
1226 | 2761 |
"a # has been read - return either |
4611 | 2762 |
a symbol, |
2763 |
HashLeftParen (for '#('), |
|
2764 |
HashLeftBrack (for '#['), |
|
2765 |
HashLeftBrace (for '#{' and AllowQualifiedNames/inline objects) |
|
2766 |
HashHashLeftParen (for '##(' and AllowDolphinExtensions) |
|
2767 |
HashHashLeftBrack (for '##[' ) |
|
2768 |
HashHash (for '##' ) |
|
3948 | 2769 |
|
2770 |
extended syntax (scheme-style literal arrays): |
|
4426 | 2771 |
(requires ParserFlags allowSTXExtendedArrayLiterals:true) |
4611 | 2772 |
HashTypedArrayParen (for '#u8(', '#s8(' , '#u16(' ...) |
2773 |
type in tokenValue: u1, u8, u16, u32, u64, s8, s16, s32, s64, |
|
2774 |
f16, f32, f64, f, d, b, B |
|
1226 | 2775 |
" |
1026 | 2776 |
|
1656 | 2777 |
|nextChar string allowUnderscoreInIdentifier| |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2778 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2779 |
allowUnderscoreInIdentifier := parserFlags allowUnderscoreInIdentifier. |
0 | 2780 |
|
141 | 2781 |
nextChar := source nextPeek. |
2782 |
nextChar notNil ifTrue:[ |
|
4611 | 2783 |
(nextChar == $( ) ifTrue:[ |
2784 |
source next. |
|
2785 |
token := '#('. |
|
2786 |
tokenType := #HashLeftParen. |
|
2787 |
^ tokenType |
|
2788 |
]. |
|
2789 |
||
2790 |
(nextChar == $[ ) ifTrue:[ |
|
2791 |
"ST-80 & ST/X support Constant ByteArrays as #[...] |
|
2792 |
now all Smalltalk dialects do." |
|
2793 |
source next. |
|
2794 |
token := '#['. |
|
2795 |
tokenType := #HashLeftBrack. |
|
2796 |
^ tokenType |
|
2797 |
]. |
|
2798 |
||
2799 |
(nextChar == ${ ) ifTrue:[ |
|
2800 |
" #{ ... } is one of: |
|
2801 |
#{ Foo.Bar.Baz } VW3 and later qualified name |
|
2802 |
#{ xx-xx-xx-xx-...-xx } StAgents UUID |
|
2803 |
#{ URL } url object qualifier |
|
2804 |
#{ key: value ... } inline literal object |
|
2805 |
" |
|
2806 |
source next. |
|
2807 |
token := '#{'. |
|
2808 |
tokenType := #HashLeftBrace. |
|
2809 |
^ tokenType |
|
2810 |
]. |
|
2811 |
||
2812 |
(nextChar == $' ) ifTrue:[ |
|
2813 |
"ST-80 and ST/X support arbitrary symbols as #'...' |
|
2814 |
now all dialects do" |
|
2815 |
self nextString:nextChar. |
|
2816 |
self markSymbolFrom:tokenPosition to:(source position). |
|
2817 |
tokenType == #EOF ifFalse:[ |
|
2818 |
tokenValue isWideString ifTrue:[ |
|
2819 |
self syntaxError:'symbols which require 2-byte characters are not (yet) allowed' |
|
2820 |
position:tokenPosition to:(source position). |
|
2821 |
]. |
|
2822 |
tokenValue := token := tokenValue asSymbol. |
|
2823 |
tokenType := #Symbol. |
|
2824 |
]. |
|
2825 |
^ tokenType |
|
2826 |
]. |
|
2827 |
||
2828 |
(nextChar == $#) ifTrue:[ |
|
2829 |
nextChar := source nextPeek. |
|
2830 |
nextChar == $( ifTrue:[ |
|
2831 |
parserFlags allowDolphinExtensions == true ifTrue:[ |
|
2832 |
"dolphin does computed literals as ##( expression )" |
|
2833 |
source next. |
|
2834 |
token := '##('. |
|
2835 |
tokenType := #HashHashLeftParen. |
|
2836 |
^ tokenType |
|
2837 |
]. |
|
2838 |
]. |
|
2839 |
||
2840 |
nextChar == $[ ifTrue:[ |
|
2841 |
source next. |
|
2842 |
token := '##['. |
|
2843 |
tokenType := #HashHashLeftBrack. |
|
2844 |
^ tokenType |
|
2845 |
]. |
|
2846 |
||
2847 |
parserFlags allowVisualAgeESSymbolLiterals == true ifTrue:[ |
|
2848 |
"V'age has special ESsymbols as ##name or ##'name'" |
|
2849 |
(self nextSymbolAfterHash) notNil ifTrue:[ |
|
2850 |
tokenType := #ESSymbol. |
|
2851 |
^ #ESSymbol |
|
2852 |
]. |
|
2853 |
(nextChar == $') ifTrue:[ |
|
2854 |
source next. |
|
2855 |
self nextString:nextChar. |
|
2856 |
tokenType := #ESSymbol. |
|
2857 |
^ #ESSymbol |
|
2858 |
]. |
|
2859 |
]. |
|
2860 |
||
2861 |
token := '##'. |
|
2862 |
tokenType := #HashHash. |
|
2863 |
^ tokenType |
|
2864 |
]. |
|
2865 |
||
2866 |
"/ scheme-style typed literal arrays: |
|
2867 |
"/ #uXX( ... ) XX = { 1, 8, 16, 32, 64 } - bit, uint8, uint16, uint32 or uint64 array |
|
2868 |
"/ #iXX( ... ) XX = { 8, 16, 32, 64 } - int8, int16, int32 or int64 array |
|
2869 |
"/ #fXX( ... ) XX = { 16, 32, 64 } - IEEE half, single or double array |
|
2870 |
"/ #f( ... ) - IEEE single float array (same as #f32) |
|
2871 |
"/ #d( ... ) - IEEE double array (same as #f64) |
|
2872 |
"/ #b( ... ) - bit array (same as #u1) |
|
2873 |
"/ #B( ... ) - boolean array |
|
2874 |
('usfdbB' includes:nextChar) ifTrue:[ |
|
2875 |
|prefix| |
|
2876 |
||
2877 |
"/ collec tuntil we know what we get... |
|
2878 |
prefix := String with:nextChar. |
|
2879 |
nextChar := source nextPeek. |
|
2880 |
[nextChar notNil and:[nextChar isDigit]] whileTrue:[ |
|
2881 |
prefix := prefix copyWith:nextChar. |
|
2882 |
nextChar := source nextPeek. |
|
2883 |
]. |
|
2884 |
nextChar == $( ifTrue:[ |
|
2885 |
parserFlags allowSTXExtendedArrayLiterals ifFalse:[ |
|
2886 |
self parseError:c'Non-Standard ST/X extension used: #XXX( .. ) unboxed array literal.\nPlease enable "allowSTXExtendedArrayLiterals" in the ParserFlags' |
|
2887 |
position:tokenPosition to:source position |
|
2888 |
]. |
|
2889 |
source next. |
|
2890 |
( |
|
2891 |
#( 'f' 'd' 'b' 'B' |
|
2892 |
'u1' 'u8' 'u16' 'u32' 'u64' |
|
2893 |
's8' 's16' 's32' 's64' |
|
2894 |
'f16' 'f32' 'f64' |
|
2895 |
) includes:prefix |
|
2896 |
) ifTrue:[ |
|
2897 |
tokenType := #HashTypedArrayParen. |
|
2898 |
tokenValue := prefix asSymbol. |
|
2899 |
^ tokenType |
|
2900 |
]. |
|
2901 |
self parseError:'unsupported literal array type: ',prefix. |
|
2902 |
tokenType := #HashLeftParen. |
|
2903 |
^ #HashLeftParen |
|
2904 |
]. |
|
2905 |
^ self nextSymbolAfterHash:prefix. |
|
2906 |
]. |
|
2907 |
||
2908 |
(self nextSymbolAfterHash) notNil ifTrue:[ |
|
2909 |
^ #Symbol |
|
2910 |
]. |
|
2911 |
||
2912 |
(self isSpecialOrExtendedSpecialCharacter:nextChar) ifTrue:[ |
|
2913 |
string := source next asString. |
|
2914 |
nextChar := source peek. |
|
2915 |
nextChar notNil ifTrue:[ |
|
2916 |
(self isSpecialOrExtendedSpecialCharacter:nextChar) ifTrue:[ |
|
2917 |
source next. |
|
2918 |
string := string copyWith:nextChar |
|
2919 |
] |
|
2920 |
]. |
|
2921 |
self markSymbolFrom:tokenPosition to:(source position). |
|
2922 |
tokenValue := token := string asSymbol. |
|
2923 |
tokenType := #Symbol. |
|
2924 |
^ tokenType |
|
2925 |
] |
|
0 | 2926 |
]. |
1298 | 2927 |
|
141 | 2928 |
"this allows hash to be used as binop - |
4037 | 2929 |
I don't know, if this is correct ..." |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
2930 |
tokenName := token := '#'. |
0 | 2931 |
tokenType := #BinaryOperator. |
2932 |
^ tokenType |
|
500 | 2933 |
|
1781 | 2934 |
"Modified: / 01-08-2006 / 14:57:19 / cg" |
2712
eddb351cf9c2
comment/format in: #nextHash
Claus Gittinger <cg@exept.de>
parents:
2678
diff
changeset
|
2935 |
"Modified (format): / 30-09-2011 / 12:23:04 / cg" |
4426 | 2936 |
"Modified: / 30-05-2019 / 19:06:36 / Claus Gittinger" |
0 | 2937 |
! |
2938 |
||
2939 |
nextId |
|
1026 | 2940 |
"no longer used here - remains for backwardCompatibility for |
2941 |
subclass users ... (sigh)" |
|
2942 |
||
4188 | 2943 |
|nextChar string oldString |
0 | 2944 |
index "{ Class: SmallInteger }" |
2945 |
max "{ Class: SmallInteger }" | |
|
2946 |
||
656
e4249b285fd8
using #peekOrNil makes it some 10% faster when scanning
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
2947 |
nextChar := source peekOrNil. |
1470
62844fc53a87
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
2948 |
string := String uninitializedNew:20. |
0 | 2949 |
index := 0. |
2950 |
max := 10. |
|
3405 | 2951 |
[ |
4611 | 2952 |
(nextChar notNil and:[nextChar isLetterOrDigit]) ifFalse:[ |
2953 |
^ string copyTo:index |
|
2954 |
]. |
|
2955 |
(index == max) ifTrue:[ |
|
2956 |
oldString := string. |
|
2957 |
string := String basicNew:(max * 2). |
|
2958 |
string replaceFrom:1 to:max with:oldString. |
|
2959 |
max := max * 2 |
|
2960 |
]. |
|
2961 |
index := index + 1. |
|
2962 |
string at:index put:nextChar. |
|
2963 |
nextChar := source nextPeek |
|
3405 | 2964 |
] loop. |
656
e4249b285fd8
using #peekOrNil makes it some 10% faster when scanning
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
2965 |
|
e4249b285fd8
using #peekOrNil makes it some 10% faster when scanning
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
2966 |
"Modified: / 5.3.1998 / 02:53:57 / cg" |
0 | 2967 |
! |
2968 |
||
2969 |
nextIdentifier |
|
4611 | 2970 |
"an alpha character |
4441 | 2971 |
(or underscore if AllowUnderscore, |
2972 |
or greek if allowGreekCharactersInIdentifier |
|
4611 | 2973 |
or national letter if allowNationalCharactersInIdentifier) |
4441 | 2974 |
has been read. |
1026 | 2975 |
Return the next identifier." |
2976 |
||
4188 | 2977 |
|nextChar string ok pos ch2 |
3449 | 2978 |
allowUnderscoreInIdentifier allowDollarInIdentifier |
4441 | 2979 |
allowParagraphInIdentifier |
2980 |
allowNationalCharactersInIdentifier allowGreekCharactersInIdentifier| |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2981 |
|
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
2982 |
allowUnderscoreInIdentifier := parserFlags allowUnderscoreInIdentifier. |
3449 | 2983 |
allowDollarInIdentifier := parserFlags allowDollarInIdentifier. |
4441 | 2984 |
allowParagraphInIdentifier := parserFlags allowParagraphInIdentifier. |
3449 | 2985 |
allowNationalCharactersInIdentifier := parserFlags allowNationalCharactersInIdentifier. |
4441 | 2986 |
allowGreekCharactersInIdentifier := parserFlags allowGreekCharactersInIdentifier. |
0 | 2987 |
|
87 | 2988 |
hereChar == $_ ifTrue:[ |
4611 | 2989 |
"/ |
2990 |
"/ no need to check for allowUnderscoreInIdentifier here; |
|
2991 |
"/ could not arrive here if it was off |
|
2992 |
"/ |
|
2993 |
nextChar := source nextPeek. |
|
2994 |
parserFlags allowOldStyleAssignment ifTrue:[ |
|
2995 |
(nextChar notNil and:[ nextChar isLetterOrDigitOrUnderline]) ifFalse:[ |
|
2996 |
"oops: a single underscore is an old-style assignement" |
|
2997 |
nextChar == $: ifFalse:[ |
|
2998 |
self warnOldStyleAssignmentAt:tokenPosition. |
|
2999 |
tokenType := token := $_. |
|
3000 |
^ tokenType |
|
3001 |
] |
|
3002 |
]. |
|
3003 |
]. |
|
3004 |
string := '_'. |
|
3005 |
self warnUnderscoreAt:tokenPosition. |
|
3006 |
[nextChar == $_] whileTrue:[ |
|
3007 |
string := string copyWith:$_. |
|
3008 |
nextChar := source nextPeek. |
|
3009 |
]. |
|
3010 |
(nextChar notNil and:[nextChar isLetterOrDigit]) ifTrue:[ |
|
3011 |
string := string , source nextAlphaNumericWord. |
|
3012 |
] |
|
87 | 3013 |
] ifFalse:[ |
4611 | 3014 |
nextChar := source peekOrNil. |
3015 |
(nextChar notNil and:[nextChar isLetterOrDigit]) ifTrue:[ |
|
3016 |
string := source nextAlphaNumericWord "self nextId". |
|
3017 |
] ifFalse:[ |
|
3018 |
string := '' |
|
3019 |
] |
|
87 | 3020 |
]. |
656
e4249b285fd8
using #peekOrNil makes it some 10% faster when scanning
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3021 |
nextChar := source peekOrNil. |
87 | 3022 |
|
4611 | 3023 |
((nextChar == $') |
4414 | 3024 |
and:[ (string size == 1) |
4432 | 3025 |
and:[ ((parserFlags allowCStrings and:[string = 'c']) |
4611 | 3026 |
or:[(parserFlags allowEStrings and:[string = 'e']) |
3027 |
or:[(parserFlags allowRStrings and:[string = 'r']) |
|
3028 |
or:[parserFlags allowExtendedSTXSyntax ]]]) ]] |
|
4414 | 3029 |
) ifTrue:[ |
4611 | 3030 |
source next. |
3031 |
^ self xnextString:$' escapeStyle:string |
|
3032 |
]. |
|
4334 | 3033 |
|
4188 | 3034 |
(((nextChar == $_) and:[allowUnderscoreInIdentifier]) |
4441 | 3035 |
or:[ (allowDollarInIdentifier and:[nextChar == $$ ]) |
4610 | 3036 |
or:[ (nextChar == $§ and:[ allowParagraphInIdentifier]) |
4441 | 3037 |
or:[ (allowNationalCharactersInIdentifier and:[ nextChar notNil and:[nextChar isNationalLetter]]) |
3038 |
or:[ (allowGreekCharactersInIdentifier and:[ nextChar notNil and:[nextChar isNationalLetter]]) |
|
3039 |
]]]]) ifTrue:[ |
|
4611 | 3040 |
pos := source position + 1. |
3041 |
nextChar == $_ ifTrue:[ |
|
3042 |
self warnUnderscoreAt:pos. |
|
3043 |
] ifFalse:[ |
|
3044 |
nextChar == $$ ifTrue:[ |
|
3045 |
self warnDollarAt:pos. |
|
3046 |
] ifFalse:[ |
|
3047 |
nextChar == $§ ifTrue:[ |
|
3048 |
self warnParagraphAt:pos. |
|
3049 |
] ifFalse:[ |
|
3050 |
"/ self warnNationalCharacterAt:pos. |
|
3051 |
] |
|
3052 |
] |
|
3053 |
]. |
|
3054 |
ok := true. |
|
3055 |
[ok] whileTrue:[ |
|
3056 |
string := string copyWith:nextChar. |
|
3057 |
nextChar := source nextPeek. |
|
3058 |
nextChar isNil ifTrue:[ |
|
3059 |
ok := false |
|
3060 |
] ifFalse:[ |
|
3061 |
(nextChar isLetterOrDigit) ifTrue:[ |
|
3062 |
string := string , source nextAlphaNumericWord. |
|
3063 |
nextChar := source peekOrNil. |
|
3064 |
]. |
|
3065 |
ok := ((nextChar == $_) and:[allowUnderscoreInIdentifier]) |
|
3066 |
or:[((nextChar == $$ ) and:[allowDollarInIdentifier]) |
|
3067 |
or:[((nextChar == $§ ) and:[allowParagraphInIdentifier]) |
|
3068 |
or:[(nextChar notNil and:[allowNationalCharactersInIdentifier and:[nextChar isNationalLetter]]) |
|
3069 |
or:[(nextChar notNil and:[allowGreekCharactersInIdentifier and:[nextChar isGreekLetter]]) |
|
3070 |
]]]]. |
|
3071 |
]. |
|
3072 |
]. |
|
60 | 3073 |
]. |
3074 |
||
785
14d0ec37a754
added hook for subclasses which do not want to scan
Claus Gittinger <cg@exept.de>
parents:
783
diff
changeset
|
3075 |
(nextChar == $: and:[scanColonAsKeyword]) ifTrue:[ |
4611 | 3076 |
source next. |
3077 |
ch2 := source peekOrNil. |
|
3078 |
"/ colon follows - care for '::' (nameSpace separator) or ':=' (assignment) |
|
3079 |
(ch2 == $=) ifFalse:[ |
|
3080 |
(ch2 == $:) ifFalse:[ |
|
3081 |
tokenName := token := string copyWith:nextChar. |
|
3082 |
tokenType := #Keyword. |
|
3083 |
inArrayLiteral == true ifTrue:[ |
|
3084 |
(ch2 isLetter |
|
3085 |
or:[ch2 == $_ and:[allowUnderscoreInIdentifier]]) ifTrue:[ |
|
3086 |
"/ kludge: recurse to read the rest. |
|
3087 |
self nextIdentifier. |
|
3088 |
tokenName := token := (string copyWith:nextChar) , token. |
|
3089 |
tokenType ~~ #Keyword ifTrue:[ |
|
3090 |
self syntaxError:'invalid keyword symbol in array constant' |
|
3091 |
position:tokenPosition to:(source position). |
|
3092 |
]. |
|
3093 |
tokenType := #Keyword. |
|
3094 |
]. |
|
3095 |
]. |
|
3096 |
^ tokenType |
|
3097 |
]. |
|
3098 |
peekChar := $:. |
|
3099 |
peekChar2 := $:. |
|
3100 |
] ifTrue:[ |
|
3101 |
peekChar := $:. |
|
3102 |
peekChar2 := $=. |
|
3103 |
] |
|
1027
c944d9be2a69
silently scan Foo.Bar as Foo::Bar,
Claus Gittinger <cg@exept.de>
parents:
1026
diff
changeset
|
3104 |
] ifFalse:[ |
4611 | 3105 |
(nextChar == $. and:[parserFlags allowQualifiedNames]) ifTrue:[ |
3106 |
"/ period follows - if next-after character is an identifier character, |
|
3107 |
"/ make peekSym a #NameSpaceSeparator; otherwise a $. |
|
3108 |
source next. |
|
3109 |
ch2 := source peekOrNil. |
|
3110 |
(ch2 notNil |
|
3111 |
and:[ch2 isLetter or:[ch2 == $_ and:[allowUnderscoreInIdentifier]]]) ifTrue:[ |
|
3112 |
peekChar := #'::'. |
|
3113 |
] ifFalse:[ |
|
3114 |
peekChar := $. |
|
3115 |
]. |
|
3116 |
]. |
|
0 | 3117 |
]. |
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
3118 |
|
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
3119 |
nextChar == $- ifTrue:[ |
4611 | 3120 |
pos := source position + 1. |
3121 |
self |
|
3122 |
warnPossibleIncompatibility:'add spaces around ''-'' for compatibility with other systems' |
|
3123 |
position:pos to:pos. |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
3124 |
]. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
3125 |
|
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
3126 |
tokenName := token := string. |
1026 | 3127 |
(self checkForKeyword:string) ifFalse:[ |
4611 | 3128 |
tokenType := #Identifier. |
1026 | 3129 |
]. |
0 | 3130 |
^ tokenType |
120 | 3131 |
|
1954
3c20721e963c
care for end-of-text when parsing a single underline identifier.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3132 |
"Created: / 13-09-1995 / 12:56:42 / claus" |
4042 | 3133 |
"Modified: / 17-11-2016 / 09:19:46 / cg" |
4441 | 3134 |
"Modified: / 08-06-2019 / 18:25:35 / Claus Gittinger" |
0 | 3135 |
! |
3136 |
||
141 | 3137 |
nextMantissa:radix |
1026 | 3138 |
"read the mantissa of a radix number" |
3139 |
||
1351 | 3140 |
<resource: #obsolete> |
3141 |
||
1347
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
3142 |
^ (self nextMantissaAndScaledPartWithRadix:radix) first |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
3143 |
! |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
3144 |
|
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
3145 |
nextMantissaAndScaledPartWithRadix:radix |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
3146 |
"read the mantissa of a radix number. |
4037 | 3147 |
Since we don't know yet if this is for a Float, LongFloat or a FixedPoint, |
1430 | 3148 |
return info which is useful for all: an array consisting of |
3149 |
the mantissa as float/longFloat, the numerator and the scale for a fixedPoint." |
|
1347
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
3150 |
|
1972
f52b7e609f1f
common code with Number-reading
Claus Gittinger <cg@exept.de>
parents:
1971
diff
changeset
|
3151 |
^ Number readMantissaAndScaleFrom:source radix:radix |
141 | 3152 |
! |
3153 |
||
3154 |
nextNumber |
|
1026 | 3155 |
"scan a number; handles radix prefix, mantissa and exponent. |
4188 | 3156 |
Allows for |
4637 | 3157 |
e, d or q to be used as exponent limiter (for float or long float), |
3158 |
s for scaled fixpoint numbers, |
|
3159 |
f for single precision floats (controlled by parserFlags). |
|
4422 | 3160 |
|
4312 | 3161 |
i.e. 1e5 -> float (technically a double precision IEEE) |
4637 | 3162 |
1d5 -> float (also, a double precision IEEE) |
3163 |
1q5 -> long float (a c-long double / extended or quad precision IEEE, dep. on CPU) |
|
3164 |
1Q5 -> quad float (quad precision IEEE) |
|
3165 |
1QD5 -> qDouble float (4*double precision) |
|
3166 |
1QL5 -> large float (arbitrary precision) |
|
3167 |
1s -> a fixed point with precision from number of digits given. |
|
3168 |
1s5 -> a fixed point with 5 digits precision. |
|
3169 |
1d -> float (technically a double precision IEEE float). |
|
3170 |
1q -> long float (technically a c-long double / extended or quad precision IEEE float, dep. on CPU). |
|
3171 |
1Q -> quad float (quad precision IEEE) |
|
3172 |
||
3173 |
1f5 -> shortFloat (technically a single precision IEEE float) or float, dep on parserFlags. |
|
3174 |
1f -> shortFloat (technically a single precision IEEE float) or float, dep on parserFlags. |
|
3705 | 3175 |
support for scaled decimals can be disabled, if code needs to be read, |
4592 | 3176 |
which does not know about them (very unlikely). |
3177 |
support for single prec. floats with f/F is controlled by a parser flag" |
|
1026 | 3178 |
|
4188 | 3179 |
|pos1 nextChar value integerPart sign |
4611 | 3180 |
expSign tokenRadix mantissaAndScaledPart d type exp scale |
4610 | 3181 |
kindChar kindClass chars | |
141 | 3182 |
|
3183 |
tokenRadix := 10. |
|
1679
c568383eb5ec
reading signed radix numbers
Claus Gittinger <cg@exept.de>
parents:
1678
diff
changeset
|
3184 |
sign := 1. |
1347
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
3185 |
type := #Integer. |
3268 | 3186 |
pos1 := source position + 1. |
1347
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
3187 |
|
4479 | 3188 |
parserFlags allowCIntegers ifTrue:[ |
4637 | 3189 |
source peek == $0 ifTrue:[ |
3190 |
nextChar := source nextPeek. |
|
3191 |
nextChar == $x ifTrue:[ |
|
3192 |
source next. |
|
3193 |
((source peek ? $.) isDigitRadix:16) ifFalse:[ |
|
3194 |
self syntaxError:'invalid cStyle integer (hex digit expected)' |
|
3195 |
position:tokenPosition to:(source position). |
|
3196 |
]. |
|
3197 |
value := Integer readFrom:source radix:16. |
|
3198 |
sign < 0 ifTrue:[ value := value negated ]. |
|
3199 |
tokenValue := token := value. |
|
3200 |
tokenType := type. |
|
3201 |
^ tokenType |
|
3202 |
]. |
|
3203 |
nextChar == $o ifTrue:[ |
|
3204 |
source next. |
|
3205 |
((source peek ? $.) isDigitRadix:8) ifFalse:[ |
|
3206 |
self syntaxError:'invalid cStyle integer (octal digit expected)' |
|
3207 |
position:tokenPosition to:(source position). |
|
3208 |
]. |
|
3209 |
value := Integer readFrom:source radix:8. |
|
3210 |
sign < 0 ifTrue:[ value := value negated ]. |
|
3211 |
tokenValue := token := value. |
|
3212 |
tokenType := type. |
|
3213 |
^ tokenType |
|
3214 |
]. |
|
3215 |
nextChar == $b ifTrue:[ |
|
3216 |
source next. |
|
3217 |
((source peek ? $.) isDigitRadix:2) ifFalse:[ |
|
3218 |
self syntaxError:'invalid cStyle integer (binary digit expected)' |
|
3219 |
position:tokenPosition to:(source position). |
|
3220 |
]. |
|
3221 |
value := Integer readFrom:source radix:2. |
|
3222 |
sign < 0 ifTrue:[ value := value negated ]. |
|
3223 |
tokenValue := token := value. |
|
3224 |
tokenType := type. |
|
3225 |
^ tokenType |
|
3226 |
]. |
|
3227 |
(nextChar notNil |
|
3228 |
and:[ nextChar isDigit or:[nextChar == $.]]) ifFalse:[ |
|
3229 |
tokenValue := token := 0. |
|
3230 |
tokenType := type. |
|
3231 |
^ tokenType |
|
3232 |
]. |
|
3233 |
value := 0. |
|
3234 |
]. |
|
4479 | 3235 |
]. |
4611 | 3236 |
nextChar == $. ifFalse:[ |
4637 | 3237 |
value := Integer readFrom:source radix:tokenRadix. |
3238 |
nextChar := source peekOrNil. |
|
3239 |
(nextChar == $r) ifTrue:[ |
|
3240 |
tokenRadix := value. |
|
3241 |
source next. |
|
3242 |
(tokenRadix between:2 and:36) ifFalse:[ |
|
3243 |
self syntaxError:'bad radix (must be 2 .. 36)' |
|
3244 |
position:tokenPosition to:(source position). |
|
3245 |
]. |
|
3246 |
source peekOrNil == $- ifTrue:[ |
|
3247 |
source next. |
|
3248 |
sign := -1 |
|
3249 |
]. |
|
3250 |
pos1 := source position + 1. |
|
3251 |
value := Integer readFrom:source radix:tokenRadix. |
|
3252 |
nextChar := source peekOrNil. |
|
3253 |
]. |
|
141 | 3254 |
]. |
821
bc543afcc1e6
give a warning if radix>14 and an e/E is encountered in a float
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
3255 |
|
141 | 3256 |
(nextChar == $.) ifTrue:[ |
4637 | 3257 |
nextChar := source nextPeek. |
3258 |
(nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[ |
|
3259 |
(tokenRadix > 13) ifTrue:[ |
|
3260 |
(nextChar == $d or:[nextChar == $D]) ifTrue:[ |
|
3261 |
self warning:'float with radix > 13 - (d/D are valid digits; not exponent-leaders)' |
|
3262 |
position:tokenPosition to:(source position). |
|
3263 |
]. |
|
3264 |
(tokenRadix > 14) ifTrue:[ |
|
3265 |
(nextChar == $e or:[nextChar == $E]) ifTrue:[ |
|
3266 |
self warning:'float with radix > 14 - (e/E are valid digits; not exponent-leaders)' |
|
3267 |
position:tokenPosition to:(source position). |
|
3268 |
]. |
|
3269 |
(tokenRadix > 15) ifTrue:[ |
|
3270 |
(nextChar == $f or:[nextChar == $F]) ifTrue:[ |
|
3271 |
self warning:'float with radix > 15 - (f/F are valid digits; not exponent-leaders)' |
|
3272 |
position:tokenPosition to:(source position). |
|
3273 |
] |
|
3274 |
] |
|
3275 |
] |
|
3276 |
]. |
|
3277 |
mantissaAndScaledPart := self nextMantissaAndScaledPartWithRadix:tokenRadix. |
|
3278 |
integerPart := value. |
|
3279 |
value := integerPart + (mantissaAndScaledPart first). "could be a longFloat now" |
|
3280 |
type := #Float. |
|
3281 |
nextChar := source peekOrNil |
|
3282 |
] ifFalse:[ |
|
3283 |
('eEdDqQfF' includes:nextChar) ifTrue:[ |
|
3284 |
"/ allow 5.e-3 - is this standard ? |
|
3285 |
||
3286 |
] ifFalse:[ |
|
1339
7dd363978456
start to migrate towards raising ParseError.
Claus Gittinger <cg@exept.de>
parents:
1321
diff
changeset
|
3287 |
"/ nextChar == (Character cr) ifTrue:[ |
7dd363978456
start to migrate towards raising ParseError.
Claus Gittinger <cg@exept.de>
parents:
1321
diff
changeset
|
3288 |
"/ lineNr := lineNr + 1. |
7dd363978456
start to migrate towards raising ParseError.
Claus Gittinger <cg@exept.de>
parents:
1321
diff
changeset
|
3289 |
"/ ]. |
4637 | 3290 |
nextChar := peekChar := $.. |
3291 |
] |
|
3292 |
] |
|
141 | 3293 |
]. |
821
bc543afcc1e6
give a warning if radix>14 and an e/E is encountered in a float
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
3294 |
|
4148 | 3295 |
('eEdDqQfF' includes:nextChar) ifTrue:[ |
4637 | 3296 |
kindClass := Float. |
3297 |
kindChar := nextChar. |
|
3298 |
nextChar := source nextPeek. |
|
3299 |
(kindChar == $q or:[kindChar == $Q]) ifTrue:[ |
|
3300 |
(kindChar == $Q) ifTrue:[ |
|
3301 |
nextChar == $D ifTrue:[ |
|
3302 |
kindClass := QDouble. |
|
3303 |
value := value asQDouble. |
|
3304 |
nextChar := source nextPeek. |
|
3305 |
] ifFalse:[ |
|
3306 |
nextChar == $L ifTrue:[ |
|
3307 |
kindClass := LargeFloat. |
|
3308 |
value := value asLargeFloat. |
|
3309 |
nextChar := source nextPeek. |
|
3310 |
] ifFalse:[ |
|
3311 |
kindClass := QuadFloat. |
|
3312 |
value := value asQuadFloat |
|
3313 |
]. |
|
3314 |
]. |
|
3315 |
] ifFalse:[ |
|
3316 |
kindClass := LongFloat. |
|
3317 |
value := value asLongFloat |
|
3318 |
]. |
|
3319 |
] ifFalse:[ |
|
3320 |
((kindChar == $f or:[kindChar == $F]) and:[parserFlags singlePrecisionFloatF]) ifTrue:[ |
|
3321 |
kindClass := ShortFloat. |
|
3322 |
value := value asShortFloat |
|
3323 |
] ifFalse:[ |
|
3324 |
value := value asFloat. |
|
3325 |
]. |
|
3326 |
]. |
|
3327 |
type := #Float. |
|
3328 |
(nextChar notNil and:[(nextChar isDigit"Radix:tokenRadix") or:['+-' includes:nextChar]]) ifTrue:[ |
|
3329 |
expSign := 1. |
|
3330 |
(nextChar == $+) ifTrue:[ |
|
3331 |
nextChar := source nextPeek |
|
3332 |
] ifFalse:[ |
|
3333 |
(nextChar == $-) ifTrue:[ |
|
3334 |
nextChar := source nextPeek. |
|
3335 |
expSign := -1 |
|
3336 |
] |
|
3337 |
]. |
|
3338 |
exp := (Integer readFrom:source) * expSign. |
|
3339 |
value := value * ((value class unity * tokenRadix) raisedToInteger:exp). |
|
3340 |
||
3341 |
nextChar := source peek. |
|
3342 |
||
3343 |
"/ due to a strange overflow, we might get a Nan, although we |
|
3344 |
"/ are actually still in the float range. |
|
3345 |
"/ happens eg. for 1.7976931348623157e+308 |
|
3346 |
||
3347 |
"/ Also, the above raisedToInteger generates an additional error, |
|
3348 |
"/ which is not present, if we use the strtox functions from the C-library. |
|
3349 |
"/ Therefore, always use the low level fastFromString: converter. |
|
3350 |
||
3351 |
"/ However: it only accepts decimal radix |
|
3352 |
tokenRadix = 10 ifTrue:[ |
|
3353 |
Error handle:[:ex | |
|
3354 |
"/ self halt. |
|
3355 |
] do:[ |
|
3356 |
chars := (source collection copyFrom:pos1 to:source position) string asSingleByteStringIfPossible. |
|
3357 |
value := kindClass fastFromString:chars at:1. |
|
3358 |
]. |
|
3359 |
]. |
|
3360 |
]. |
|
1347
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
3361 |
] ifFalse:[ |
4637 | 3362 |
value isLimitedPrecisionReal ifTrue:[ |
3363 |
"/ fastFromString only accepts decimal radix |
|
3364 |
tokenRadix = 10 ifTrue:[ |
|
3365 |
"/ no type specified - makes it a float |
|
3366 |
"/ value := value asFloat. |
|
3367 |
Error handle:[:ex | |
|
3368 |
value := value asFloat |
|
3369 |
] do:[ |
|
3370 |
chars := (source collection copyFrom:pos1 to:source position) asSingleByteStringIfPossible. |
|
3371 |
value := Float fastFromString:chars at:1. |
|
3372 |
]. |
|
3373 |
]. |
|
3374 |
]. |
|
3375 |
||
3376 |
parserFlags allowFixedPointLiterals ifTrue:[ |
|
3377 |
"/ ScaledDecimal numbers |
|
3378 |
('s' includes:nextChar) ifTrue:[ |
|
3379 |
nextChar := source nextPeek. |
|
3380 |
||
3381 |
(nextChar notNil and:[(nextChar isDigit)]) ifTrue:[ |
|
3382 |
scale := (Integer readFrom:source). |
|
3383 |
]. |
|
3384 |
||
3385 |
mantissaAndScaledPart isNil ifTrue:[ |
|
3386 |
value := value asFixedPoint:(scale ? 0) |
|
3387 |
] ifFalse:[ |
|
3388 |
d := 10 raisedTo:(mantissaAndScaledPart last). |
|
3389 |
value := FixedPoint |
|
3390 |
numerator:((integerPart * d) + mantissaAndScaledPart second) |
|
3391 |
denominator:d |
|
3392 |
scale:(scale ? mantissaAndScaledPart last). |
|
3393 |
]. |
|
3394 |
type := #FixedPoint. |
|
3395 |
self |
|
3396 |
warnPossibleIncompatibility:'fixedPoint literal might be incompatibile with other systems' |
|
3397 |
position:pos1 to:source position + 1. |
|
3398 |
]. |
|
3399 |
]. |
|
141 | 3400 |
]. |
4188 | 3401 |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
3402 |
nextChar == $- ifTrue:[ |
4637 | 3403 |
self |
3404 |
warnPossibleIncompatibility:'add a space before ''-'' for compatibility with other systems' |
|
3405 |
position:(source position + 1) to:(source position + 1). |
|
526
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
3406 |
]. |
adb8aed3a691
added compatibility warnings for '-' without whitespace
Claus Gittinger <cg@exept.de>
parents:
505
diff
changeset
|
3407 |
|
4598 | 3408 |
tokenValue := token := (sign < 0) ifTrue:[value negated] ifFalse:[value]. |
1347
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
3409 |
tokenType := type. |
1596 | 3410 |
(tokenValue isLimitedPrecisionReal) ~~ (tokenType == #Float) ifTrue:[ |
4637 | 3411 |
self shouldImplement. |
1596 | 3412 |
]. |
1347
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
3413 |
|
671 | 3414 |
"/ self markConstantFrom:tokenPosition to:(source position - 1). |
141 | 3415 |
^ tokenType |
313
ee72a11af9a2
handle trailing 'd' after a float (ST-80 compatible Doubles)
Claus Gittinger <cg@exept.de>
parents:
311
diff
changeset
|
3416 |
|
4148 | 3417 |
"Modified: / 15-06-2017 / 11:07:52 / cg" |
4443 | 3418 |
"Modified: / 11-06-2019 / 00:41:00 / Claus Gittinger" |
141 | 3419 |
! |
3420 |
||
0 | 3421 |
nextPrimitive |
1026 | 3422 |
"scan an inline C-primitive." |
3423 |
||
4188 | 3424 |
|nextChar inPrimitive string stringCollector |
0 | 3425 |
index "{ Class: SmallInteger }" |
3426 |
len "{ Class: SmallInteger }" | |
|
3427 |
||
3428 |
nextChar := source nextPeek. |
|
1302 | 3429 |
(nextChar == ${) ifFalse:[ |
4611 | 3430 |
^ self nextSpecialWith:$% |
1302 | 3431 |
]. |
3432 |
||
3705 | 3433 |
stringCollector := CharacterWriteStream new. |
1302 | 3434 |
nextChar := source nextPeek. |
3435 |
inPrimitive := true. |
|
3436 |
[inPrimitive] whileTrue:[ |
|
4611 | 3437 |
[nextChar == $%] whileFalse:[ |
3438 |
nextChar isNil ifTrue:[ |
|
3439 |
self syntaxError:'unterminated primitive' |
|
3440 |
position:tokenPosition to:source position + 1. |
|
3441 |
^ #Error |
|
3442 |
]. |
|
3443 |
stringCollector nextPut:nextChar. |
|
3444 |
nextChar := source next |
|
3445 |
]. |
|
3446 |
(source peekOrNil == $}) ifTrue:[ |
|
3447 |
inPrimitive := false |
|
3448 |
] ifFalse:[ |
|
3449 |
stringCollector nextPut:nextChar. |
|
3450 |
nextChar := source next |
|
3451 |
] |
|
0 | 3452 |
]. |
1302 | 3453 |
source next. |
3705 | 3454 |
tokenValue := token := stringCollector contents. |
1302 | 3455 |
tokenType := #Primitive. |
3456 |
lineNr := lineNr + (tokenValue occurrencesOf:(Character cr)). |
|
3457 |
^ tokenType |
|
0 | 3458 |
! |
3459 |
||
141 | 3460 |
nextSpecial |
3461 |
"a special character has been read, look for another one. |
|
3462 |
also -number is handled here" |
|
3463 |
||
1302 | 3464 |
|firstChar| |
0 | 3465 |
|
141 | 3466 |
firstChar := source next. |
1302 | 3467 |
^ self nextSpecialWith:firstChar |
3468 |
! |
|
3469 |
||
3470 |
nextSpecialWith:firstChar |
|
3471 |
"a special character has been read, look for another one. |
|
3472 |
also -number is handled here" |
|
3473 |
||
2155 | 3474 |
|secondChar thirdChar fourthChar string p| |
1302 | 3475 |
|
656
e4249b285fd8
using #peekOrNil makes it some 10% faster when scanning
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3476 |
secondChar := source peekOrNil. |
241
418eb41350d3
no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
3477 |
((firstChar == $-) and:[secondChar notNil]) ifTrue:[ |
4612 | 3478 |
secondChar isDigit ifTrue:[ |
3479 |
self nextNumber. |
|
3480 |
tokenValue := token := tokenValue negated. |
|
3481 |
^ tokenType |
|
3482 |
] |
|
0 | 3483 |
]. |
141 | 3484 |
string := firstChar asString. |
1705
19fff84a354a
more support for filein of ST/V code
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
3485 |
|
2155 | 3486 |
"/ changed: do not allow second char to be a hash |
3487 |
"/ unless the first is also. |
|
1705
19fff84a354a
more support for filein of ST/V code
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
3488 |
secondChar == $# ifTrue:[ |
4612 | 3489 |
(parserFlags allowHashAsBinarySelector |
3490 |
and:[firstChar == $#]) ifFalse:[ |
|
3491 |
tokenName := token := string. |
|
3492 |
tokenType := #BinaryOperator. |
|
3493 |
^ tokenType |
|
3494 |
]. |
|
1705
19fff84a354a
more support for filein of ST/V code
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
3495 |
]. |
19fff84a354a
more support for filein of ST/V code
Claus Gittinger <cg@exept.de>
parents:
1681
diff
changeset
|
3496 |
|
141 | 3497 |
secondChar notNil ifTrue:[ |
4612 | 3498 |
(secondChar == $-) ifTrue:[ |
3499 |
"special- look ahead if minus belongs to number following" |
|
3500 |
p := source position. |
|
3501 |
source next. |
|
3502 |
thirdChar := source peekOrNil. |
|
3503 |
source position:p. |
|
3504 |
(thirdChar notNil and:[thirdChar isDigit]) ifTrue:[ |
|
3505 |
tokenName := token := string. |
|
3506 |
tokenType := #BinaryOperator. |
|
3507 |
self |
|
3508 |
warnPossibleIncompatibility:'add a space before ''-'' for compatibility with stc and other ST systems' |
|
3509 |
position:p+1 |
|
3510 |
to:p+1. |
|
3511 |
^ tokenType |
|
3512 |
] |
|
3513 |
]. |
|
3514 |
(self isSpecialOrExtendedSpecialCharacter:secondChar) ifTrue:[ |
|
3515 |
source next. |
|
3516 |
string := string copyWith:secondChar. |
|
3517 |
||
3518 |
thirdChar := source peekOrNil. |
|
3519 |
thirdChar notNil ifTrue:[ |
|
3520 |
(self isSpecialOrExtendedSpecialCharacter:thirdChar) ifTrue:[ |
|
3521 |
p := source position. |
|
3522 |
source next. |
|
3523 |
fourthChar := source peekOrNil. |
|
3524 |
source position:p. |
|
3525 |
||
3526 |
(thirdChar == $-) ifTrue:[ |
|
3527 |
"special- look ahead if minus belongs to number following" |
|
3528 |
(fourthChar notNil and:[fourthChar isDigit]) ifTrue:[ |
|
3529 |
tokenName := token := string. |
|
3530 |
tokenType := #BinaryOperator. |
|
3531 |
self |
|
3532 |
warnPossibleIncompatibility:'add a space before ''-'' for compatibility with stc and other ST systems' |
|
3533 |
position:p+1 |
|
3534 |
to:p+1. |
|
3535 |
^ tokenType |
|
3536 |
]. |
|
3537 |
]. |
|
3538 |
thirdChar == $# ifTrue:[ |
|
3539 |
(fourthChar notNil and:[fourthChar isSeparator]) ifFalse:[ |
|
3540 |
"/ in sth. like ->#foo, the binop is NOT -># |
|
3541 |
tokenName := token := string. |
|
3542 |
tokenType := #BinaryOperator. |
|
3543 |
^ tokenType |
|
3544 |
]. |
|
3545 |
]. |
|
3546 |
source next. |
|
3547 |
string := string copyWith:thirdChar. |
|
3548 |
]. |
|
3549 |
]. |
|
3550 |
]. |
|
141 | 3551 |
]. |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
3552 |
tokenName := token := string. |
45 | 3553 |
tokenType := #BinaryOperator. |
3 | 3554 |
^ tokenType |
241
418eb41350d3
no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
3555 |
|
4116 | 3556 |
"Modified: / 12-02-2017 / 11:02:51 / cg" |
0 | 3557 |
! |
3558 |
||
1781 | 3559 |
nextString:delimiter |
4291 | 3560 |
"a quote has been scanned; scan the string (caring for doubled quotes)" |
1026 | 3561 |
|
4410 | 3562 |
source next. |
3563 |
^ self xnextString:delimiter escapeStyle:nil |
|
4334 | 3564 |
|
3565 |
" |
|
3566 |
old style ST80 string (no escapes): |
|
4611 | 3567 |
'hello\new world' |
4334 | 3568 |
|
3569 |
ParserFlags allowCStrings:true. |
|
4611 | 3570 |
|
4334 | 3571 |
new style STX c-string (c escapes): |
4611 | 3572 |
c'hello\nnew world' |
3573 |
c'hello\tnew world' |
|
3574 |
c'hello\<tab>new world' |
|
3575 |
c'a\0b' |
|
3576 |
c'a\n\\\nb' |
|
3577 |
c'a\r\\\nb' |
|
3578 |
||
4334 | 3579 |
ParserFlags allowCStrings:false. |
4432 | 3580 |
|
4571 | 3581 |
ParserFlags allowEStrings:true. |
3582 |
||
3583 |
new style strings with embedded expressions: |
|
4611 | 3584 |
e'Hello, this is a computed value: {3 factorial}' |
4571 | 3585 |
|
3586 |
ParserFlags allowEStrings:false. |
|
4432 | 3587 |
|
3588 |
ParserFlags allowRStrings:true. |
|
3589 |
||
3590 |
STX regex: |
|
4611 | 3591 |
r'a+b+' |
4432 | 3592 |
|
3593 |
ParserFlags allowRStrings:false. |
|
4334 | 3594 |
" |
3595 |
||
3596 |
"Created: / 01-08-2006 / 14:56:07 / cg" |
|
3597 |
"Modified: / 22-08-2006 / 14:10:26 / cg" |
|
4410 | 3598 |
"Modified: / 22-05-2019 / 20:32:14 / Claus Gittinger" |
4432 | 3599 |
"Modified (comment): / 03-06-2019 / 11:16:00 / Claus Gittinger" |
4571 | 3600 |
"Modified (comment): / 24-09-2019 / 11:52:28 / Stefan Vogel" |
4334 | 3601 |
! |
3602 |
||
3603 |
nextString:delimiter escapeStyle:escapeStyle |
|
3604 |
"a quote has been scanned; scan the string (caring for doubled quotes). |
|
3605 |
escapeStyle may be: |
|
4611 | 3606 |
nil - old style ST80 strings (no character escapes) |
3607 |
ot a single char string: |
|
3608 |
'c' - C-style escapes: |
|
3609 |
\n,\t,\r,\b,\xXX,\uXXXX,\UXXXXXX, |
|
3610 |
||
3611 |
'e' - C-style plus embedded escapes: |
|
3612 |
e'...{ expr1 } ... { exprN }' will generate: |
|
3613 |
'...%1 ... %N' bindWithArguments:{ expr1 . ... . exprN } |
|
3614 |
||
3615 |
'x' - extended-style escapes: |
|
3616 |
as yet unsupported |
|
3617 |
'r' - regex |
|
3618 |
as yet unsupported |
|
4345 | 3619 |
|
4334 | 3620 |
" |
3621 |
||
0 | 3622 |
source next. |
4410 | 3623 |
^ self xnextString:delimiter escapeStyle:escapeStyle |
546
db5ce842f64f
added #scanTokens for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
3624 |
|
4334 | 3625 |
"Created: / 08-02-2019 / 19:07:57 / Claus Gittinger" |
4410 | 3626 |
"Modified: / 22-05-2019 / 20:33:04 / Claus Gittinger" |
4414 | 3627 |
"Modified (comment): / 23-05-2019 / 08:52:46 / Claus Gittinger" |
141 | 3628 |
! |
3629 |
||
1656 | 3630 |
nextSymbolAfterHash |
3631 |
"helper: a # has been read - return #Symbol token or nil" |
|
3632 |
||
3948 | 3633 |
^ self nextSymbolAfterHash:'' |
3634 |
! |
|
3635 |
||
3636 |
nextSymbolAfterHash:prefix |
|
3637 |
"helper: #<prefix> has been read - return #Symbol token or nil" |
|
3638 |
||
2180
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
3639 |
|nextChar string part isNameSpaceSymbol allowUnderscoreInIdentifier |
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
3640 |
allowPeriodInSymbol| |
1656 | 3641 |
|
3642 |
nextChar := source peek. |
|
3948 | 3643 |
(nextChar isNil and:[prefix isEmpty]) ifTrue:[^ nil]. |
1656 | 3644 |
|
3645 |
allowUnderscoreInIdentifier := parserFlags allowUnderscoreInIdentifier. |
|
2180
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
3646 |
allowPeriodInSymbol := parserFlags allowPeriodInSymbol. |
1656 | 3647 |
isNameSpaceSymbol := false. |
3648 |
||
3948 | 3649 |
prefix isEmpty ifTrue:[ |
4611 | 3650 |
nextChar isLetter ifFalse:[ |
3651 |
((nextChar == $_) and:[allowUnderscoreInIdentifier]) ifFalse:[ |
|
3652 |
((nextChar == $.) and:[allowPeriodInSymbol]) ifFalse:[ |
|
3653 |
(nextChar isDigit and:[parserFlags allowSymbolsStartingWithDigit]) ifFalse:[ |
|
3654 |
"/ just for the better error message |
|
3655 |
(nextChar isNationalAlphaNumeric) ifTrue:[ |
|
3656 |
|errMsg| |
|
3657 |
||
3658 |
errMsg := 'Invalid character: ''' , nextChar asString , ''' ', '(' , (nextChar codePoint radixPrintStringRadix:16) , ').'. |
|
3659 |
errMsg := errMsg , '\\Notice:\ Only 7-bit ascii allowed (for compatibility with other Smalltalk dialects).' withCRs. |
|
3660 |
errMsg := errMsg , '\ If you need symbols with 8-bit characters, use the #''...'' form, or ''...'' asSymbol.' withCRs. |
|
3661 |
self syntaxError:errMsg position:tokenPosition to:source position+1. |
|
3662 |
]. |
|
3663 |
^ nil |
|
3664 |
] |
|
3665 |
] |
|
3666 |
] |
|
3667 |
]. |
|
2180
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
3668 |
]. |
1656 | 3669 |
|
3948 | 3670 |
string := prefix. |
2180
891d45ffad68
allowPeriodInSymbol - to read old st80/squeak code
Claus Gittinger <cg@exept.de>
parents:
2157
diff
changeset
|
3671 |
[ |
4611 | 3672 |
nextChar notNil |
3673 |
and:[nextChar isLetterOrDigit |
|
3674 |
or:[(nextChar == $_ and:[allowUnderscoreInIdentifier]) |
|
3675 |
or:[nextChar == $. and:[allowPeriodInSymbol and:[source peek isLetter]]]] |
|
3676 |
] |
|
1656 | 3677 |
] whileTrue:[ |
4611 | 3678 |
nextChar == $_ ifTrue:[ |
3679 |
part := nil. |
|
3680 |
] ifFalse:[ |
|
3681 |
(allowPeriodInSymbol and:[nextChar == $.]) ifTrue:[ |
|
3682 |
part := nil. |
|
3683 |
] ifFalse:[ |
|
3684 |
part := source nextAlphaNumericWord. |
|
3685 |
] |
|
3686 |
]. |
|
3687 |
part notNil ifTrue:[ |
|
3688 |
string := string , part. |
|
3689 |
]. |
|
3690 |
nextChar := source peek. |
|
3691 |
||
3692 |
((allowUnderscoreInIdentifier and:[nextChar == $_]) |
|
3693 |
or:[ allowPeriodInSymbol and:[nextChar == $.] ]) ifTrue:[ |
|
3694 |
nextChar == $_ ifTrue:[ |
|
3695 |
self warnUnderscoreAt:source position + 1. |
|
3696 |
] ifFalse:[ |
|
3697 |
self warnPeriodAt:source position + 1. |
|
3698 |
]. |
|
3699 |
[(nextChar == $_) or:[(allowPeriodInSymbol and:[nextChar == $.])]] whileTrue:[ |
|
3700 |
string := string copyWith:nextChar. |
|
3701 |
nextChar := source nextPeek. |
|
3702 |
(nextChar notNil and:[nextChar isLetterOrDigit]) ifTrue:[ |
|
3703 |
string := string , source nextAlphaNumericWord. |
|
3704 |
nextChar := source peek. |
|
3705 |
] ifFalse:[ |
|
3706 |
(allowPeriodInSymbol and:[string last == $.]) ifTrue:[ |
|
3707 |
peekChar := nextChar. |
|
3708 |
nextChar := $.. |
|
3709 |
string := string copyButLast:1. |
|
3710 |
tokenValue := token := string asSymbol. |
|
3711 |
tokenType := #Symbol. |
|
3712 |
^ tokenType |
|
3713 |
]. |
|
3714 |
]. |
|
3715 |
]. |
|
3716 |
]. |
|
3717 |
(nextChar == $:) ifFalse:[ |
|
3718 |
self markSymbolFrom:tokenPosition to:(source position). |
|
3719 |
tokenValue := token := string asSymbol. |
|
3720 |
tokenType := #Symbol. |
|
3721 |
^ tokenType |
|
3722 |
]. |
|
3723 |
string := string copyWith:nextChar. |
|
3724 |
nextChar := source nextPeek. |
|
3725 |
parserFlags allowLiteralNameSpaceSymbols ifTrue:[ |
|
3726 |
(nextChar == $:) ifTrue:[ |
|
3727 |
string := string copyWith:nextChar. |
|
3728 |
nextChar := source nextPeek. |
|
3729 |
isNameSpaceSymbol := true. |
|
3730 |
]. |
|
3731 |
]. |
|
4188 | 3732 |
]. |
1656 | 3733 |
tokenValue := token := string asSymbol. |
3734 |
tokenType := #Symbol. |
|
3735 |
^ tokenType |
|
4150 | 3736 |
|
3737 |
"Modified (format): / 18-06-2017 / 16:31:56 / cg" |
|
1656 | 3738 |
! |
3739 |
||
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
3740 |
nextToken |
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
3741 |
"return the next token from the source-stream" |
141 | 3742 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
3743 |
|skipping actionBlock v ch tok| |
141 | 3744 |
|
4529 | 3745 |
tokenLastEndPosition := source position+1. |
2612
6c04d60c1403
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2523
diff
changeset
|
3746 |
|
3405 | 3747 |
[ |
4611 | 3748 |
peekChar notNil ifTrue:[ |
3749 |
"/ kludge - should be called peekSym. |
|
3750 |
"/ used when xlating Foo.Bar into Foo::Bar |
|
3751 |
peekChar isSymbol ifTrue:[ |
|
3752 |
token := nil. |
|
3753 |
tokenType := peekChar. |
|
3754 |
peekChar := nil. |
|
3755 |
^ tokenType |
|
3756 |
]. |
|
3757 |
||
3758 |
(peekChar isSeparator or:[ peekChar codePoint == 16rFEFF ]) ifTrue:[ |
|
3759 |
peekChar == (Character cr) ifTrue:[ |
|
3760 |
lineNr := lineNr + 1. |
|
3761 |
]. |
|
3762 |
hereChar := peekChar. |
|
3763 |
peekChar := peekChar2. |
|
3764 |
peekChar2 := nil. |
|
3765 |
(hereChar == Character cr) ifTrue:[ |
|
3766 |
(self eolIsWhiteSpace) ifFalse:[ |
|
3767 |
token := nil. |
|
3768 |
tokenType := #EOL. |
|
3769 |
^ tokenType |
|
3770 |
]. |
|
3771 |
]. |
|
3772 |
]. |
|
3773 |
]. |
|
3774 |
||
3775 |
peekChar notNil ifTrue:[ |
|
3776 |
ch := peekChar. |
|
3777 |
peekChar := peekChar2. |
|
3778 |
peekChar2 := nil. |
|
3779 |
hereChar := nil. |
|
3780 |
] ifFalse:[ |
|
3781 |
skipping := true. |
|
3782 |
[skipping] whileTrue:[ |
|
3783 |
||
3784 |
outStream notNil ifTrue:[ |
|
3785 |
[ |
|
3786 |
hereChar := source peekOrNil. |
|
3787 |
(hereChar notNil |
|
3788 |
and:[(hereChar == Character space) or:[hereChar isSeparator]]) |
|
3789 |
] whileTrue:[ |
|
3790 |
source next. |
|
3791 |
outStream space. |
|
3792 |
outCol := outCol + 1. |
|
3793 |
hereChar == (Character cr) ifTrue:[ |
|
3794 |
self eolIsWhiteSpace ifFalse:[ |
|
3795 |
source isPositionable ifTrue:[ |
|
3796 |
tokenPosition := source position. |
|
3797 |
]. |
|
3798 |
token := nil. |
|
3799 |
tokenType := #EOL. |
|
3800 |
^ tokenType |
|
3801 |
]. |
|
3802 |
] |
|
3803 |
] |
|
3804 |
] ifFalse:[ |
|
3805 |
hereChar := source skipSeparatorsExceptCR. |
|
3806 |
]. |
|
3807 |
||
3808 |
hereChar isNil ifTrue:[ |
|
3809 |
skipping := false |
|
3810 |
] ifFalse:[ |
|
3811 |
hereChar == (Character cr) ifTrue:[ |
|
3812 |
lineNr := lineNr + 1. |
|
3813 |
source next. |
|
3814 |
outStream notNil ifTrue:[ |
|
3815 |
outStream cr. |
|
3816 |
outCol := 1 |
|
3817 |
]. |
|
3818 |
self eolIsWhiteSpace ifFalse:[ |
|
3819 |
source isPositionable ifTrue:[ |
|
3820 |
tokenPosition := source position. |
|
3821 |
]. |
|
3822 |
token := nil. |
|
3823 |
tokenType := #EOL. |
|
3824 |
^ tokenType |
|
3825 |
]. |
|
3826 |
] ifFalse:[ |
|
3827 |
hereChar == (Character return) ifTrue:[ |
|
3828 |
outStream notNil ifTrue:[ |
|
3829 |
outStream nextPut:hereChar. |
|
3830 |
outCol := 1 |
|
3831 |
]. |
|
3832 |
source next. |
|
3833 |
] ifFalse:[ |
|
3834 |
(self isCommentCharacter:hereChar) ifTrue:[ |
|
3835 |
"start of a comment" |
|
3836 |
||
3837 |
self skipComment. |
|
3838 |
hereChar := source peekOrNil. |
|
3839 |
] ifFalse:[ |
|
3840 |
skipping := false |
|
3841 |
] |
|
3842 |
] |
|
3843 |
] |
|
3844 |
]. |
|
3845 |
]. |
|
3846 |
hereChar isNil ifTrue:[ |
|
3847 |
source isPositionable ifTrue:[ |
|
3848 |
tokenPosition := source position + 1. |
|
3849 |
]. |
|
3850 |
token := nil. |
|
3851 |
tokenType := #EOF. |
|
3852 |
^ tokenType |
|
3853 |
]. |
|
3854 |
ch := hereChar |
|
3855 |
]. |
|
3856 |
source isPositionable ifTrue:[ |
|
3857 |
tokenPosition := source position + 1. |
|
3858 |
]. |
|
3859 |
tokenLineNr := lineNr. |
|
3860 |
||
3861 |
(v := ch codePoint) == 0 ifTrue:[ |
|
3862 |
v := Character space codePoint |
|
3863 |
]. |
|
3864 |
v <= 16rFF ifTrue:[ |
|
3865 |
actionBlock := actionArray at:v. |
|
3866 |
] ifFalse:[ |
|
3867 |
actionBlock := unicodeActions at:v ifAbsent:nil |
|
3868 |
]. |
|
3869 |
actionBlock notNil ifTrue:[ |
|
3870 |
tok := actionBlock value:self value:ch. |
|
3871 |
tok notNil ifTrue:[ |
|
3872 |
^ tok |
|
3873 |
]. |
|
3874 |
"/ a nil token means: continue reading |
|
3875 |
] ifFalse:[ |
|
3876 |
((ch isNationalLetter and:[parserFlags allowNationalCharactersInIdentifier]) |
|
3877 |
or:[ (ch == $§ and:[parserFlags allowParagraphInIdentifier]) |
|
3878 |
or:[ (ch isGreekLetter and:[parserFlags allowGreekCharactersInIdentifier]) |
|
3879 |
]]) ifTrue:[ |
|
3880 |
tok := self nextIdentifier. |
|
3881 |
tok notNil ifTrue:[ |
|
3882 |
^ tok |
|
3883 |
]. |
|
3884 |
"/ a nil token means: continue reading |
|
3885 |
] ifFalse:[ |
|
3886 |
^ self invalidCharacter:ch. |
|
3887 |
]. |
|
3888 |
] |
|
3405 | 3889 |
] loop. |
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
|
3890 |
|
2481 | 3891 |
"Modified: / 13-09-1995 / 12:56:14 / claus" |
2612
6c04d60c1403
More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2523
diff
changeset
|
3892 |
"Modified: / 27-07-2011 / 15:36:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4117 | 3893 |
"Modified: / 12-02-2017 / 11:27:59 / cg" |
4438 | 3894 |
"Modified: / 08-06-2019 / 14:59:14 / Claus Gittinger" |
141 | 3895 |
! |
3896 |
||
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
3897 |
nextToken:aCharacter |
1026 | 3898 |
"return a character token" |
3899 |
||
707
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
3900 |
tokenType := token := 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
|
3901 |
hereChar notNil ifTrue:[source next]. |
141 | 3902 |
^ 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
|
3903 |
|
707
2fe4b3a7708a
extracted keyword detection into a separate method for easier
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
3904 |
"Modified: / 13.5.1998 / 15:10:23 / cg" |
141 | 3905 |
! |
3906 |
||
1501
ca87aed7eb82
allowUnderline etc. are inst-flags
Claus Gittinger <cg@exept.de>
parents:
1497
diff
changeset
|
3907 |
nextUnderline |
3380 | 3908 |
"return either an identifier, or an underline (sometimes an assignment) token" |
1501
ca87aed7eb82
allowUnderline etc. are inst-flags
Claus Gittinger <cg@exept.de>
parents:
1497
diff
changeset
|
3909 |
|
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
3910 |
parserFlags allowUnderscoreInIdentifier ifTrue:[ |
4611 | 3911 |
^ self nextIdentifier |
1636
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
3912 |
]. |
98afdcdacde8
compilerflags separated into ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
1622
diff
changeset
|
3913 |
^ self nextToken:$_ |
1501
ca87aed7eb82
allowUnderline etc. are inst-flags
Claus Gittinger <cg@exept.de>
parents:
1497
diff
changeset
|
3914 |
! |
ca87aed7eb82
allowUnderline etc. are inst-flags
Claus Gittinger <cg@exept.de>
parents:
1497
diff
changeset
|
3915 |
|
264
f10298cba622
oops - corrupted version checked in
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
3916 |
skipComment |
4188 | 3917 |
"skip over a comment; |
3463 | 3918 |
handles ST/X eol comments (quote-slash) |
4173 | 3919 |
and multiline-delimiter comment (quote-less-less). |
3920 |
Multiline-delimiter comments start with ''<<TOKEN and end in a line which starts with TOKEN (quote-quote being a double quote here)" |
|
2983 | 3921 |
|
3922 |
|commentStream commentType commentText startPos endPos stillInComment anyNonBlank |
|
3456 | 3923 |
delimiter line| |
1653 | 3924 |
|
3925 |
anyNonBlank := false. |
|
141 | 3926 |
|
3927 |
saveComments ifTrue:[ |
|
4611 | 3928 |
commentStream := CharacterWriteStream on:''. |
3929 |
self beginComment. |
|
141 | 3930 |
]. |
3931 |
||
3932 |
outStream notNil ifTrue:[ |
|
4611 | 3933 |
outStream nextPut:Character doubleQuote. |
3934 |
outCol := outCol + 1 |
|
141 | 3935 |
]. |
3936 |
||
3268 | 3937 |
startPos := source position + 1. |
141 | 3938 |
source next. |
656
e4249b285fd8
using #peekOrNil makes it some 10% faster when scanning
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3939 |
hereChar := source peekOrNil. |
2983 | 3940 |
commentType := #regularComment. |
141 | 3941 |
|
3942 |
" |
|
3943 |
special ST/X addition: |
|
3944 |
a $/ right after the initial double quote makes it an up-to-end-of-line comment, |
|
3945 |
which is very useful to comment out parts of filed-in source code. |
|
3312 | 3946 |
Since this is non-standard, you loose compatibility with other Smalltalks, if you use it. |
3947 |
(however, it is so convenient - I don't want to miss it) |
|
3948 |
" |
|
1707
28a94a1701c2
more support for filein of ST/V code
Claus Gittinger <cg@exept.de>
parents:
1705
diff
changeset
|
3949 |
(hereChar == $/ and:[parserFlags allowSTXEOLComments]) ifTrue:[ |
4611 | 3950 |
hereChar := source nextPeek. |
3951 |
||
3952 |
self skipToEndOfLineRememberingIn:commentStream. |
|
3953 |
endPos := source position. |
|
3954 |
self markCommentFrom:startPos to:endPos+1. |
|
3955 |
commentType := #eolComment. |
|
3956 |
self warnSTXSpecialCommentAt:startPos to:endPos. |
|
3957 |
outStream notNil ifTrue:[ |
|
3958 |
outStream cr. |
|
3959 |
outCol := 1 |
|
3960 |
]. |
|
3961 |
"skip cr" |
|
3962 |
source next. |
|
141 | 3963 |
] ifFalse:[ |
4611 | 3964 |
(hereChar == $< and:[parserFlags allowSTXDelimiterComments]) ifTrue:[ |
3965 |
hereChar := source nextPeek. |
|
3966 |
(hereChar == $<) ifTrue:[ |
|
3967 |
" |
|
3968 |
another special ST/X addition: |
|
3969 |
a << right after the initial double quote makes it a token delimited comment, |
|
3970 |
which continues up to a line starting with the token. |
|
3971 |
This is very useful to comment out which contain any other type of comment. |
|
3972 |
Since this is non-standard, you loose compatibility with other Smalltalks, if you use it. |
|
3973 |
" |
|
3974 |
commentStream notNil ifTrue:[ |
|
3975 |
commentStream nextPutAll:'<<' |
|
3976 |
]. |
|
3977 |
hereChar := source nextPeek. |
|
3978 |
||
3979 |
delimiter := String streamContents:[:s | self skipToEndOfLineRememberingIn:s]. |
|
3980 |
delimiter := delimiter withoutSeparators. |
|
3981 |
delimiter isEmpty ifTrue:[ |
|
3982 |
self parseError:'invalid delimiter in comment'. |
|
3983 |
^ self |
|
3984 |
]. |
|
3985 |
((delimiter first isLetterOrUnderline) |
|
3986 |
and:[delimiter from:2 conform:[:ch | ch isLetterOrDigit]]) ifFalse:[ |
|
3987 |
"/ treat as regular comment |
|
3988 |
commentType := #regularComment. |
|
3989 |
source position:startPos. |
|
3990 |
] ifTrue:[ |
|
3991 |
"/ delimiter comment |
|
3992 |
hereChar == Character cr ifTrue:[ |
|
3993 |
hereChar := source nextPeek. |
|
3994 |
]. |
|
3995 |
commentStream notNil ifTrue:[ |
|
3996 |
commentStream nextPutLine:delimiter |
|
3997 |
]. |
|
3998 |
stillInComment := true. |
|
3999 |
[stillInComment and:[hereChar notNil]] whileTrue:[ |
|
4000 |
line := String streamContents:[:s | self skipToEndOfLineRememberingIn:s]. |
|
4001 |
commentStream notNil ifTrue:[ |
|
4002 |
commentStream nextPutLine:line |
|
4003 |
]. |
|
4004 |
hereChar == Character cr ifTrue:[ |
|
4005 |
hereChar := source nextPeek. |
|
4006 |
]. |
|
4007 |
stillInComment := (line startsWith:delimiter) not. |
|
4008 |
]. |
|
4009 |
stillInComment ifTrue:[ |
|
4010 |
self markCommentFrom:startPos to:(source collectionSize). |
|
4011 |
self warning:'unclosed comment (missing delimiter: "',delimiter,'")' position:startPos to:(source position + 1) |
|
4012 |
]. |
|
4013 |
self markCommentFrom:startPos to:(source position + 1). |
|
4014 |
commentType := #delimiterComment. |
|
4015 |
] |
|
4016 |
] ifFalse:[ |
|
4017 |
commentStream notNil ifTrue:[ |
|
4018 |
commentStream nextPut:$< |
|
4019 |
]. |
|
4020 |
]. |
|
4021 |
]. |
|
4022 |
||
4023 |
(commentType == #regularComment) ifTrue:[ |
|
4024 |
hereChar == ${ ifTrue:[ |
|
4025 |
" |
|
4026 |
special ST/X addition: |
|
4027 |
a ${ right after the initial double quote starts a directive |
|
4028 |
" |
|
4029 |
self parseDirective |
|
4030 |
]. |
|
4031 |
||
4032 |
stillInComment := true. |
|
4033 |
[stillInComment] whileTrue:[ |
|
4034 |
stillInComment := false. |
|
4035 |
||
4036 |
[hereChar notNil and:[hereChar ~~ (Character doubleQuote)]] whileTrue:[ |
|
4037 |
hereChar isSeparator ifFalse:[ anyNonBlank := true ]. |
|
4038 |
hereChar == (Character cr) ifTrue:[ |
|
4039 |
lineNr := lineNr + 1. |
|
4040 |
]. |
|
4041 |
commentStream notNil ifTrue:[ |
|
4042 |
commentStream nextPut:hereChar |
|
4043 |
]. |
|
4044 |
outStream notNil ifTrue:[ |
|
4045 |
outStream nextPut:hereChar. |
|
4046 |
outCol := outCol + 1 |
|
4047 |
]. |
|
4048 |
hereChar := source nextPeek |
|
4049 |
]. |
|
4050 |
||
4051 |
hereChar isNil ifTrue:[ |
|
4052 |
self markCommentFrom:startPos to:(source collectionSize). |
|
4053 |
self warning:'unclosed comment' position:startPos to:(source position + 1) |
|
4054 |
] ifFalse:[ |
|
4055 |
self markCommentFrom:startPos to:(source position + 1). |
|
4056 |
outStream notNil ifTrue:[ |
|
4057 |
outStream nextPut:(Character doubleQuote). |
|
4058 |
outCol := outCol + 1 |
|
4059 |
]. |
|
4060 |
]. |
|
4061 |
endPos := source position. |
|
4062 |
"skip final dQuote" |
|
4063 |
source next. |
|
4064 |
||
4065 |
(source peek == Character doubleQuote) ifTrue:[ |
|
4066 |
stillInComment := true. |
|
4067 |
hereChar := source nextPeek. |
|
4068 |
]. |
|
4069 |
]. |
|
4070 |
] |
|
141 | 4071 |
]. |
4072 |
||
4073 |
saveComments ifTrue:[ |
|
4611 | 4074 |
commentText := commentStream contents. |
4075 |
self endComment:commentText type:commentType start:startPos end:endPos. |
|
1653 | 4076 |
]. |
4077 |
||
3288 | 4078 |
ignoreWarnings ifFalse:[ |
4611 | 4079 |
parserFlags warnAboutBadComments ifTrue:[ |
4080 |
anyNonBlank ifFalse:[ |
|
4081 |
commentType == #regularComment ifTrue:[ |
|
4082 |
self isDoIt ifFalse:[ |
|
4083 |
self |
|
4084 |
warning:'empty comment' |
|
4085 |
doNotShowAgainAction:[ ParserFlags warnAboutBadComments: false ] |
|
4086 |
position:startPos to:endPos+1. |
|
4087 |
parserFlags warnAboutBadComments:false. |
|
4088 |
] |
|
4089 |
]. |
|
4090 |
]. |
|
4091 |
]. |
|
141 | 4092 |
]. |
4173 | 4093 |
|
4190 | 4094 |
"Modified: / 30-08-2017 / 09:58:02 / cg" |
2138 | 4095 |
! |
4096 |
||
4097 |
skipToEndOfLineRememberingIn:commentStreamOrNil |
|
4098 |
[hereChar notNil and:[hereChar ~~ Character cr]] whileTrue:[ |
|
4611 | 4099 |
commentStreamOrNil notNil ifTrue:[ |
4100 |
commentStreamOrNil nextPut:hereChar |
|
4101 |
]. |
|
4102 |
outStream notNil ifTrue:[ |
|
4103 |
outStream nextPut:hereChar. |
|
4104 |
outCol := outCol + 1 |
|
4105 |
]. |
|
4106 |
hereChar := source nextPeek. |
|
2138 | 4107 |
]. |
2983 | 4108 |
lineNr := lineNr + 1. |
4410 | 4109 |
! |
4110 |
||
4111 |
xnextString:delimiter escapeStyle:escapeStyle |
|
4112 |
"a quote has been scanned; scan the string (caring for doubled quotes). |
|
4113 |
escapeStyle may be: |
|
4611 | 4114 |
nil - old style ST80 strings (no character escapes) |
4115 |
or a single char string: |
|
4116 |
'c' - C-style escapes: |
|
4117 |
\n,\t,\r,\b,\xXX,\uXXXX,\UXXXXXX, |
|
4118 |
||
4119 |
'e' - C-style plus embedded escapes: |
|
4120 |
e'...{ expr1 } ... { exprN }' will generate: |
|
4121 |
'...%1 ... %N' bindWithArguments:{ expr1 . ... . exprN } |
|
4122 |
||
4123 |
'r' - regex |
|
4124 |
||
4125 |
'x' - extended-style escapes: |
|
4126 |
as yet unsupported |
|
4410 | 4127 |
" |
4128 |
||
4129 |
|nextChar string pos |
|
4130 |
index "{ Class: SmallInteger }" |
|
4131 |
len "{ Class: SmallInteger }" |
|
4414 | 4132 |
inString peekChar |
4432 | 4133 |
isCString isEString isRString| |
4414 | 4134 |
|
4135 |
isEString := (escapeStyle = 'e'). |
|
4136 |
isCString := (escapeStyle = 'c'). |
|
4432 | 4137 |
isRString := (escapeStyle = 'r'). |
4611 | 4138 |
|
4410 | 4139 |
string := String uninitializedNew:20. |
4140 |
len := 20. |
|
4141 |
index := 1. |
|
4142 |
pos := source position. |
|
4143 |
nextChar := source next. |
|
4144 |
inString := true. |
|
4145 |
||
4146 |
[inString] whileTrue:[ |
|
4611 | 4147 |
nextChar isNil ifTrue:[ |
4148 |
self syntaxError:'unexpected end-of-input in String' |
|
4149 |
position:pos to:(source position). |
|
4150 |
self markStringFrom:pos to:source position. |
|
4151 |
token := nil. |
|
4152 |
tokenType := #EOF. |
|
4153 |
^ tokenType |
|
4154 |
]. |
|
4155 |
(nextChar == Character cr) ifTrue:[ |
|
4156 |
lineNr := lineNr + 1 |
|
4157 |
] ifFalse:[ |
|
4158 |
(nextChar == delimiter) ifTrue:[ |
|
4159 |
(source peekOrNil == delimiter) ifTrue:[ |
|
4160 |
source next |
|
4161 |
] ifFalse:[ |
|
4162 |
inString := false |
|
4163 |
] |
|
4164 |
] ifFalse:[ |
|
4165 |
(escapeStyle notNil and:[isRString not]) ifTrue:[ |
|
4166 |
((nextChar == ${) and:[isEString]) ifTrue:[ |
|
4167 |
"/ bail out, to read one expression |
|
4168 |
tokenValue := token := string copyTo:(index - 1). |
|
4169 |
tokenType := #StringFragment. |
|
4170 |
^ tokenType |
|
4171 |
]. |
|
4172 |
(nextChar == $\) ifTrue:[ |
|
4173 |
peekChar := source peekOrNil. |
|
4174 |
peekChar notNil ifTrue:[ |
|
4175 |
source next. |
|
4176 |
nextChar := self escapeCharacterFor:peekChar escapeStyle:escapeStyle. |
|
4177 |
] |
|
4178 |
] |
|
4179 |
] |
|
4180 |
]. |
|
4181 |
]. |
|
4182 |
inString ifTrue:[ |
|
4183 |
nextChar notNil ifTrue:[ |
|
4184 |
nextChar codePoint > 255 ifTrue:[ |
|
4185 |
string bitsPerCharacter < nextChar bitsPerCharacter ifTrue:[ |
|
4186 |
nextChar codePoint > 16rFFFF ifTrue:[ |
|
4187 |
string := string asUnicode32String |
|
4188 |
] ifFalse:[ |
|
4189 |
string := string asUnicode16String. |
|
4190 |
]. |
|
4191 |
]. |
|
4192 |
]. |
|
4193 |
string at:index put:nextChar. |
|
4194 |
(index == len) ifTrue:[ |
|
4195 |
string := string , (string species new:len). |
|
4196 |
len := len * 2 |
|
4197 |
]. |
|
4198 |
index := index + 1. |
|
4199 |
]. |
|
4200 |
nextChar := source next |
|
4201 |
] |
|
4410 | 4202 |
]. |
4203 |
||
4204 |
tokenValue := token := string copyTo:(index - 1). |
|
4432 | 4205 |
tokenType := isRString ifTrue:[#RegexString] ifFalse:[#String]. |
4410 | 4206 |
^ tokenType |
4207 |
||
4208 |
"Created: / 22-05-2019 / 20:31:36 / Claus Gittinger" |
|
4432 | 4209 |
"Modified: / 03-06-2019 / 11:10:24 / Claus Gittinger" |
648 | 4210 |
! ! |
4211 |
||
4212 |
!Scanner::Comment methodsFor:'accessing'! |
|
4213 |
||
4214 |
commentString |
|
4215 |
"return the value of the instance variable 'commentString' (automatically generated)" |
|
4216 |
||
4217 |
^ commentString |
|
4218 |
||
4219 |
"Created: / 17.2.1998 / 14:44:33 / cg" |
|
4220 |
! |
|
4221 |
||
4222 |
commentString:something |
|
4223 |
"set the value of the instance variable 'commentString' (automatically generated)" |
|
4224 |
||
4225 |
commentString := something. |
|
4226 |
||
4227 |
"Created: / 17.2.1998 / 14:44:33 / cg" |
|
4228 |
! |
|
4229 |
||
1596 | 4230 |
commentString:commentStringArg commentType:commentTypeArg |
4231 |
commentString := commentStringArg. |
|
4232 |
commentType := commentTypeArg. |
|
4233 |
||
4234 |
"Created: / 17.2.1998 / 14:44:33 / cg" |
|
4235 |
! |
|
4236 |
||
648 | 4237 |
commentType |
4238 |
^ commentType |
|
4239 |
||
4240 |
"Created: / 17.2.1998 / 14:44:33 / cg" |
|
4241 |
! |
|
4242 |
||
4243 |
commentType:something |
|
4244 |
commentType := something. |
|
4245 |
||
4246 |
"Created: / 17.2.1998 / 14:44:33 / cg" |
|
4247 |
! |
|
4248 |
||
3551 | 4249 |
endPosition |
4250 |
^ endPosition |
|
4251 |
! |
|
4252 |
||
4253 |
endPosition:something |
|
4254 |
endPosition := something. |
|
4255 |
! |
|
4256 |
||
4257 |
startPosition |
|
4258 |
^ startPosition |
|
4259 |
! |
|
4260 |
||
4261 |
startPosition:something |
|
4262 |
startPosition := something. |
|
4263 |
! |
|
4264 |
||
4188 | 4265 |
startPosition:startPositionArg endPosition:endPositionArg |
3551 | 4266 |
startPosition := startPositionArg. |
4267 |
endPosition := endPositionArg. |
|
4268 |
! |
|
4269 |
||
648 | 4270 |
string |
4271 |
^ commentString |
|
4272 |
||
4273 |
"Created: / 17.2.1998 / 14:49:52 / cg" |
|
0 | 4274 |
! ! |
141 | 4275 |
|
1580 | 4276 |
!Scanner::Comment methodsFor:'converting'! |
4277 |
||
4278 |
asString |
|
4279 |
^ commentString. |
|
1583 | 4280 |
! |
4281 |
||
4282 |
asStringCollection |
|
4283 |
^ commentString asStringCollection. |
|
1580 | 4284 |
! ! |
4285 |
||
1651 | 4286 |
!Scanner::Comment methodsFor:'queries'! |
4287 |
||
4288 |
isEndOfLineComment |
|
4289 |
^ commentType == #eolComment |
|
4290 |
! ! |
|
4291 |
||
1596 | 4292 |
!Scanner::Directive class methodsFor:'instance creation'! |
4293 |
||
4294 |
newClassDirective |
|
4295 |
^ ClassDirective new |
|
4296 |
! |
|
4297 |
||
4298 |
newClassHintDirective |
|
4299 |
^ ClassHintDirective new |
|
4300 |
! ! |
|
4301 |
||
1598 | 4302 |
!Scanner::Directive methodsFor:'queries'! |
4303 |
||
4304 |
isClassHintDirective |
|
4305 |
^ false |
|
4306 |
! ! |
|
4307 |
||
1596 | 4308 |
!Scanner::Directive::ClassDirective methodsFor:'accessing'! |
4309 |
||
4310 |
className |
|
4311 |
^ className |
|
4312 |
! |
|
4313 |
||
4314 |
className:something |
|
4315 |
className := something. |
|
4316 |
! ! |
|
4317 |
||
1598 | 4318 |
!Scanner::Directive::ClassHintDirective methodsFor:'queries'! |
4319 |
||
4320 |
isClassHintDirective |
|
4321 |
^ true |
|
4322 |
! ! |
|
4323 |
||
359
5c3718455360
support for nameSpaces (space::name)
Claus Gittinger <cg@exept.de>
parents:
313
diff
changeset
|
4324 |
!Scanner class methodsFor:'documentation'! |
148 | 4325 |
|
2740 | 4326 |
version |
3695 | 4327 |
^ '$Header$' |
2740 | 4328 |
! |
4329 |
||
2290 | 4330 |
version_CVS |
3695 | 4331 |
^ '$Header$' |
148 | 4332 |
! ! |
1321 | 4333 |
|
3056 | 4334 |
|
141 | 4335 |
Scanner initialize! |