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