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