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