10022
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libtool' }"
|
|
13 |
|
|
14 |
SyntaxHighlighter subclass:#SyntaxHighlighter2
|
|
15 |
instanceVariableNames:'elements lastSelectorElement lastVariableElement'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Interface-CodeView-Syntax'
|
|
19 |
!
|
|
20 |
|
|
21 |
!SyntaxHighlighter2 class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
! !
|
|
36 |
|
|
37 |
!SyntaxHighlighter2 class methodsFor:'highlighting'!
|
|
38 |
|
|
39 |
formatClassDefinition:aString in:aClass elementsInto: elements
|
|
40 |
"format (recolor) a class definition expression in a given class.
|
|
41 |
Return the text containing font changes and color information."
|
|
42 |
|
|
43 |
^ self formatExpression:aString in:aClass elementsInto: elements
|
|
44 |
|
|
45 |
"Created: / 10-04-2011 / 18:18:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
46 |
!
|
|
47 |
|
|
48 |
formatExpression:aString in:aClass elementsInto: elements
|
|
49 |
"format (recolor) an expression in a given class.
|
|
50 |
Return the text containing font changes and color information."
|
|
51 |
|
|
52 |
|parser tree text endPos|
|
|
53 |
|
|
54 |
aString isNil ifTrue:[^ nil].
|
|
55 |
|
|
56 |
parser := self for:(ReadStream on:aString string) in:aClass.
|
|
57 |
parser elements: elements.
|
|
58 |
parser ignoreErrors:true.
|
|
59 |
parser ignoreWarnings:true.
|
|
60 |
parser sourceText:(text := aString string asText).
|
|
61 |
"/ use an array here - this can be changed much faster using #at:put:
|
|
62 |
text emphasisCollection:(Array new:aString size).
|
|
63 |
|
|
64 |
parser nextToken.
|
|
65 |
tree := parser "expression"statementList.
|
|
66 |
"/ now, convert the emphasis-array to a runArray
|
|
67 |
text emphasisCollection:(text emphasis asRunArray).
|
|
68 |
|
|
69 |
tree == #Error ifTrue:[
|
|
70 |
"/ mhmh - which is better ...
|
|
71 |
"/ alternative1: color rest after error in red
|
|
72 |
"/ text
|
|
73 |
"/ emphasizeFrom:(parser sourceStream position)
|
|
74 |
"/ to:text size
|
|
75 |
"/ with:(#color->Color red).
|
|
76 |
|
|
77 |
|
|
78 |
"/ alternative2: take original emphasis for rest
|
|
79 |
|
|
80 |
endPos := parser sourceStream position1Based.
|
|
81 |
endPos >= text size ifTrue:[
|
|
82 |
^ text
|
|
83 |
].
|
|
84 |
^ ((text copyTo:endPos) , (aString copyFrom:(endPos+1))).
|
|
85 |
|
|
86 |
"/ alternative3: no emphasis for rest.
|
|
87 |
|
|
88 |
"/ ^ text "/ aString
|
|
89 |
].
|
|
90 |
^ text
|
|
91 |
|
|
92 |
"
|
|
93 |
self
|
|
94 |
formatExpression:'(1 + 2) max:5'
|
|
95 |
in:UndefinedObject
|
|
96 |
"
|
|
97 |
|
|
98 |
"Created: / 25-07-2010 / 08:56:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
99 |
"Modified: / 25-07-2010 / 10:57:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
100 |
!
|
|
101 |
|
|
102 |
formatMethod:aString in:aClass using:preferencesOrNil elementsInto: elements
|
|
103 |
"format (recolor) a method in a given class.
|
|
104 |
Return the text containing font changes and color information."
|
|
105 |
|
|
106 |
|highlighter tree text endPos eColor|
|
|
107 |
|
|
108 |
aString isNil ifTrue:[^ nil].
|
|
109 |
|
|
110 |
Error handle:[:ex |
|
|
111 |
ex signal isHandled ifTrue:[
|
|
112 |
ex reject.
|
|
113 |
].
|
|
114 |
(self parseErrorSignal handles:ex) ifFalse:[
|
|
115 |
"Parse error may happen when re-formatting incomplete code while editing"
|
|
116 |
('SyntaxHighlighter [info]: error during highlight: ' , ex description) infoPrintCR.
|
|
117 |
"/ ex suspendedContext fullPrintAll.
|
|
118 |
].
|
|
119 |
^ aString
|
|
120 |
] do:[
|
|
121 |
highlighter := self for:(ReadStream on:aString string) in:aClass.
|
|
122 |
highlighter elements: elements.
|
|
123 |
preferencesOrNil notNil ifTrue:[highlighter preferences:preferencesOrNil].
|
|
124 |
"/ highlighter ignoreErrors:true.
|
|
125 |
highlighter ignoreWarnings:true.
|
|
126 |
highlighter sourceText:(text := aString string asText).
|
|
127 |
"/ use an array here - this can be changed much faster using #at:put:
|
|
128 |
text emphasisCollection:(Array new:aString size).
|
|
129 |
|
|
130 |
tree := highlighter parseMethod.
|
|
131 |
"/ now, convert the emphasis-array to a runArray
|
|
132 |
text emphasisCollection:(text emphasis asRunArray).
|
|
133 |
|
|
134 |
tree == #Error ifTrue:[
|
|
135 |
eColor := UserPreferences current errorColor.
|
|
136 |
eColor notNil ifTrue:[
|
|
137 |
"/ mhmh - which is better ...
|
|
138 |
"/ alternative1: color rest after error in red
|
|
139 |
text
|
|
140 |
emphasizeFrom:(highlighter sourceStream position1Based)
|
|
141 |
to:text size
|
|
142 |
with:(#color->eColor).
|
|
143 |
] ifFalse:[
|
|
144 |
"/ alternative2: take original emphasis for rest
|
|
145 |
|
|
146 |
endPos := highlighter sourceStream position1Based.
|
|
147 |
endPos >= text size ifTrue:[
|
|
148 |
^ Array with: text with: highlighter elements
|
|
149 |
].
|
|
150 |
^ ((text copyTo:endPos) , (aString copyFrom:(endPos+1)))
|
|
151 |
].
|
|
152 |
"/ alternative3: no emphasis for rest.
|
|
153 |
].
|
|
154 |
^text
|
|
155 |
]
|
|
156 |
"
|
|
157 |
self
|
|
158 |
formatMethod:'foo
|
|
159 |
^ self bar:''hello''.
|
|
160 |
|
|
161 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
|
|
162 |
'
|
|
163 |
in:UndefinedObject
|
|
164 |
"
|
|
165 |
|
|
166 |
"Modified: / 22-08-2006 / 13:32:04 / cg"
|
|
167 |
"Created: / 25-07-2010 / 08:56:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
168 |
! !
|
|
169 |
|
|
170 |
!SyntaxHighlighter2 methodsFor:'accessing'!
|
|
171 |
|
|
172 |
elements
|
|
173 |
^ elements
|
|
174 |
!
|
|
175 |
|
|
176 |
elements:something
|
|
177 |
elements := something.
|
|
178 |
! !
|
|
179 |
|
|
180 |
!SyntaxHighlighter2 methodsFor:'initialization'!
|
|
181 |
|
|
182 |
initialize
|
|
183 |
|
|
184 |
super initialize.
|
|
185 |
elements := SortedCollection new.
|
|
186 |
lastVariableElement := Dictionary new.
|
|
187 |
|
|
188 |
"Created: / 14-02-2010 / 13:08:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
189 |
"Modified: / 25-06-2010 / 13:04:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
190 |
! !
|
|
191 |
|
|
192 |
!SyntaxHighlighter2 methodsFor:'parsing-expressions'!
|
|
193 |
|
|
194 |
binaryExpressionFor:receiverArg
|
|
195 |
"parse a binary-expression; return a node-tree, nil or #Error"
|
|
196 |
|
|
197 |
|receiver expr arg sel pos1 pos2 lno note|
|
|
198 |
|
|
199 |
receiver := receiverArg.
|
|
200 |
(receiver == #Error) ifTrue:[^ #Error].
|
|
201 |
|
|
202 |
"special kludge: since Scanner cannot know if -digit is a binary
|
|
203 |
expression or a negative constant, handle cases here"
|
|
204 |
|
|
205 |
[(tokenType == #BinaryOperator)
|
|
206 |
or:[(tokenType == $|)
|
|
207 |
or:[(tokenType == $^ and:[parserFlags allowCaretAsBinop])
|
|
208 |
or:[((tokenType == #Integer) or:[tokenType == #Float])
|
|
209 |
and:[tokenValue < 0]]]]
|
|
210 |
] whileTrue:[
|
|
211 |
"/ kludge alarm: in a function-call argList, #, is not a binarySelector
|
|
212 |
inFunctionCallArgument == true ifTrue:[
|
|
213 |
((tokenType == #BinaryOperator) and:[tokenName = ',']) ifTrue:[
|
|
214 |
^ receiver
|
|
215 |
].
|
|
216 |
].
|
|
217 |
|
|
218 |
pos1 := tokenPosition.
|
|
219 |
lno := tokenLineNr.
|
|
220 |
|
|
221 |
"/ kludge alarm: bar, caret and minus are not scanned as binop
|
|
222 |
(tokenType == $|) ifTrue:[
|
|
223 |
sel := '|'.
|
|
224 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition.
|
|
225 |
self nextToken.
|
|
226 |
] ifFalse:[
|
|
227 |
(tokenType == $^) ifTrue:[
|
|
228 |
sel := '^'.
|
|
229 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition.
|
|
230 |
self nextToken.
|
|
231 |
] ifFalse:[
|
|
232 |
(tokenType == #BinaryOperator) ifTrue:[
|
|
233 |
sel := tokenName.
|
|
234 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1).
|
|
235 |
self nextToken
|
|
236 |
] ifFalse:[
|
|
237 |
sel := '-'.
|
|
238 |
token := tokenValue := tokenValue negated.
|
|
239 |
tokenPosition := tokenPosition + 1. "/ to skip the sign
|
|
240 |
]
|
|
241 |
].
|
|
242 |
].
|
|
243 |
|
|
244 |
pos2 := pos1 + sel size - 1.
|
|
245 |
self markSelector:sel from:pos1 to:pos2 receiverNode:receiver.
|
|
246 |
lastSelectorElement := nil.
|
|
247 |
|
|
248 |
arg := self unaryExpression.
|
|
249 |
(arg == #Error) ifTrue:[^ #Error].
|
|
250 |
|
|
251 |
expr := BinaryNode receiver:receiver selector:sel arg:arg fold:foldConstants.
|
|
252 |
expr isErrorNode ifTrue:[
|
|
253 |
self parseError:(expr errorString) position:pos1 to:tokenPosition.
|
|
254 |
errorFlag := false. "ok, user wants it - so he'll get it"
|
|
255 |
expr := BinaryNode receiver:receiver selector:sel arg:arg fold:nil.
|
|
256 |
].
|
|
257 |
expr lineNumber:lno.
|
|
258 |
expr selectorPosition:pos1.
|
|
259 |
|
|
260 |
(ignoreErrors or:[ignoreWarnings]) ifFalse:[
|
|
261 |
note := self plausibilityCheck:expr.
|
|
262 |
note notNil ifTrue:[
|
|
263 |
self warning:note position:pos1 to:pos2
|
|
264 |
].
|
|
265 |
].
|
|
266 |
parseForCode ifFalse:[
|
|
267 |
self rememberSelectorUsed:sel receiver:receiver
|
|
268 |
].
|
|
269 |
receiver := expr. "/ for next message
|
|
270 |
].
|
|
271 |
^ receiver
|
|
272 |
|
|
273 |
"Modified: / 09-01-1998 / 19:05:18 / stefan"
|
|
274 |
"Modified: / 19-01-2000 / 16:22:04 / cg"
|
|
275 |
"Modified: / 14-02-2010 / 17:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
276 |
!
|
|
277 |
|
|
278 |
expression
|
|
279 |
"parse a cascade-expression; return a node-tree, nil or #Error.
|
|
280 |
|
|
281 |
expression ::= keywordExpression
|
|
282 |
| keywordExpression cascade
|
|
283 |
|
|
284 |
cascade ::= ';' expressionSendPart
|
|
285 |
| cascade ';' expressionSendPart
|
|
286 |
|
|
287 |
expressionSendPart ::= { KEYWORD binaryExpression }
|
|
288 |
| BINARYOPERATOR unaryExpression
|
|
289 |
| IDENTIFIER
|
|
290 |
"
|
|
291 |
|
|
292 |
|receiver arg sel args pos pos2 lno tokenEnd realReceiver positions|
|
|
293 |
|
|
294 |
pos := tokenPosition.
|
|
295 |
receiver := self keywordExpression.
|
|
296 |
(receiver == #Error) ifTrue:[^ #Error].
|
|
297 |
(tokenType == $;) ifTrue:[
|
|
298 |
receiver isMessage ifFalse:[
|
|
299 |
self syntaxError:'left side of cascade must be a message expression'
|
|
300 |
position:pos to:tokenPosition.
|
|
301 |
realReceiver := receiver. "/ only to allow continuing.
|
|
302 |
] ifTrue:[
|
|
303 |
realReceiver := receiver receiver.
|
|
304 |
].
|
|
305 |
[tokenType == $;] whileTrue:[
|
|
306 |
self nextToken.
|
|
307 |
(tokenType == #Identifier) ifTrue:[
|
|
308 |
tokenEnd := tokenPosition + tokenName size - 1.
|
|
309 |
self markSelector:tokenName from:tokenPosition to:tokenEnd receiverNode:realReceiver.
|
|
310 |
sel := tokenName.
|
|
311 |
sel := self selectorCheck:tokenName for:realReceiver position:tokenPosition to:tokenEnd.
|
|
312 |
receiver := CascadeNode receiver:receiver selector:sel.
|
|
313 |
receiver lineNumber:tokenLineNr.
|
|
314 |
parseForCode ifFalse:[
|
|
315 |
self rememberSelectorUsed:sel
|
|
316 |
].
|
|
317 |
self nextToken.
|
|
318 |
] ifFalse:[
|
|
319 |
(tokenType == #BinaryOperator) ifTrue:[
|
|
320 |
tokenEnd := tokenPosition + tokenName size - 1.
|
|
321 |
self markSelector:tokenName from:tokenPosition to:tokenEnd receiverNode:realReceiver.
|
|
322 |
lastSelectorElement := nil.
|
|
323 |
sel := tokenName.
|
|
324 |
sel := self selectorCheck:tokenName for:realReceiver position:tokenPosition to:tokenEnd.
|
|
325 |
lno := tokenLineNr.
|
|
326 |
self nextToken.
|
|
327 |
arg := self unaryExpression.
|
|
328 |
(arg == #Error) ifTrue:[^ #Error].
|
|
329 |
receiver := CascadeNode receiver:receiver selector:sel arg:arg.
|
|
330 |
receiver lineNumber:lno.
|
|
331 |
parseForCode ifFalse:[
|
|
332 |
self rememberSelectorUsed:sel
|
|
333 |
].
|
|
334 |
] ifFalse:[
|
|
335 |
(tokenType == #Keyword) ifTrue:[
|
|
336 |
tokenEnd := tokenPosition + tokenName size - 1.
|
|
337 |
positions := OrderedCollection with:(tokenPosition to:tokenEnd).
|
|
338 |
pos := tokenPosition.
|
|
339 |
pos2 := tokenEnd.
|
|
340 |
lno := tokenLineNr.
|
|
341 |
sel := tokenName.
|
|
342 |
self nextToken.
|
|
343 |
arg := self binaryExpression.
|
|
344 |
(arg == #Error) ifTrue:[^ #Error].
|
|
345 |
args := Array with:arg.
|
|
346 |
[tokenType == #Keyword] whileTrue:[
|
|
347 |
tokenEnd := tokenPosition + tokenName size - 1.
|
|
348 |
positions add:(tokenPosition to:tokenEnd).
|
|
349 |
sel := sel , tokenName.
|
|
350 |
self nextToken.
|
|
351 |
arg := self binaryExpression.
|
|
352 |
(arg == #Error) ifTrue:[^ #Error].
|
|
353 |
args := args copyWith:arg.
|
|
354 |
pos2 := tokenEnd
|
|
355 |
].
|
|
356 |
positions do:[:p |
|
|
357 |
self markSelector:sel from:p start to:p stop receiverNode:realReceiver.
|
|
358 |
].
|
|
359 |
lastSelectorElement := nil.
|
|
360 |
|
|
361 |
sel := self selectorCheck:sel for:realReceiver position:pos to:pos2.
|
|
362 |
|
|
363 |
receiver := CascadeNode receiver:receiver selector:sel args:args.
|
|
364 |
receiver lineNumber:lno.
|
|
365 |
parseForCode ifFalse:[
|
|
366 |
self rememberSelectorUsed:sel
|
|
367 |
].
|
|
368 |
] ifFalse:[
|
|
369 |
(tokenType == #Error) ifTrue:[^ #Error].
|
|
370 |
self syntaxError:('invalid cascade; ' , tokenType printString , ' unexpected')
|
|
371 |
position:tokenPosition to:source position1Based - 1.
|
|
372 |
^ #Error
|
|
373 |
]
|
|
374 |
]
|
|
375 |
]
|
|
376 |
].
|
|
377 |
|
|
378 |
"obscure (unspecified ?) if selector follows; Question:
|
|
379 |
|
|
380 |
is
|
|
381 |
'expr sel1; sel2 sel3'
|
|
382 |
|
|
383 |
to be parsed as:
|
|
384 |
(t := expr.
|
|
385 |
t sel1.
|
|
386 |
t sel2) sel3
|
|
387 |
|
|
388 |
or:
|
|
389 |
(t := expr.
|
|
390 |
t sel1.
|
|
391 |
t sel2 sel3)
|
|
392 |
"
|
|
393 |
((tokenType == #Identifier)
|
|
394 |
or:[(tokenType == #BinaryOperator)
|
|
395 |
or:[tokenType == #Keyword]]) ifTrue:[
|
|
396 |
self syntaxError:'ambigous cascade - please group using (...)'
|
|
397 |
position:tokenPosition to:source position1Based - 1.
|
|
398 |
^ #Error
|
|
399 |
"/ self warning: "syntaxError:" 'possibly ambigous cascade - please group using (...)'
|
|
400 |
"/ position:tokenPosition to:source position - 1.
|
|
401 |
"/ tokenType == #Identifier ifTrue:[
|
|
402 |
"/ ^ self unaryExpressionFor:receiver
|
|
403 |
"/ ].
|
|
404 |
"/ tokenType == #BinaryOperator ifTrue:[
|
|
405 |
"/ ^ self binaryExpressionFor:receiver
|
|
406 |
"/ ].
|
|
407 |
"/ ^ self keywordExpressionFor:receiver
|
|
408 |
]
|
|
409 |
].
|
|
410 |
^ receiver
|
|
411 |
|
|
412 |
"Modified: / 19-01-2000 / 16:22:16 / cg"
|
|
413 |
"Modified: / 14-02-2010 / 17:58:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
414 |
!
|
|
415 |
|
|
416 |
keywordExpressionFor:receiverArg
|
|
417 |
"parse a keyword-expression; return a node-tree, nil or #Error.
|
|
418 |
|
|
419 |
keywordExpression ::= binaryexpression
|
|
420 |
| { KEYWORD-PART binaryExpression }
|
|
421 |
"
|
|
422 |
|
|
423 |
|expr receiver sel arg args posR1 posR2 pos1 pos2 lno note positions constVal|
|
|
424 |
|
|
425 |
receiver := receiverArg.
|
|
426 |
posR1 := tokenPosition.
|
|
427 |
(tokenType == #Keyword) ifFalse:[^ receiver].
|
|
428 |
|
|
429 |
pos1 := posR2 := tokenPosition.
|
|
430 |
pos2 := tokenPosition + tokenName size - 1.
|
|
431 |
positions := OrderedCollection with:(pos1 to:pos2).
|
|
432 |
sel := tokenName.
|
|
433 |
lno := tokenLineNr.
|
|
434 |
self nextToken.
|
|
435 |
arg := self binaryExpression.
|
|
436 |
(arg == #Error) ifTrue:[^ #Error].
|
|
437 |
args := Array with:arg.
|
|
438 |
[tokenType == #Keyword] whileTrue:[
|
|
439 |
sel := sel , tokenName.
|
|
440 |
pos2 := tokenPosition + tokenName size - 1.
|
|
441 |
positions add:(tokenPosition to:pos2).
|
|
442 |
self nextToken.
|
|
443 |
arg := self binaryExpression.
|
|
444 |
(arg == #Error) ifTrue:[^ #Error].
|
|
445 |
args := args copyWith:arg.
|
|
446 |
].
|
|
447 |
|
|
448 |
positions do:[:p |
|
|
449 |
self markSelector:sel from:p start to:p stop receiverNode:receiver.
|
|
450 |
].
|
|
451 |
lastSelectorElement := nil.
|
|
452 |
sel := self selectorCheck:sel for:receiver positions:positions.
|
|
453 |
|
|
454 |
ignoreWarnings ifFalse:[
|
|
455 |
(Class definitionSelectors includes:sel) ifTrue:[
|
|
456 |
(receiver isVariable and:[receiver isUndeclared]) ifTrue:[
|
|
457 |
"this is not an error - the undefined class may be loaded after this code!!"
|
|
458 |
self warning:('as yet undefined superclass: ' , receiver name) position:pos1 to:pos2.
|
|
459 |
].
|
|
460 |
].
|
|
461 |
].
|
|
462 |
|
|
463 |
expr := MessageNode receiver:receiver selector:sel args:args fold:foldConstants.
|
|
464 |
expr isErrorNode ifTrue:[
|
|
465 |
self parseError:(expr errorString) position:pos1 to:pos2.
|
|
466 |
errorFlag := false. "ok, user wants it - so he'll get it"
|
|
467 |
expr := MessageNode receiver:receiver selector:sel args:args fold:nil.
|
|
468 |
].
|
|
469 |
expr lineNumber:lno.
|
|
470 |
(ignoreErrors or:[ignoreWarnings]) ifFalse:[
|
|
471 |
note := self plausibilityCheck:expr.
|
|
472 |
note notNil ifTrue:[
|
|
473 |
self warning:note position:pos1 to:pos2
|
|
474 |
].
|
|
475 |
].
|
|
476 |
parseForCode ifFalse:[
|
|
477 |
self rememberSelectorUsed:sel receiver:receiver
|
|
478 |
].
|
|
479 |
|
|
480 |
"/ (contextToEvaluateIn isNil and:[selfValue isNil]) ifTrue:[ "/ do not check this for doits
|
|
481 |
"/ receiver isSuper ifTrue:[
|
|
482 |
"/ sel ~= selector ifTrue:[
|
|
483 |
"/ self warnCommonMistake:'possible bad super message (selector should be same as in current method) ?'
|
|
484 |
"/ position:posR1 to:posR2-1
|
|
485 |
"/ ].
|
|
486 |
"/ ].
|
|
487 |
"/ ].
|
|
488 |
"/
|
|
489 |
|
|
490 |
(sel = #ifTrue: or:[sel = #ifFalse: or:[sel = #ifTrue:ifFalse: or:[sel = #ifFalse:ifTrue:]]]) ifTrue:[
|
|
491 |
(expr receiver withConstantValueDo:[:val | constVal := val]) ifTrue:[
|
|
492 |
|indexOfArgNotExecuted|
|
|
493 |
|
|
494 |
"/ receiver evaluates to a constant
|
|
495 |
constVal == true ifTrue:[
|
|
496 |
(sel startsWith: #ifFalse:) ifTrue:[
|
|
497 |
indexOfArgNotExecuted := 1.
|
|
498 |
] ifFalse:[
|
|
499 |
indexOfArgNotExecuted := 2.
|
|
500 |
]
|
|
501 |
].
|
|
502 |
constVal == false ifTrue:[
|
|
503 |
(sel startsWith: #ifTrue:) ifTrue:[
|
|
504 |
indexOfArgNotExecuted := 1.
|
|
505 |
] ifFalse:[
|
|
506 |
indexOfArgNotExecuted := 2.
|
|
507 |
]
|
|
508 |
].
|
|
509 |
indexOfArgNotExecuted == 2 ifTrue:[
|
|
510 |
args size == 1 ifTrue:[ indexOfArgNotExecuted := nil]
|
|
511 |
].
|
|
512 |
|
|
513 |
indexOfArgNotExecuted notNil ifTrue:[
|
|
514 |
|argIsNotExecuted|
|
|
515 |
|
|
516 |
"/ self warning:'receiver is constant; arg',indexOfArgNotExecuted printString,' is never executed' position:pos1 to:tokenPosition.
|
|
517 |
argIsNotExecuted := expr args at:indexOfArgNotExecuted.
|
|
518 |
argIsNotExecuted isBlockNode ifTrue:[
|
|
519 |
self markCommentFrom:argIsNotExecuted startPosition to:argIsNotExecuted endPosition.
|
|
520 |
].
|
|
521 |
].
|
|
522 |
].
|
|
523 |
].
|
|
524 |
|
|
525 |
(ignoreErrors or:[ignoreWarnings]) ifFalse:[
|
|
526 |
(sel = #and: or:[sel = #or:]) ifTrue:[
|
|
527 |
expr arg1 isBlock ifFalse:[
|
|
528 |
(expr arg1 isVariable
|
|
529 |
and:[ (expr arg1 name asLowercase includesString:'block')]) ifFalse:[
|
|
530 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?'
|
|
531 |
position:pos2+1 to:tokenPosition-1
|
|
532 |
]
|
|
533 |
].
|
|
534 |
^ expr.
|
|
535 |
].
|
|
536 |
|
|
537 |
(sel = #whileTrue: or:[sel = #whileFalse:]) ifTrue:[
|
|
538 |
expr receiver isBlock ifFalse:[
|
|
539 |
(expr receiver isVariable
|
|
540 |
and:[ (expr receiver name asLowercase includesString:'block')]) ifFalse:[
|
|
541 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?'
|
|
542 |
position:pos1 to:pos2
|
|
543 |
]
|
|
544 |
].
|
|
545 |
^ expr.
|
|
546 |
].
|
|
547 |
|
|
548 |
(sel = #ifTrue: or:[sel = #ifFalse:]) ifTrue:[
|
|
549 |
expr receiver isMessage ifTrue:[
|
|
550 |
(expr receiver selector = #whileTrue or:[expr receiver selector = #whileFalse]) ifTrue:[
|
|
551 |
self warnCommonMistake:'strange receiver expression'
|
|
552 |
position:pos1 to:pos2
|
|
553 |
].
|
|
554 |
].
|
|
555 |
^ expr
|
|
556 |
].
|
|
557 |
].
|
|
558 |
|
|
559 |
^ expr.
|
|
560 |
|
|
561 |
"Modified: / 19-01-2000 / 16:22:22 / cg"
|
|
562 |
"Modified: / 14-02-2010 / 17:58:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
563 |
!
|
|
564 |
|
|
565 |
unaryExpressionFor:receiverArg
|
|
566 |
"parse a unary-expression; return a node-tree, nil or #Error"
|
|
567 |
|
|
568 |
|receiver expr sel pos pos2 note lNr arguments|
|
|
569 |
|
|
570 |
receiver := receiverArg.
|
|
571 |
(receiver == #Error) ifTrue:[^ #Error].
|
|
572 |
|
|
573 |
[ self isValidUnarySelector:tokenType ] whileTrue:[
|
|
574 |
pos := tokenPosition.
|
|
575 |
pos2 := pos + tokenName size - 1.
|
|
576 |
lNr := tokenLineNr.
|
|
577 |
sel := tokenName.
|
|
578 |
|
|
579 |
self markSelector:sel from:pos to:pos2 receiverNode:receiver.
|
|
580 |
lastSelectorElement := nil.
|
|
581 |
|
|
582 |
self nextToken.
|
|
583 |
tokenType == $( ifTrue:[
|
|
584 |
parserFlags allowSqueakExtensions == true ifTrue:[
|
|
585 |
"/ croquet/squeak extension - c/java-style arguments
|
|
586 |
arguments := self functionCallArgList.
|
|
587 |
"/ synthetic selector: foo[:[with:[with:[...]]]]
|
|
588 |
arguments notEmpty ifTrue:[
|
|
589 |
sel := sel , ':'.
|
|
590 |
arguments size - 1 timesRepeat:[ sel := sel , 'with:' ].
|
|
591 |
].
|
|
592 |
sel := self selectorCheck:sel for:receiver position:pos to:pos2.
|
|
593 |
expr := MessageNode receiver:receiver selector:sel args:arguments fold:foldConstants.
|
|
594 |
expr isErrorNode ifTrue:[
|
|
595 |
self parseError:(expr errorString) position:pos to:pos2.
|
|
596 |
errorFlag := false. "ok, user wants it - so he'll get it"
|
|
597 |
expr := MessageNode receiver:receiver selector:sel args:arguments fold:nil.
|
|
598 |
].
|
|
599 |
expr lineNumber:lNr.
|
|
600 |
(ignoreErrors or:[ignoreWarnings]) ifFalse:[
|
|
601 |
note := self plausibilityCheck:receiver.
|
|
602 |
note notNil ifTrue:[
|
|
603 |
self warning:note position:pos to:pos2
|
|
604 |
].
|
|
605 |
].
|
|
606 |
parseForCode ifFalse:[
|
|
607 |
self rememberSelectorUsed:sel receiver:receiver
|
|
608 |
].
|
|
609 |
^ expr.
|
|
610 |
].
|
|
611 |
].
|
|
612 |
|
|
613 |
sel := self selectorCheck:sel for:receiver position:pos to:pos2.
|
|
614 |
expr := UnaryNode receiver:receiver selector:sel fold:foldConstants.
|
|
615 |
expr isErrorNode ifTrue:[
|
|
616 |
self warning:(expr errorString , '.\\If you proceed, that error will happen at runtime.') withCRs position:pos to:pos2.
|
|
617 |
errorFlag := false. "ok, user wants it - so he'll get it"
|
|
618 |
expr := UnaryNode receiver:receiver selector:sel fold:nil.
|
|
619 |
].
|
|
620 |
expr lineNumber:lNr.
|
|
621 |
|
|
622 |
(ignoreErrors or:[ignoreWarnings]) ifFalse:[
|
|
623 |
note := self plausibilityCheck:expr.
|
|
624 |
note notNil ifTrue:[
|
|
625 |
self warning:note position:pos to:pos2
|
|
626 |
].
|
|
627 |
].
|
|
628 |
parseForCode ifFalse:[
|
|
629 |
self rememberSelectorUsed:sel receiver:receiver
|
|
630 |
].
|
|
631 |
|
|
632 |
receiver := expr. "/ for next message
|
|
633 |
].
|
|
634 |
^ receiver
|
|
635 |
|
|
636 |
"Modified: / 16-07-2006 / 16:15:22 / cg"
|
|
637 |
"Modified: / 14-02-2010 / 17:56:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
638 |
! !
|
|
639 |
|
|
640 |
!SyntaxHighlighter2 methodsFor:'syntax detection'!
|
|
641 |
|
|
642 |
markArgumentIdentifierFrom:pos1 to:pos2
|
|
643 |
|
|
644 |
| element prev |
|
|
645 |
|
|
646 |
super markArgumentIdentifierFrom:pos1 to:pos2.
|
|
647 |
element := SyntaxElement from: pos1 to: pos2 type: #variable value: tokenName.
|
|
648 |
prev := lastVariableElement at: tokenName ifAbsent:[nil].
|
|
649 |
prev ifNotNil:[prev next:element].
|
|
650 |
lastVariableElement at: tokenName put:element.
|
|
651 |
elements add: element.
|
|
652 |
|
|
653 |
"Created: / 24-07-2010 / 09:25:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
654 |
!
|
|
655 |
|
|
656 |
markGlobalClassIdentifierFrom:pos1 to:pos2
|
|
657 |
|
|
658 |
| name env cls |
|
|
659 |
|
|
660 |
super markGlobalClassIdentifierFrom:pos1 to:pos2.
|
|
661 |
|
|
662 |
name := token isString ifTrue:[token asSymbolIfInterned] ifFalse:[nil].
|
|
663 |
name ifNotNil:
|
|
664 |
[env := (classToCompileFor ? UndefinedObject) theNonMetaclass environment.
|
|
665 |
cls := env isNameSpace
|
|
666 |
ifTrue:[env at: name]
|
|
667 |
ifFalse:[nil].
|
|
668 |
cls ifNil:[
|
|
669 |
cls := Smalltalk at: name]].
|
|
670 |
|
|
671 |
elements add:
|
|
672 |
(SyntaxElement from: pos1 to: pos2 type: #class value: cls)
|
|
673 |
|
|
674 |
"Created: / 14-02-2010 / 14:08:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
675 |
"Modified: / 15-02-2010 / 10:53:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
676 |
!
|
|
677 |
|
|
678 |
markLocalIdentifierFrom:pos1 to:pos2
|
|
679 |
| element prev |
|
|
680 |
|
|
681 |
super markLocalIdentifierFrom:pos1 to:pos2.
|
|
682 |
element := SyntaxElement from: pos1 to: pos2 type: #variable value: tokenName.
|
|
683 |
prev := lastVariableElement at: tokenName ifAbsent:[nil].
|
|
684 |
prev ifNotNil:[prev next:element].
|
|
685 |
lastVariableElement at: tokenName put:element.
|
|
686 |
elements add: element.
|
|
687 |
|
|
688 |
"Created: / 24-07-2010 / 09:28:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
689 |
!
|
|
690 |
|
|
691 |
markSelector:selectorString from:pos1 to:pos2 receiverNode:aReceiverNode
|
|
692 |
|
|
693 |
| element |
|
|
694 |
|
|
695 |
super markSelector:selectorString from:pos1 to:pos2 receiverNode:aReceiverNode.
|
|
696 |
|
|
697 |
element := SyntaxElement from: pos1 to: pos2 type: #selector value: selectorString asSymbol.
|
|
698 |
lastSelectorElement
|
|
699 |
ifNotNil:[lastSelectorElement next: element].
|
|
700 |
elements add: element.
|
|
701 |
lastSelectorElement := element.
|
|
702 |
|
|
703 |
"Created: / 14-02-2010 / 17:40:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
704 |
"Modified: / 14-02-2010 / 19:24:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
705 |
!
|
|
706 |
|
|
707 |
markUnknownIdentifierFrom:pos1 to:pos2
|
|
708 |
|
|
709 |
classToCompileFor
|
|
710 |
ifNotNil:[super markUnknownIdentifierFrom:pos1 to:pos2]
|
|
711 |
ifNil:[self markLocalIdentifierFrom: pos1 to: pos2].
|
|
712 |
|
|
713 |
"Created: / 24-07-2010 / 09:51:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
714 |
!
|
|
715 |
|
|
716 |
markVariable:v from:pos1 to:pos2
|
|
717 |
|
|
718 |
| element prev |
|
|
719 |
super markVariable:v from:pos1 to:pos2.
|
|
720 |
(v type == #GlobalVariable) ifTrue:[^self].
|
|
721 |
|
|
722 |
element := SyntaxElement from: pos1 to: pos2 type: #variable value: v name.
|
|
723 |
|
|
724 |
prev := lastVariableElement at: v name ifAbsent:[nil].
|
|
725 |
prev ifNotNil:[prev next:element].
|
|
726 |
lastVariableElement at: v name put:element.
|
|
727 |
elements add: element.
|
|
728 |
|
|
729 |
"Created: / 25-06-2010 / 13:03:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
730 |
"Modified: / 25-06-2010 / 14:23:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
731 |
! !
|
|
732 |
|
|
733 |
!SyntaxHighlighter2 class methodsFor:'documentation'!
|
|
734 |
|
|
735 |
version_CVS
|
|
736 |
^ '$Header: /cvs/stx/stx/libtool/SyntaxHighlighter2.st,v 1.1 2011-07-01 14:19:38 cg Exp $'
|
|
737 |
!
|
|
738 |
|
|
739 |
version_SVN
|
|
740 |
^ '§Id: SyntaxHighlighter2.st 7715 2011-04-10 16:32:58Z vranyj1 §'
|
|
741 |
! !
|