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