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