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