author | Claus Gittinger <cg@exept.de> |
Sat, 13 Jul 2019 16:02:10 +0200 | |
changeset 18898 | e786d72d82ef |
parent 18318 | ae7c57af448f |
child 19032 | f79f6e7937ee |
permissions | -rw-r--r-- |
18318 | 1 |
"{ Encoding: utf8 }" |
2 |
||
10022 | 3 |
" |
10067 | 4 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
5 |
All Rights Reserved |
|
10022 | 6 |
|
10067 | 7 |
Permission is hereby granted, free of charge, to any person |
8 |
obtaining a copy of this software and associated documentation |
|
9 |
files (the 'Software'), to deal in the Software without |
|
10 |
restriction, including without limitation the rights to use, |
|
11 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
12 |
copies of the Software, and to permit persons to whom the |
|
13 |
Software is furnished to do so, subject to the following |
|
14 |
conditions: |
|
15 |
||
16 |
The above copyright notice and this permission notice shall be |
|
17 |
included in all copies or substantial portions of the Software. |
|
18 |
||
19 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
20 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
21 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
22 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
23 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
24 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
25 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
26 |
OTHER DEALINGS IN THE SOFTWARE. |
|
10022 | 27 |
" |
28 |
"{ Package: 'stx:libtool' }" |
|
29 |
||
15446 | 30 |
"{ NameSpace: Smalltalk }" |
31 |
||
10022 | 32 |
SyntaxHighlighter subclass:#SyntaxHighlighter2 |
13844 | 33 |
instanceVariableNames:'elements lastVariableElements lastSelectorElement |
34 |
ignoreBadIdentifier' |
|
10022 | 35 |
classVariableNames:'' |
36 |
poolDictionaries:'' |
|
37 |
category:'Interface-CodeView-Syntax' |
|
38 |
! |
|
39 |
||
40 |
!SyntaxHighlighter2 class methodsFor:'documentation'! |
|
41 |
||
42 |
copyright |
|
43 |
" |
|
10067 | 44 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
45 |
All Rights Reserved |
|
46 |
||
47 |
Permission is hereby granted, free of charge, to any person |
|
48 |
obtaining a copy of this software and associated documentation |
|
49 |
files (the 'Software'), to deal in the Software without |
|
50 |
restriction, including without limitation the rights to use, |
|
51 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
52 |
copies of the Software, and to permit persons to whom the |
|
53 |
Software is furnished to do so, subject to the following |
|
54 |
conditions: |
|
10022 | 55 |
|
10067 | 56 |
The above copyright notice and this permission notice shall be |
57 |
included in all copies or substantial portions of the Software. |
|
58 |
||
59 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
60 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
61 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
62 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
63 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
64 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
65 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
66 |
OTHER DEALINGS IN THE SOFTWARE. |
|
10022 | 67 |
" |
15446 | 68 |
! |
69 |
||
70 |
documentation |
|
71 |
" |
|
72 |
A slightly improved syntax highlighter. |
|
73 |
||
74 |
In addition to the inherited colorization, this one also remembers |
|
75 |
so called 'syntax elements' (variable tokens and selectors) and remembers |
|
76 |
them in a list. |
|
77 |
This can be later used by the codeView to highlight uses of a clicked-on |
|
78 |
variable or a clicked-on selector. |
|
79 |
Also this list could (but is not, at the moment) be used to forward/backward |
|
80 |
search for the next use of some variable. |
|
81 |
||
82 |
[caveat:] |
|
83 |
This code has a smell: there is a lot of code duplication, |
|
84 |
and most can be moved to the superclass. Actually, there is propably no |
|
85 |
reason to have both classes around, so why not integrate all into the superclass. |
|
86 |
" |
|
10022 | 87 |
! ! |
88 |
||
17858 | 89 |
!SyntaxHighlighter2 class methodsFor:'api highlighting'! |
12636 | 90 |
|
91 |
formatClassDefinition:aString in:aClass elementsInto: elements |
|
92 |
"format (recolor) a class definition expression in a given class. |
|
93 |
Return the text containing font changes and color information." |
|
94 |
||
95 |
^ self formatExpression:aString in:aClass elementsInto: elements |
|
96 |
||
97 |
"Created: / 10-04-2011 / 18:18:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
98 |
! |
|
99 |
||
100 |
formatExpression:aString in:aClass elementsInto: elements |
|
101 |
"format (recolor) an expression in a given class. |
|
102 |
Return the text containing font changes and color information." |
|
103 |
||
15446 | 104 |
"/ cg: I smell a wumpus: I don't think, all of this must be redefined - most is already there in the superclass. |
105 |
||
106 |
|parser tree text| |
|
13844 | 107 |
|
108 |
aString isNil ifTrue:[^ nil]. |
|
109 |
||
110 |
parser := self for:(ReadStream on:aString string) in:aClass. |
|
111 |
parser elements: elements. |
|
112 |
parser ignoreErrors:true. |
|
113 |
parser ignoreWarnings:true. |
|
114 |
parser sourceText:(text := aString string asText). |
|
115 |
"/ use an array here - this can be changed much faster using #at:put: |
|
116 |
text emphasisCollection:(Array new:aString size). |
|
117 |
||
118 |
parser nextToken. |
|
15580 | 119 |
[ |
120 |
tree := parser "expression"statementList. |
|
121 |
] on:ParseError do:[ |
|
122 |
tree := #Error |
|
123 |
]. |
|
13844 | 124 |
"/ now, convert the emphasis-array to a runArray |
125 |
text emphasisCollection:(text emphasis asRunArray). |
|
126 |
||
127 |
tree == #Error ifTrue:[ |
|
15446 | 128 |
^ self colorize:text forErrorAtPosition:parser sourceStream position withOriginal:aString |
13844 | 129 |
]. |
130 |
^ text |
|
12636 | 131 |
|
132 |
" |
|
133 |
self |
|
14299 | 134 |
formatExpression:'(1 + 2) max:5' |
135 |
in:UndefinedObject |
|
10022 | 136 |
" |
13844 | 137 |
|
138 |
"Created: / 25-07-2010 / 08:56:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
139 |
"Modified: / 25-07-2010 / 10:57:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10022 | 140 |
! |
141 |
||
10150
3792ee8840ea
added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents:
10067
diff
changeset
|
142 |
formatMethod:aMethodOrNil source:aString in:aClass using:preferencesOrNil elementsInto: elements |
3792ee8840ea
added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents:
10067
diff
changeset
|
143 |
"format (recolor) a method in a given class. |
3792ee8840ea
added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents:
10067
diff
changeset
|
144 |
Return the text containing font changes and color information." |
3792ee8840ea
added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents:
10067
diff
changeset
|
145 |
|
15446 | 146 |
"/ cg: I smell a wumpus: I don't think, all of this must be redefined - most is already there in the superclass. |
147 |
||
148 |
|highlighter tree newText| |
|
10022 | 149 |
|
150 |
aString isNil ifTrue:[^ nil]. |
|
151 |
||
152 |
Error handle:[:ex | |
|
15446 | 153 |
"/ Transcript showCR:ex description. |
10022 | 154 |
(self parseErrorSignal handles:ex) ifFalse:[ |
15446 | 155 |
ex creator isHandled ifTrue:[ |
156 |
"/ Transcript showCR:'handled'. |
|
157 |
ex reject. |
|
158 |
]. |
|
10022 | 159 |
"Parse error may happen when re-formatting incomplete code while editing" |
160 |
('SyntaxHighlighter [info]: error during highlight: ' , ex description) infoPrintCR. |
|
161 |
"/ ex suspendedContext fullPrintAll. |
|
162 |
]. |
|
15446 | 163 |
highlighter notNil ifTrue:[ |
164 |
^ self colorize:(newText ? aString) forErrorAtPosition:highlighter sourceStream position withOriginal:aString |
|
165 |
]. |
|
10022 | 166 |
^ aString |
167 |
] do:[ |
|
15446 | 168 |
|sourceString| |
169 |
||
170 |
sourceString := aString string. |
|
18318 | 171 |
newText := sourceString asUnicodeString asText. |
15446 | 172 |
"/ use an array here (instead of the RunArray) - this can be changed much faster using #at:put: |
173 |
newText emphasisCollection:(Array new:sourceString size). |
|
174 |
||
175 |
highlighter := self for:(ReadStream on:sourceString) in:aClass. |
|
10022 | 176 |
highlighter elements: elements. |
177 |
preferencesOrNil notNil ifTrue:[highlighter preferences:preferencesOrNil]. |
|
178 |
"/ highlighter ignoreErrors:true. |
|
179 |
highlighter ignoreWarnings:true. |
|
15446 | 180 |
highlighter sourceText:newText. |
10022 | 181 |
|
182 |
tree := highlighter parseMethod. |
|
15446 | 183 |
newText := highlighter sourceText. "/ might have changed identity |
10022 | 184 |
"/ now, convert the emphasis-array to a runArray |
15446 | 185 |
newText emphasisCollection:(newText emphasis asRunArray). |
10022 | 186 |
|
187 |
tree == #Error ifTrue:[ |
|
15446 | 188 |
^ self colorize:newText forErrorAtPosition:highlighter sourceStream position withOriginal:aString |
189 |
]. |
|
190 |
^ newText |
|
191 |
] |
|
10022 | 192 |
|
193 |
" |
|
15446 | 194 |
self formatMethod:'foo |
10022 | 195 |
^ self bar:''hello''. |
196 |
||
197 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
198 |
' |
|
199 |
in:UndefinedObject |
|
200 |
" |
|
201 |
||
202 |
"Modified: / 22-08-2006 / 13:32:04 / cg" |
|
10150
3792ee8840ea
added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents:
10067
diff
changeset
|
203 |
"Created: / 05-07-2011 / 10:39:21 / cg" |
13844 | 204 |
"Modified: / 28-05-2013 / 22:45:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
18318 | 205 |
"Modified: / 04-08-2018 / 19:01:50 / Claus Gittinger" |
17858 | 206 |
! ! |
207 |
||
208 |
!SyntaxHighlighter2 class methodsFor:'highlighting'! |
|
209 |
||
210 |
format:aString parsingWith:aBlock in:aClass elementsInto:elements |
|
211 |
"common code for formatStatementList, formatExpression, ... |
|
212 |
format (recolor) whatever is parsed in aBlock (within the context of a given class). |
|
213 |
Return the text containing font changes and color information. |
|
214 |
As a side effect, put syntax elements into the passed in elements container |
|
215 |
(for element-highlighting in codeView2)" |
|
216 |
||
217 |
"/ cg: I smell a wumpus: I don't think, all of this must be redefined - most is already there in the superclass. |
|
218 |
||
219 |
|parser tree text| |
|
220 |
||
221 |
aString isNil ifTrue:[^ nil]. |
|
222 |
||
223 |
parser := self for:(ReadStream on:aString string) in:aClass. |
|
224 |
parser elements: elements. |
|
225 |
parser ignoreErrors:true. |
|
226 |
parser ignoreWarnings:true. |
|
227 |
parser sourceText:(text := aString string asText). |
|
228 |
"/ use an array here - this can be changed much faster using #at:put: |
|
229 |
text emphasisCollection:(Array new:aString size). |
|
230 |
||
231 |
parser nextToken. |
|
232 |
tree := aBlock value:parser. |
|
233 |
"/ now, convert the emphasis-array to a runArray |
|
234 |
text emphasisCollection:(text emphasis asRunArray). |
|
235 |
||
236 |
tree == #Error ifTrue:[ |
|
237 |
^ self colorize:text forErrorAtPosition:parser sourceStream position withOriginal:aString |
|
238 |
]. |
|
239 |
^ text |
|
240 |
||
241 |
" |
|
242 |
self |
|
243 |
formatStatementList:'(1 + 2) max:5. 1 + 2' |
|
244 |
in:UndefinedObject |
|
245 |
elementsInto:(OrderedCollection new). |
|
246 |
" |
|
12636 | 247 |
! |
248 |
||
249 |
formatStatementList:aString in:aClass elementsInto: elements |
|
250 |
"format (recolor) a statement list in a given class. |
|
251 |
Return the text containing font changes and color information." |
|
252 |
||
253 |
^ self |
|
254 |
format:aString parsingWith:[:parser | parser statementList] |
|
255 |
in:aClass elementsInto:elements |
|
256 |
||
257 |
" |
|
258 |
self |
|
259 |
formatStatementList:'(1 + 2) max:5. 1 + 2' |
|
260 |
in:UndefinedObject |
|
261 |
elementsInto:(OrderedCollection new). |
|
262 |
" |
|
10022 | 263 |
! ! |
264 |
||
265 |
!SyntaxHighlighter2 methodsFor:'accessing'! |
|
266 |
||
267 |
elements |
|
268 |
^ elements |
|
269 |
! |
|
270 |
||
15456 | 271 |
elements:aParseTreeIndexCollection |
10633 | 272 |
"the element collection, to collect variables, selectors etc. into" |
273 |
||
15456 | 274 |
elements := aParseTreeIndexCollection. |
10633 | 275 |
|
276 |
"Modified (comment): / 21-08-2011 / 09:13:31 / cg" |
|
13844 | 277 |
! |
278 |
||
279 |
tree: aParseNode |
|
280 |
super tree: aParseNode. |
|
281 |
elements tree: aParseNode |
|
282 |
||
283 |
"Created: / 16-02-2012 / 09:56:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10022 | 284 |
! ! |
285 |
||
286 |
!SyntaxHighlighter2 methodsFor:'initialization'! |
|
287 |
||
288 |
initialize |
|
289 |
||
17371 | 290 |
<modifier: #super> "must be called if redefined" |
291 |
||
10022 | 292 |
super initialize. |
13844 | 293 |
elements := ParseTreeIndex new. |
10633 | 294 |
lastVariableElements := Dictionary new. |
10022 | 295 |
|
296 |
"Created: / 14-02-2010 / 13:08:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
13844 | 297 |
"Modified: / 16-02-2012 / 09:59:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
17371 | 298 |
"Modified: / 08-02-2017 / 00:31:42 / cg" |
10022 | 299 |
! ! |
300 |
||
301 |
!SyntaxHighlighter2 methodsFor:'parsing-expressions'! |
|
302 |
||
13844 | 303 |
_binaryExpressionFor:receiverArg |
304 |
"parse a binary-expression; return a node-tree, nil or #Error" |
|
305 |
||
306 |
|receiver expr arg sel pos1 pos2 lno| |
|
307 |
||
308 |
receiver := receiverArg. |
|
309 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
310 |
||
311 |
"special kludge: since Scanner cannot know if -digit is a binary |
|
312 |
expression or a negative constant, handle cases here" |
|
313 |
||
314 |
[(tokenType == #BinaryOperator) |
|
315 |
or:[(tokenType == $|) |
|
316 |
or:[(tokenType == $^ and:[parserFlags allowCaretAsBinop]) |
|
14384 | 317 |
or:[((tokenType == #Integer) or:[tokenType == #Float]) |
318 |
and:[tokenValue < 0]]]] |
|
13844 | 319 |
] whileTrue:[ |
14384 | 320 |
"/ kludge alarm: in a function-call argList, #, is not a binarySelector |
321 |
inFunctionCallArgument == true ifTrue:[ |
|
322 |
((tokenType == #BinaryOperator) and:[tokenName = ',']) ifTrue:[ |
|
323 |
^ receiver |
|
324 |
]. |
|
325 |
]. |
|
13844 | 326 |
|
14384 | 327 |
pos1 := tokenPosition. |
328 |
lno := tokenLineNr. |
|
13844 | 329 |
|
14384 | 330 |
"/ kludge alarm: bar, caret and minus are not scanned as binop |
331 |
(tokenType == $|) ifTrue:[ |
|
332 |
sel := '|'. |
|
333 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition. |
|
334 |
self nextToken. |
|
335 |
] ifFalse:[ |
|
336 |
(tokenType == $^) ifTrue:[ |
|
337 |
sel := '^'. |
|
338 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition. |
|
339 |
self nextToken. |
|
340 |
] ifFalse:[ |
|
341 |
(tokenType == #BinaryOperator) ifTrue:[ |
|
342 |
sel := tokenName. |
|
343 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1). |
|
344 |
self nextToken |
|
345 |
] ifFalse:[ |
|
346 |
sel := '-'. |
|
347 |
token := tokenValue := tokenValue negated. |
|
348 |
tokenPosition := tokenPosition + 1. "/ to skip the sign |
|
349 |
] |
|
350 |
]. |
|
351 |
]. |
|
13844 | 352 |
|
14384 | 353 |
pos2 := pos1 + sel size - 1. |
354 |
self markSelector:sel from:pos1 to:pos2 receiverNode:receiver. |
|
355 |
lastSelectorElement := nil. |
|
13844 | 356 |
|
14384 | 357 |
arg := self unaryExpression. |
358 |
(arg == #Error) ifTrue:[^ #Error]. |
|
13844 | 359 |
|
14384 | 360 |
expr := BinaryNode receiver:receiver selector:sel arg:arg fold:foldConstants. |
361 |
expr isErrorNode ifTrue:[ |
|
362 |
self parseError:(expr errorString) position:pos1 to:tokenPosition. |
|
363 |
self clearErrorFlag. "ok, user wants it - so he'll get it" |
|
364 |
expr := BinaryNode receiver:receiver selector:sel arg:arg fold:nil. |
|
365 |
]. |
|
366 |
expr lineNumber:lno. |
|
367 |
expr selectorPosition:pos1. |
|
13844 | 368 |
|
14384 | 369 |
self checkPlausibilityOf:expr from:pos1 to:pos2. |
370 |
parseForCode ifFalse:[ |
|
371 |
self rememberSelectorUsed:sel receiver:receiver |
|
372 |
]. |
|
373 |
receiver := expr. "/ for next message |
|
13844 | 374 |
]. |
375 |
^ receiver |
|
376 |
||
377 |
"Modified: / 09-01-1998 / 19:05:18 / stefan" |
|
378 |
"Modified: / 14-02-2010 / 17:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
379 |
"Modified: / 19-01-2012 / 10:46:49 / cg" |
|
380 |
"Created: / 16-02-2012 / 21:54:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
381 |
! |
|
382 |
||
383 |
_keywordExpressionFor:receiverArg |
|
384 |
"parse a keyword-expression; return a node-tree, nil or #Error. |
|
385 |
||
386 |
keywordExpression ::= binaryexpression |
|
14384 | 387 |
| { KEYWORD-PART binaryExpression } |
13844 | 388 |
" |
389 |
||
390 |
|expr receiver sel arg args posR1 posR2 pos1 pos2 lno positions constVal| |
|
391 |
||
392 |
receiver := receiverArg. |
|
393 |
posR1 := tokenPosition. |
|
394 |
(tokenType == #Keyword) ifFalse:[^ receiver]. |
|
395 |
||
396 |
pos1 := posR2 := tokenPosition. |
|
397 |
pos2 := tokenPosition + tokenName size - 1. |
|
398 |
positions := OrderedCollection with:(pos1 to:pos2). |
|
399 |
sel := tokenName. |
|
400 |
lno := tokenLineNr. |
|
401 |
self nextToken. |
|
402 |
arg := self binaryExpression. |
|
403 |
(arg == #Error) ifTrue:[^ #Error]. |
|
404 |
args := Array with:arg. |
|
405 |
[tokenType == #Keyword] whileTrue:[ |
|
14384 | 406 |
sel := sel , tokenName. |
407 |
pos2 := tokenPosition + tokenName size - 1. |
|
408 |
positions add:(tokenPosition to:pos2). |
|
409 |
self nextToken. |
|
410 |
arg := self binaryExpression. |
|
411 |
(arg == #Error) ifTrue:[^ #Error]. |
|
412 |
args := args copyWith:arg. |
|
13844 | 413 |
]. |
414 |
||
415 |
positions do:[:p | |
|
14384 | 416 |
self markSelector:sel from:p start to:p stop receiverNode:receiver. |
13844 | 417 |
]. |
418 |
lastSelectorElement := nil. |
|
419 |
sel := self selectorCheck:sel for:receiver positions:positions. |
|
420 |
||
421 |
ignoreWarnings ifFalse:[ |
|
14384 | 422 |
(Class definitionSelectors includes:sel) ifTrue:[ |
423 |
(receiver isVariable and:[receiver isUndeclared]) ifTrue:[ |
|
424 |
"this is not an error - the undefined class may be loaded after this code!!" |
|
425 |
self warning:('as yet undefined superclass: ' , receiver name) position:pos1 to:pos2. |
|
426 |
]. |
|
427 |
]. |
|
13844 | 428 |
]. |
429 |
||
430 |
expr := MessageNode receiver:receiver selector:sel args:args fold:foldConstants. |
|
431 |
expr isErrorNode ifTrue:[ |
|
14384 | 432 |
self parseError:(expr errorString) position:pos1 to:pos2. |
433 |
self clearErrorFlag. "ok, user wants it - so he'll get it" |
|
434 |
expr := MessageNode receiver:receiver selector:sel args:args fold:nil. |
|
13844 | 435 |
]. |
436 |
expr lineNumber:lno. |
|
437 |
self checkPlausibilityOf:expr from:pos1 to:pos2. |
|
438 |
parseForCode ifFalse:[ |
|
14384 | 439 |
self rememberSelectorUsed:sel receiver:receiver |
13844 | 440 |
]. |
441 |
||
442 |
"/ (contextToEvaluateIn isNil and:[selfValue isNil]) ifTrue:[ "/ do not check this for doits |
|
443 |
"/ receiver isSuper ifTrue:[ |
|
444 |
"/ sel ~= selector ifTrue:[ |
|
445 |
"/ self warnCommonMistake:'possible bad super message (selector should be same as in current method) ?' |
|
446 |
"/ position:posR1 to:posR2-1 |
|
447 |
"/ ]. |
|
448 |
"/ ]. |
|
449 |
"/ ]. |
|
450 |
"/ |
|
451 |
||
452 |
(sel = #ifTrue: or:[sel = #ifFalse: or:[sel = #ifTrue:ifFalse: or:[sel = #ifFalse:ifTrue:]]]) ifTrue:[ |
|
14384 | 453 |
(expr receiver withConstantValueDo:[:val | constVal := val]) ifTrue:[ |
454 |
|indexOfArgNotExecuted| |
|
13844 | 455 |
|
14384 | 456 |
"/ receiver evaluates to a constant |
457 |
constVal == true ifTrue:[ |
|
458 |
(sel startsWith: #ifFalse:) ifTrue:[ |
|
459 |
indexOfArgNotExecuted := 1. |
|
460 |
] ifFalse:[ |
|
461 |
indexOfArgNotExecuted := 2. |
|
462 |
] |
|
463 |
]. |
|
464 |
constVal == false ifTrue:[ |
|
465 |
(sel startsWith: #ifTrue:) ifTrue:[ |
|
466 |
indexOfArgNotExecuted := 1. |
|
467 |
] ifFalse:[ |
|
468 |
indexOfArgNotExecuted := 2. |
|
469 |
] |
|
470 |
]. |
|
471 |
indexOfArgNotExecuted == 2 ifTrue:[ |
|
472 |
args size == 1 ifTrue:[ indexOfArgNotExecuted := nil] |
|
473 |
]. |
|
13844 | 474 |
|
14384 | 475 |
indexOfArgNotExecuted notNil ifTrue:[ |
476 |
|argIsNotExecuted| |
|
13844 | 477 |
|
14384 | 478 |
"/ self warning:'receiver is constant; arg',indexOfArgNotExecuted printString,' is never executed' position:pos1 to:tokenPosition. |
479 |
argIsNotExecuted := expr args at:indexOfArgNotExecuted. |
|
14489 | 480 |
argIsNotExecuted realNode isBlockNode ifTrue:[ |
14384 | 481 |
self markCommentFrom:argIsNotExecuted startPosition to:argIsNotExecuted endPosition. |
482 |
]. |
|
483 |
]. |
|
484 |
]. |
|
13844 | 485 |
]. |
486 |
||
487 |
(ignoreErrors or:[ignoreWarnings]) ifFalse:[ |
|
14384 | 488 |
(sel = #and: or:[sel = #or:]) ifTrue:[ |
489 |
expr arg1 isBlock ifFalse:[ |
|
490 |
(expr arg1 isVariable |
|
491 |
and:[ (expr arg1 name asLowercase includesString:'block')]) ifFalse:[ |
|
492 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?' |
|
493 |
position:pos2+1 to:tokenPosition-1 |
|
494 |
] |
|
495 |
]. |
|
496 |
^ expr. |
|
497 |
]. |
|
13844 | 498 |
|
14384 | 499 |
(sel = #whileTrue: or:[sel = #whileFalse:]) ifTrue:[ |
500 |
expr receiver isBlock ifFalse:[ |
|
501 |
(expr receiver isVariable |
|
502 |
and:[ (expr receiver name asLowercase includesString:'block')]) ifFalse:[ |
|
503 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?' |
|
504 |
position:pos1 to:pos2 |
|
505 |
] |
|
506 |
]. |
|
507 |
^ expr. |
|
508 |
]. |
|
13844 | 509 |
|
14384 | 510 |
(sel = #ifTrue: or:[sel = #ifFalse:]) ifTrue:[ |
511 |
expr receiver isMessage ifTrue:[ |
|
512 |
(expr receiver selector = #whileTrue or:[expr receiver selector = #whileFalse]) ifTrue:[ |
|
513 |
self warnCommonMistake:'strange receiver expression' |
|
514 |
position:pos1 to:pos2 |
|
515 |
]. |
|
516 |
]. |
|
517 |
^ expr |
|
518 |
]. |
|
13844 | 519 |
]. |
520 |
||
521 |
^ expr. |
|
522 |
||
523 |
"Modified: / 14-02-2010 / 17:58:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
524 |
"Modified: / 19-01-2012 / 10:47:01 / cg" |
|
525 |
"Created: / 16-02-2012 / 21:54:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
526 |
! |
|
527 |
||
528 |
_unaryExpressionFor:receiverArg |
|
529 |
"parse a unary-expression; return a node-tree, nil or #Error" |
|
530 |
||
531 |
|receiver expr sel pos pos2 lNr arguments| |
|
532 |
||
533 |
receiver := receiverArg. |
|
534 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
535 |
||
536 |
[ self isValidUnarySelector:tokenType ] whileTrue:[ |
|
14384 | 537 |
pos := tokenPosition. |
538 |
pos2 := pos + tokenName size - 1. |
|
539 |
lNr := tokenLineNr. |
|
540 |
sel := tokenName. |
|
13844 | 541 |
|
14384 | 542 |
self markSelector:sel from:pos to:pos2 receiverNode:receiver. |
543 |
lastSelectorElement := nil. |
|
13844 | 544 |
|
14384 | 545 |
self nextToken. |
546 |
tokenType == $( ifTrue:[ |
|
547 |
parserFlags allowSqueakExtensions == true ifTrue:[ |
|
548 |
"/ croquet/squeak extension - c/java-style arguments |
|
549 |
arguments := self functionCallArgList. |
|
550 |
"/ synthetic selector: foo[:[with:[with:[...]]]] |
|
551 |
arguments notEmpty ifTrue:[ |
|
552 |
sel := sel , ':'. |
|
553 |
arguments size - 1 timesRepeat:[ sel := sel , 'with:' ]. |
|
554 |
]. |
|
555 |
sel := self selectorCheck:sel for:receiver position:pos to:pos2. |
|
556 |
expr := MessageNode receiver:receiver selector:sel args:arguments fold:foldConstants. |
|
557 |
expr isErrorNode ifTrue:[ |
|
558 |
self parseError:(expr errorString) position:pos to:pos2. |
|
559 |
self clearErrorFlag. "ok, user wants it - so he'll get it" |
|
560 |
expr := MessageNode receiver:receiver selector:sel args:arguments fold:nil. |
|
561 |
]. |
|
562 |
expr lineNumber:lNr. |
|
563 |
self checkPlausibilityOf:expr from:pos to:pos2. |
|
564 |
parseForCode ifFalse:[ |
|
565 |
self rememberSelectorUsed:sel receiver:receiver |
|
566 |
]. |
|
567 |
^ expr. |
|
568 |
]. |
|
569 |
]. |
|
13844 | 570 |
|
14384 | 571 |
sel := self selectorCheck:sel for:receiver position:pos to:pos2. |
572 |
expr := UnaryNode receiver:receiver selector:sel fold:foldConstants. |
|
573 |
expr isErrorNode ifTrue:[ |
|
574 |
self warning:(expr errorString , '.\\If you proceed, that error will happen at runtime.') withCRs position:pos to:pos2. |
|
575 |
self clearErrorFlag. "ok, user wants it - so he'll get it" |
|
576 |
expr := UnaryNode receiver:receiver selector:sel fold:nil. |
|
577 |
]. |
|
578 |
expr lineNumber:lNr. |
|
13844 | 579 |
|
14384 | 580 |
self checkPlausibilityOf:expr from:pos to:pos2. |
581 |
parseForCode ifFalse:[ |
|
582 |
self rememberSelectorUsed:sel receiver:receiver |
|
583 |
]. |
|
13844 | 584 |
|
14384 | 585 |
receiver := expr. "/ for next message |
13844 | 586 |
]. |
587 |
^ receiver |
|
588 |
||
589 |
"Modified: / 14-02-2010 / 17:56:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
590 |
"Modified: / 19-01-2012 / 10:47:37 / cg" |
|
591 |
"Created: / 16-02-2012 / 21:54:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
592 |
! |
|
593 |
||
594 |
binaryExpression |
|
595 |
| node savedLastSelectorElement | |
|
596 |
||
597 |
savedLastSelectorElement := lastSelectorElement. |
|
598 |
lastSelectorElement := nil. |
|
599 |
node := super binaryExpression. |
|
600 |
(lastSelectorElement notNil and:[node ~~ #Error and:[node isMessage]]) ifTrue:[ |
|
601 |
lastSelectorElement node parent: node. |
|
602 |
]. |
|
603 |
lastSelectorElement := savedLastSelectorElement. |
|
604 |
^node |
|
605 |
||
606 |
"Modified: / 19-01-2000 / 16:22:16 / cg" |
|
607 |
"Created: / 16-02-2012 / 21:56:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
608 |
! |
|
609 |
||
10022 | 610 |
binaryExpressionFor:receiverArg |
611 |
"parse a binary-expression; return a node-tree, nil or #Error" |
|
612 |
||
11152
c9a386e4f1e0
refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents:
10882
diff
changeset
|
613 |
|receiver expr arg sel pos1 pos2 lno| |
10022 | 614 |
|
615 |
receiver := receiverArg. |
|
616 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
617 |
||
618 |
"special kludge: since Scanner cannot know if -digit is a binary |
|
619 |
expression or a negative constant, handle cases here" |
|
620 |
||
621 |
[(tokenType == #BinaryOperator) |
|
622 |
or:[(tokenType == $|) |
|
623 |
or:[(tokenType == $^ and:[parserFlags allowCaretAsBinop]) |
|
624 |
or:[((tokenType == #Integer) or:[tokenType == #Float]) |
|
625 |
and:[tokenValue < 0]]]] |
|
626 |
] whileTrue:[ |
|
627 |
"/ kludge alarm: in a function-call argList, #, is not a binarySelector |
|
628 |
inFunctionCallArgument == true ifTrue:[ |
|
629 |
((tokenType == #BinaryOperator) and:[tokenName = ',']) ifTrue:[ |
|
630 |
^ receiver |
|
631 |
]. |
|
632 |
]. |
|
633 |
||
634 |
pos1 := tokenPosition. |
|
635 |
lno := tokenLineNr. |
|
636 |
||
637 |
"/ kludge alarm: bar, caret and minus are not scanned as binop |
|
638 |
(tokenType == $|) ifTrue:[ |
|
639 |
sel := '|'. |
|
640 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition. |
|
641 |
self nextToken. |
|
642 |
] ifFalse:[ |
|
643 |
(tokenType == $^) ifTrue:[ |
|
644 |
sel := '^'. |
|
645 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition. |
|
646 |
self nextToken. |
|
647 |
] ifFalse:[ |
|
648 |
(tokenType == #BinaryOperator) ifTrue:[ |
|
649 |
sel := tokenName. |
|
650 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1). |
|
651 |
self nextToken |
|
652 |
] ifFalse:[ |
|
653 |
sel := '-'. |
|
654 |
token := tokenValue := tokenValue negated. |
|
655 |
tokenPosition := tokenPosition + 1. "/ to skip the sign |
|
656 |
] |
|
657 |
]. |
|
658 |
]. |
|
659 |
||
660 |
pos2 := pos1 + sel size - 1. |
|
661 |
self markSelector:sel from:pos1 to:pos2 receiverNode:receiver. |
|
662 |
lastSelectorElement := nil. |
|
663 |
||
664 |
arg := self unaryExpression. |
|
665 |
(arg == #Error) ifTrue:[^ #Error]. |
|
666 |
||
667 |
expr := BinaryNode receiver:receiver selector:sel arg:arg fold:foldConstants. |
|
668 |
expr isErrorNode ifTrue:[ |
|
669 |
self parseError:(expr errorString) position:pos1 to:tokenPosition. |
|
14384 | 670 |
self clearErrorFlag. "ok, user wants it - so he'll get it" |
10022 | 671 |
expr := BinaryNode receiver:receiver selector:sel arg:arg fold:nil. |
672 |
]. |
|
673 |
expr lineNumber:lno. |
|
674 |
expr selectorPosition:pos1. |
|
675 |
||
11152
c9a386e4f1e0
refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents:
10882
diff
changeset
|
676 |
self checkPlausibilityOf:expr from:pos1 to:pos2. |
10022 | 677 |
receiver := expr. "/ for next message |
678 |
]. |
|
679 |
^ receiver |
|
680 |
||
681 |
"Modified: / 09-01-1998 / 19:05:18 / stefan" |
|
682 |
"Modified: / 14-02-2010 / 17:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
11152
c9a386e4f1e0
refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents:
10882
diff
changeset
|
683 |
"Modified: / 19-01-2012 / 10:46:49 / cg" |
10022 | 684 |
! |
685 |
||
686 |
expression |
|
13844 | 687 |
| node savedLastSelectorElement | |
10022 | 688 |
|
13844 | 689 |
savedLastSelectorElement := lastSelectorElement. |
690 |
lastSelectorElement := nil. |
|
15456 | 691 |
|
13844 | 692 |
node := super expression. |
693 |
((node ~~ #Error) and:[node isMessage]) ifTrue:[ |
|
694 |
[ lastSelectorElement notNil ] whileTrue:[ |
|
695 |
lastSelectorElement node parent: node. |
|
15456 | 696 |
lastSelectorElement := lastSelectorElement previousElement. |
10022 | 697 |
]. |
698 |
]. |
|
13844 | 699 |
lastSelectorElement := savedLastSelectorElement. |
700 |
^node |
|
10022 | 701 |
|
702 |
"Modified: / 19-01-2000 / 16:22:16 / cg" |
|
13844 | 703 |
"Modified: / 16-02-2012 / 23:39:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10022 | 704 |
! |
705 |
||
706 |
keywordExpressionFor:receiverArg |
|
707 |
"parse a keyword-expression; return a node-tree, nil or #Error. |
|
708 |
||
709 |
keywordExpression ::= binaryexpression |
|
710 |
| { KEYWORD-PART binaryExpression } |
|
711 |
" |
|
712 |
||
11152
c9a386e4f1e0
refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents:
10882
diff
changeset
|
713 |
|expr receiver sel arg args posR1 posR2 pos1 pos2 lno positions constVal| |
10022 | 714 |
|
715 |
receiver := receiverArg. |
|
716 |
posR1 := tokenPosition. |
|
717 |
(tokenType == #Keyword) ifFalse:[^ receiver]. |
|
718 |
||
719 |
pos1 := posR2 := tokenPosition. |
|
720 |
pos2 := tokenPosition + tokenName size - 1. |
|
721 |
positions := OrderedCollection with:(pos1 to:pos2). |
|
722 |
sel := tokenName. |
|
723 |
lno := tokenLineNr. |
|
724 |
self nextToken. |
|
725 |
arg := self binaryExpression. |
|
726 |
(arg == #Error) ifTrue:[^ #Error]. |
|
727 |
args := Array with:arg. |
|
728 |
[tokenType == #Keyword] whileTrue:[ |
|
729 |
sel := sel , tokenName. |
|
730 |
pos2 := tokenPosition + tokenName size - 1. |
|
731 |
positions add:(tokenPosition to:pos2). |
|
732 |
self nextToken. |
|
733 |
arg := self binaryExpression. |
|
734 |
(arg == #Error) ifTrue:[^ #Error]. |
|
735 |
args := args copyWith:arg. |
|
736 |
]. |
|
737 |
||
738 |
positions do:[:p | |
|
739 |
self markSelector:sel from:p start to:p stop receiverNode:receiver. |
|
740 |
]. |
|
741 |
lastSelectorElement := nil. |
|
742 |
sel := self selectorCheck:sel for:receiver positions:positions. |
|
743 |
||
744 |
ignoreWarnings ifFalse:[ |
|
745 |
(Class definitionSelectors includes:sel) ifTrue:[ |
|
746 |
(receiver isVariable and:[receiver isUndeclared]) ifTrue:[ |
|
747 |
"this is not an error - the undefined class may be loaded after this code!!" |
|
748 |
self warning:('as yet undefined superclass: ' , receiver name) position:pos1 to:pos2. |
|
749 |
]. |
|
750 |
]. |
|
751 |
]. |
|
752 |
||
753 |
expr := MessageNode receiver:receiver selector:sel args:args fold:foldConstants. |
|
754 |
expr isErrorNode ifTrue:[ |
|
755 |
self parseError:(expr errorString) position:pos1 to:pos2. |
|
14384 | 756 |
self clearErrorFlag. "ok, user wants it - so he'll get it" |
10022 | 757 |
expr := MessageNode receiver:receiver selector:sel args:args fold:nil. |
758 |
]. |
|
759 |
expr lineNumber:lno. |
|
11152
c9a386e4f1e0
refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents:
10882
diff
changeset
|
760 |
self checkPlausibilityOf:expr from:pos1 to:pos2. |
10022 | 761 |
|
762 |
"/ (contextToEvaluateIn isNil and:[selfValue isNil]) ifTrue:[ "/ do not check this for doits |
|
763 |
"/ receiver isSuper ifTrue:[ |
|
764 |
"/ sel ~= selector ifTrue:[ |
|
765 |
"/ self warnCommonMistake:'possible bad super message (selector should be same as in current method) ?' |
|
766 |
"/ position:posR1 to:posR2-1 |
|
767 |
"/ ]. |
|
768 |
"/ ]. |
|
769 |
"/ ]. |
|
770 |
"/ |
|
771 |
||
772 |
(sel = #ifTrue: or:[sel = #ifFalse: or:[sel = #ifTrue:ifFalse: or:[sel = #ifFalse:ifTrue:]]]) ifTrue:[ |
|
773 |
(expr receiver withConstantValueDo:[:val | constVal := val]) ifTrue:[ |
|
774 |
|indexOfArgNotExecuted| |
|
775 |
||
776 |
"/ receiver evaluates to a constant |
|
777 |
constVal == true ifTrue:[ |
|
778 |
(sel startsWith: #ifFalse:) ifTrue:[ |
|
779 |
indexOfArgNotExecuted := 1. |
|
780 |
] ifFalse:[ |
|
781 |
indexOfArgNotExecuted := 2. |
|
782 |
] |
|
783 |
]. |
|
784 |
constVal == false ifTrue:[ |
|
785 |
(sel startsWith: #ifTrue:) ifTrue:[ |
|
786 |
indexOfArgNotExecuted := 1. |
|
787 |
] ifFalse:[ |
|
788 |
indexOfArgNotExecuted := 2. |
|
789 |
] |
|
790 |
]. |
|
791 |
indexOfArgNotExecuted == 2 ifTrue:[ |
|
792 |
args size == 1 ifTrue:[ indexOfArgNotExecuted := nil] |
|
793 |
]. |
|
794 |
||
795 |
indexOfArgNotExecuted notNil ifTrue:[ |
|
796 |
|argIsNotExecuted| |
|
797 |
||
798 |
"/ self warning:'receiver is constant; arg',indexOfArgNotExecuted printString,' is never executed' position:pos1 to:tokenPosition. |
|
799 |
argIsNotExecuted := expr args at:indexOfArgNotExecuted. |
|
14489 | 800 |
argIsNotExecuted realNode isBlockNode ifTrue:[ |
10022 | 801 |
self markCommentFrom:argIsNotExecuted startPosition to:argIsNotExecuted endPosition. |
802 |
]. |
|
803 |
]. |
|
804 |
]. |
|
805 |
]. |
|
806 |
||
807 |
(ignoreErrors or:[ignoreWarnings]) ifFalse:[ |
|
808 |
(sel = #and: or:[sel = #or:]) ifTrue:[ |
|
809 |
expr arg1 isBlock ifFalse:[ |
|
810 |
(expr arg1 isVariable |
|
811 |
and:[ (expr arg1 name asLowercase includesString:'block')]) ifFalse:[ |
|
812 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?' |
|
813 |
position:pos2+1 to:tokenPosition-1 |
|
814 |
] |
|
815 |
]. |
|
816 |
^ expr. |
|
817 |
]. |
|
818 |
||
819 |
(sel = #whileTrue: or:[sel = #whileFalse:]) ifTrue:[ |
|
820 |
expr receiver isBlock ifFalse:[ |
|
821 |
(expr receiver isVariable |
|
822 |
and:[ (expr receiver name asLowercase includesString:'block')]) ifFalse:[ |
|
823 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?' |
|
824 |
position:pos1 to:pos2 |
|
825 |
] |
|
826 |
]. |
|
827 |
^ expr. |
|
828 |
]. |
|
829 |
||
830 |
(sel = #ifTrue: or:[sel = #ifFalse:]) ifTrue:[ |
|
831 |
expr receiver isMessage ifTrue:[ |
|
832 |
(expr receiver selector = #whileTrue or:[expr receiver selector = #whileFalse]) ifTrue:[ |
|
833 |
self warnCommonMistake:'strange receiver expression' |
|
834 |
position:pos1 to:pos2 |
|
835 |
]. |
|
836 |
]. |
|
837 |
^ expr |
|
838 |
]. |
|
839 |
]. |
|
840 |
||
841 |
^ expr. |
|
842 |
||
843 |
"Modified: / 14-02-2010 / 17:58:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
11152
c9a386e4f1e0
refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents:
10882
diff
changeset
|
844 |
"Modified: / 19-01-2012 / 10:47:01 / cg" |
10022 | 845 |
! |
846 |
||
847 |
unaryExpressionFor:receiverArg |
|
848 |
"parse a unary-expression; return a node-tree, nil or #Error" |
|
849 |
||
13844 | 850 |
|receiver expr sel pos pos2 lNr arguments savedLastSelectorElement| |
10022 | 851 |
|
13844 | 852 |
savedLastSelectorElement := lastSelectorElement. |
10022 | 853 |
receiver := receiverArg. |
854 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
855 |
||
856 |
[ self isValidUnarySelector:tokenType ] whileTrue:[ |
|
14384 | 857 |
pos := tokenPosition. |
858 |
pos2 := pos + tokenName size - 1. |
|
859 |
lNr := tokenLineNr. |
|
860 |
sel := tokenName. |
|
10022 | 861 |
|
14384 | 862 |
lastSelectorElement := nil. |
863 |
self markSelector:sel from:pos to:pos2 receiverNode:receiver. |
|
10022 | 864 |
|
14384 | 865 |
self nextToken. |
866 |
tokenType == $( ifTrue:[ |
|
867 |
parserFlags allowSqueakExtensions == true ifTrue:[ |
|
868 |
"/ croquet/squeak extension - c/java-style arguments |
|
869 |
arguments := self functionCallArgList. |
|
870 |
"/ synthetic selector: foo[:[with:[with:[...]]]] |
|
871 |
arguments notEmpty ifTrue:[ |
|
872 |
sel := sel , ':'. |
|
873 |
arguments size - 1 timesRepeat:[ sel := sel , 'with:' ]. |
|
874 |
]. |
|
875 |
sel := self selectorCheck:sel for:receiver position:pos to:pos2. |
|
876 |
expr := MessageNode receiver:receiver selector:sel args:arguments fold:foldConstants. |
|
877 |
expr isErrorNode ifTrue:[ |
|
878 |
self parseError:(expr errorString) position:pos to:pos2. |
|
879 |
self clearErrorFlag. "ok, user wants it - so he'll get it" |
|
880 |
expr := MessageNode receiver:receiver selector:sel args:arguments fold:nil. |
|
881 |
]. |
|
882 |
lastSelectorElement node parent: expr. |
|
883 |
expr lineNumber:lNr. |
|
884 |
self checkPlausibilityOf:expr from:pos to:pos2. |
|
885 |
parseForCode ifFalse:[ |
|
886 |
self rememberSelectorUsed:sel receiver:receiver |
|
887 |
]. |
|
888 |
^ expr. |
|
889 |
]. |
|
890 |
]. |
|
10022 | 891 |
|
14384 | 892 |
sel := self selectorCheck:sel for:receiver position:pos to:pos2. |
893 |
expr := UnaryNode receiver:receiver selector:sel fold:foldConstants. |
|
894 |
expr isErrorNode ifTrue:[ |
|
895 |
self warning:(expr errorString , '.\\If you proceed, that error will happen at runtime.') withCRs position:pos to:pos2. |
|
896 |
self clearErrorFlag. "ok, user wants it - so he'll get it" |
|
897 |
expr := UnaryNode receiver:receiver selector:sel fold:nil. |
|
898 |
]. |
|
899 |
expr lineNumber:lNr. |
|
900 |
lastSelectorElement node parent: expr. |
|
10022 | 901 |
|
14384 | 902 |
self checkPlausibilityOf:expr from:pos to:pos2. |
903 |
parseForCode ifFalse:[ |
|
904 |
self rememberSelectorUsed:sel receiver:receiver |
|
905 |
]. |
|
10022 | 906 |
|
14384 | 907 |
receiver := expr. "/ for next message |
10022 | 908 |
]. |
13844 | 909 |
lastSelectorElement := savedLastSelectorElement. |
10022 | 910 |
^ receiver |
911 |
||
11152
c9a386e4f1e0
refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents:
10882
diff
changeset
|
912 |
"Modified: / 19-01-2012 / 10:47:37 / cg" |
13844 | 913 |
"Created: / 16-02-2012 / 23:50:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10022 | 914 |
! ! |
915 |
||
916 |
!SyntaxHighlighter2 methodsFor:'syntax detection'! |
|
917 |
||
15456 | 918 |
markBlockArgumentIdentifierFrom:pos1 to:pos2 |
919 |
"in addition to marking, remember the variable reference" |
|
920 |
||
921 |
| node | |
|
922 |
||
923 |
super markBlockArgumentIdentifierFrom:pos1 to:pos2. |
|
924 |
||
925 |
node := VariableNode blockArgumentNamed:(sourceText string copyFrom: pos1 to: pos2). |
|
926 |
node block:currentBlock. |
|
927 |
self rememberVariableElementFor: node from:pos1 to:pos2 assigned:false |
|
928 |
! |
|
929 |
||
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
930 |
markLocalVariableDeclaration: name from:pos1 to:pos2 |
15456 | 931 |
"in addition to marking, remember the variable reference" |
932 |
||
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
933 |
| type node | |
13844 | 934 |
|
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
935 |
super markLocalVariableDeclaration: name from:pos1 to:pos2. |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
936 |
|
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
937 |
type := currentBlock notNil ifTrue:[#BlockVariable] ifFalse:[#MethodVariable]. |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
938 |
node := VariableNode type: type name: name. |
15456 | 939 |
node block:currentBlock. "/ which is nil for method locals |
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
940 |
self rememberVariableElementFor: node from: pos1 to: pos2 assigned: false. |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
941 |
|
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
942 |
"Created: / 25-02-2014 / 20:22:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
943 |
! |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
944 |
|
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
945 |
markMethodArgumentIdentifierFrom:pos1 to:pos2 |
15456 | 946 |
"in addition to marking, remember the variable reference" |
947 |
||
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
948 |
| node | |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
949 |
|
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
950 |
super markMethodArgumentIdentifierFrom:pos1 to:pos2. |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
951 |
|
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
952 |
node := VariableNode methodArgumentNamed:(sourceText string copyFrom: pos1 to: pos2). |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
953 |
self rememberVariableElementFor: node from:pos1 to:pos2 assigned:false |
13844 | 954 |
|
955 |
"Created: / 24-07-2010 / 09:25:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
956 |
"Modified: / 21-08-2011 / 09:27:26 / cg" |
|
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
957 |
"Modified: / 25-02-2014 / 12:15:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10022 | 958 |
! |
959 |
||
960 |
markSelector:selectorString from:pos1 to:pos2 receiverNode:aReceiverNode |
|
12672 | 961 |
| element selectorSymbol | |
10022 | 962 |
|
13844 | 963 |
"Special hack for Java class references - I would like to have them |
964 |
marked specially (and not as an error when the class is not yet loaded - |
|
965 |
the code is correct as JavaClassAccessor loads it lazily" |
|
966 |
(aReceiverNode isJavaPackageReference) ifTrue:[ |
|
15456 | 967 |
self |
968 |
markFrom:pos1 to:pos2 |
|
969 |
withEmphasis:preferences globalClassIdentifierEmphasis |
|
970 |
color: preferences globalClassIdentifierColor |
|
13844 | 971 |
] ifFalse:[ |
15456 | 972 |
super markSelector:selectorString from:pos1 to:pos2 receiverNode:aReceiverNode. |
13844 | 973 |
]. |
974 |
||
12672 | 975 |
"don't create symbols for partial typed selectors" |
976 |
selectorSymbol := selectorString asSymbolIfInterned. |
|
10022 | 977 |
|
15714 | 978 |
element := elements newElementFor: (SelectorNode value: selectorSymbol ? selectorString from: pos1 to: pos2). |
13844 | 979 |
|
980 |
(lastSelectorElement notNil "and:[lastSelectorElement value = selectorString]") ifTrue:[ |
|
15456 | 981 |
lastSelectorElement nextElement: element. |
13844 | 982 |
]. |
10022 | 983 |
elements add: element. |
13844 | 984 |
lastSelectorElement := "(self isValidUnarySelector:tokenType)"false |
15456 | 985 |
ifTrue:[nil] |
986 |
ifFalse:[element]. |
|
10022 | 987 |
|
988 |
"Created: / 14-02-2010 / 17:40:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
989 |
"Modified: / 14-02-2010 / 19:24:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10633 | 990 |
"Modified (format): / 21-08-2011 / 09:18:21 / cg" |
13844 | 991 |
"Modified: / 19-04-2012 / 09:53:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10633 | 992 |
! |
993 |
||
994 |
markSelfFrom:pos1 to:pos2 |
|
15456 | 995 |
"in addition to marking, remember the variable reference" |
996 |
||
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
997 |
| node | |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
998 |
|
10633 | 999 |
super markSelfFrom:pos1 to:pos2. |
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1000 |
|
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1001 |
node := SelfNode new. |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1002 |
node type: #Self. |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1003 |
self rememberVariableElementFor: node from:pos1 to:pos2 assigned:false |
10633 | 1004 |
|
1005 |
"Created: / 21-08-2011 / 09:15:45 / cg" |
|
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1006 |
"Modified: / 25-02-2014 / 21:56:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1007 |
! |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1008 |
|
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1009 |
markSuperFrom:pos1 to:pos2 |
15456 | 1010 |
"in addition to marking, remember the variable reference" |
1011 |
||
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1012 |
| node | |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1013 |
|
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1014 |
super markSuperFrom:pos1 to:pos2. |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1015 |
|
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1016 |
node := SuperNode new. |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1017 |
node type: #Super. |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1018 |
self rememberVariableElementFor: node from:pos1 to:pos2 assigned:false |
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1019 |
|
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1020 |
"Created: / 25-02-2014 / 21:57:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10022 | 1021 |
! |
1022 |
||
1023 |
markUnknownIdentifierFrom:pos1 to:pos2 |
|
1024 |
||
13844 | 1025 |
ignoreBadIdentifier == true ifTrue:[ ^ self ]. |
10022 | 1026 |
|
13844 | 1027 |
super markUnknownIdentifierFrom:pos1 to:pos2 |
1028 |
||
1029 |
"Created: / 31.3.1998 / 19:09:26 / cg" |
|
1030 |
"Modified: / 31.3.1998 / 19:10:30 / cg" |
|
10022 | 1031 |
! |
1032 |
||
12911 | 1033 |
markVariable:v from:pos1 to:pos2 assigned:assigned |
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1034 |
self rememberVariableElementFor:v from:pos1 to:pos2 assigned:assigned. |
12911 | 1035 |
super markVariable:v from:pos1 to:pos2 assigned:assigned. |
10022 | 1036 |
|
1037 |
"Created: / 25-06-2010 / 13:03:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10633 | 1038 |
"Modified: / 21-08-2011 / 09:26:30 / cg" |
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1039 |
"Modified: / 25-02-2014 / 14:07:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10633 | 1040 |
! |
1041 |
||
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1042 |
rememberVariableElementFor:node from:pos1 to:pos2 assigned:assigned |
15473 | 1043 |
|name typeSymbol key element prev dict| |
15456 | 1044 |
|
1045 |
node startPosition: pos1 endPosition: pos2. |
|
12911 | 1046 |
|
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1047 |
name := node name. |
15456 | 1048 |
typeSymbol := key := node type. |
15473 | 1049 |
|
15456 | 1050 |
(typeSymbol == #BlockArg or:[typeSymbol == #BlockVariable]) ifTrue:[ |
15473 | 1051 |
key := (typeSymbol -> currentBlock "node block") |
15456 | 1052 |
]. |
1053 |
||
15473 | 1054 |
dict := lastVariableElements at:key ifAbsentPut:[Dictionary new]. |
1055 |
prev := dict at:name ifAbsent:[nil]. |
|
12987 | 1056 |
(prev notNil and:[prev start == pos1]) ifTrue:[ |
15456 | 1057 |
"/ prev assigned:assigned. |
12987 | 1058 |
^ self |
1059 |
]. |
|
11458
8fdf55d6d1c8
changed: #rememberVariableElementFor:type:from:to:
Claus Gittinger <cg@exept.de>
parents:
11152
diff
changeset
|
1060 |
|
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1061 |
element := elements newElementFor: node. |
10633 | 1062 |
|
15456 | 1063 |
prev notNil ifTrue:[prev nextElement:element]. |
15473 | 1064 |
dict at:name put:element. |
10633 | 1065 |
|
1066 |
elements add: element. |
|
1067 |
||
14056
1b0f6f3c4bbd
Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13844
diff
changeset
|
1068 |
"Created: / 25-02-2014 / 12:13:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10022 | 1069 |
! ! |
1070 |
||
1071 |
!SyntaxHighlighter2 class methodsFor:'documentation'! |
|
1072 |
||
12984 | 1073 |
version |
15714 | 1074 |
^ '$Header$' |
12984 | 1075 |
! |
1076 |
||
10022 | 1077 |
version_CVS |
15714 | 1078 |
^ '$Header$' |
10022 | 1079 |
! |
1080 |
||
1081 |
version_SVN |
|
15714 | 1082 |
^ '$Id$' |
10022 | 1083 |
! ! |
12636 | 1084 |