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