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