author | Claus Gittinger <cg@exept.de> |
Tue, 28 Jan 2020 17:19:05 +0100 | |
changeset 4621 | cf9b7c0d6fbf |
parent 4578 | 6a1d8da4191d |
child 4669 | c0e6828144eb |
permissions | -rw-r--r-- |
4568 | 1 |
"{ Encoding: utf8 }" |
2 |
||
2506 | 3 |
" |
4 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
2371 | 14 |
"{ Package: 'stx:libcomp' }" |
15 |
||
3561
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
16 |
"{ NameSpace: Smalltalk }" |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
17 |
|
2371 | 18 |
Parser subclass:#AbstractSyntaxHighlighter |
4202 | 19 |
instanceVariableNames:'method sourceText preferences fullSelectorCheck commentColor |
20 |
commentEmphasis commentFont constantColor constantEmphasis' |
|
2371 | 21 |
classVariableNames:'' |
22 |
poolDictionaries:'' |
|
23 |
category:'System-Compiler' |
|
24 |
! |
|
25 |
||
2506 | 26 |
!AbstractSyntaxHighlighter class methodsFor:'documentation'! |
27 |
||
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
31 |
All Rights Reserved |
|
32 |
||
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
3345
718b64ff3db3
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3344
diff
changeset
|
40 |
! |
718b64ff3db3
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3344
diff
changeset
|
41 |
|
718b64ff3db3
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3344
diff
changeset
|
42 |
documentation |
718b64ff3db3
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3344
diff
changeset
|
43 |
" |
718b64ff3db3
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3344
diff
changeset
|
44 |
common superclass for (smalltalk-) syntax highlighting. |
3599 | 45 |
|
46 |
This will parse the source code and update the local copy of the |
|
47 |
sourceText (in that instvar) by changing emphasis and color, |
|
48 |
as syntax elements are encountered. |
|
49 |
This is done by redefining appropriate markXXX methods, which are |
|
50 |
called by the parser whenever an interesting syntactic construct is encountered. |
|
51 |
These methods are no-ops in the Parser class, but redefined here to update |
|
52 |
the colorization of sourceText. |
|
4200 | 53 |
|
54 |
Caveat: |
|
55 |
used to be a smalltalk syntax highlighter and therefore (wrongly) subclassed Parser. |
|
56 |
However, over time, much functionality was added, which is of use for other languages also |
|
57 |
and this class will therefore be changed to use composition and have parsing delegated. |
|
58 |
to be independent of the language and to not inherit stuff, which is not needed. |
|
3345
718b64ff3db3
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3344
diff
changeset
|
59 |
" |
2506 | 60 |
! ! |
2371 | 61 |
|
62 |
!AbstractSyntaxHighlighter class methodsFor:'api highlighting'! |
|
63 |
||
64 |
formatClassDefinition:aString in:aClass |
|
65 |
"format (recolor) a class definition expression in a given class. |
|
66 |
Return the text containing font changes and color information." |
|
67 |
||
68 |
^ self formatExpression:aString in:aClass |
|
69 |
! |
|
70 |
||
2506 | 71 |
formatClassDefinition:aString in:aClass elementsInto: elements |
72 |
"format (recolor) a class definition expression in a given class. |
|
73 |
Return the text containing font changes and color information." |
|
74 |
||
75 |
^ self formatExpression:aString in:aClass |
|
76 |
||
77 |
"Created: / 10-04-2011 / 18:18:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
78 |
! |
|
79 |
||
2371 | 80 |
formatExpression:aString in:aClass |
81 |
"format (recolor) an expression in a given class. |
|
82 |
Return the text containing font changes and color information." |
|
83 |
||
4568 | 84 |
|parser| |
2371 | 85 |
|
86 |
aString isNil ifTrue:[^ nil]. |
|
87 |
||
88 |
parser := self for:(ReadStream on:aString string) in:aClass. |
|
4568 | 89 |
^ parser formatExpression:aString in:aClass |
2371 | 90 |
|
91 |
" |
|
92 |
self |
|
3599 | 93 |
formatExpression:'(1 + 2) max:5' |
94 |
in:UndefinedObject |
|
2371 | 95 |
" |
96 |
||
97 |
"Modified: / 7.4.1998 / 09:57:19 / cg" |
|
98 |
"Created: / 9.4.1998 / 16:57:16 / cg" |
|
99 |
! |
|
100 |
||
101 |
formatMethod:aString in:aClass |
|
3191 | 102 |
<resource: #obsolete> |
2371 | 103 |
"format (recolor) a method in a given class. |
104 |
Return the text containing font changes and color information." |
|
105 |
||
106 |
self obsoleteMethodWarning:'use #formatMethodSource:in:'. |
|
107 |
^ self formatMethod:nil source:aString in:aClass using:nil |
|
108 |
||
109 |
" |
|
110 |
self |
|
3469 | 111 |
formatMethod:'foo |
2371 | 112 |
^ self bar:''hello''. |
113 |
||
114 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
115 |
' |
|
3469 | 116 |
in:UndefinedObject |
2371 | 117 |
" |
118 |
||
119 |
"Modified: / 28-04-2010 / 13:03:04 / cg" |
|
120 |
! |
|
121 |
||
122 |
formatMethod:aString in:aClass using:preferencesOrNil |
|
3191 | 123 |
<resource: #obsolete> |
2371 | 124 |
"format (recolor) a method in a given class. |
125 |
Return the text containing font changes and color information." |
|
126 |
||
127 |
self obsoleteMethodWarning:'use #formatMethodSource:in:using:'. |
|
128 |
^ self formatMethod:nil source:aString in:aClass using:preferencesOrNil |
|
129 |
||
130 |
"Modified: / 28-04-2010 / 13:03:15 / cg" |
|
131 |
! |
|
132 |
||
133 |
formatMethod:methodOrNil source:aString in:aClass |
|
134 |
"format (recolor) a method in a given class. |
|
135 |
Return the text containing font changes and color information." |
|
136 |
||
137 |
^ self formatMethod:methodOrNil source:aString in:aClass using:nil |
|
138 |
||
139 |
" |
|
140 |
self |
|
3469 | 141 |
formatMethod:'foo |
2371 | 142 |
^ self bar:''hello''. |
143 |
||
144 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
145 |
' |
|
3469 | 146 |
in:UndefinedObject |
2371 | 147 |
" |
148 |
||
149 |
"Created: / 28-04-2010 / 13:44:24 / cg" |
|
150 |
! |
|
151 |
||
152 |
formatMethod:methodOrNil source:aString in:aClass using:preferencesOrNil |
|
153 |
"format (recolor) a method in a given class. |
|
154 |
Return the text containing font changes and color information." |
|
155 |
||
156 |
aString isNil ifTrue:[^ nil]. |
|
4568 | 157 |
^ (self for:aString in:aClass) |
158 |
formatMethod:methodOrNil source:aString in:aClass using:preferencesOrNil |
|
3599 | 159 |
|
2371 | 160 |
" |
161 |
self |
|
3599 | 162 |
formatMethod:'foo |
2371 | 163 |
^ self bar:''hello''. |
164 |
||
165 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
166 |
' |
|
3599 | 167 |
in:UndefinedObject |
2371 | 168 |
" |
169 |
||
170 |
"Created: / 28-04-2010 / 13:01:42 / cg" |
|
2527
a87cf2c8edf2
changed: #formatMethod:source:in:using:
Claus Gittinger <cg@exept.de>
parents:
2526
diff
changeset
|
171 |
"Modified: / 05-07-2011 / 11:22:20 / cg" |
4323 | 172 |
"Modified: / 22-12-2018 / 09:01:10 / Claus Gittinger" |
2371 | 173 |
! |
174 |
||
175 |
formatMethodSource:aString in:aClass |
|
176 |
"format (recolor) a method in a given class. |
|
177 |
Return the text containing font changes and color information." |
|
178 |
||
179 |
^ self formatMethod:nil source:aString in:aClass using:nil |
|
180 |
||
181 |
" |
|
182 |
self |
|
3469 | 183 |
formatMethod:'foo |
2371 | 184 |
^ self bar:''hello''. |
185 |
||
186 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
187 |
' |
|
3469 | 188 |
in:UndefinedObject |
2371 | 189 |
" |
190 |
||
191 |
"Created: / 28-04-2010 / 12:58:13 / cg" |
|
192 |
! |
|
193 |
||
194 |
formatMethodSource:aString in:aClass using:preferencesOrNil |
|
195 |
"format (recolor) a method in a given class. |
|
196 |
Return the text containing font changes and color information." |
|
197 |
||
198 |
^ self formatMethod:nil source:aString in:aClass using:preferencesOrNil |
|
199 |
||
200 |
"Modified: / 28-04-2010 / 13:02:11 / cg" |
|
201 |
! ! |
|
202 |
||
3599 | 203 |
!AbstractSyntaxHighlighter class methodsFor:'highlighting'! |
204 |
||
205 |
colorize:text forErrorAtPosition:pos withOriginal:originalString |
|
206 |
|eColor endPos| |
|
207 |
||
208 |
endPos := pos + 1. |
|
209 |
||
210 |
"/ mhmh - which is better ... |
|
211 |
||
212 |
"/ alternative1: colorize the rest after the error in red |
|
213 |
||
214 |
eColor := UserPreferences current errorColor. |
|
215 |
eColor notNil ifTrue:[ |
|
216 |
^ text |
|
217 |
emphasizeFrom:endPos |
|
218 |
to:text size |
|
219 |
with:(#color->eColor). |
|
220 |
]. |
|
221 |
||
222 |
"/ alternative2: take the original emphasis for the rest |
|
223 |
endPos >= text size ifTrue:[ |
|
224 |
^ text |
|
225 |
] ifFalse:[ |
|
226 |
^ (text copyTo:endPos) , (originalString copyFrom:(endPos+1)) |
|
227 |
]. |
|
228 |
||
229 |
"/ alternative3: no emphasis for rest. |
|
230 |
^ text |
|
231 |
! ! |
|
232 |
||
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
233 |
!AbstractSyntaxHighlighter class methodsFor:'misc'! |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
234 |
|
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
235 |
collectionEnumerationSelectors |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
236 |
"these are considered wellknown, builtin selectors of very common |
3469 | 237 |
collection enumeration methods. |
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
238 |
These are optionally shown with another color (dark green)" |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
239 |
|
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
240 |
^ #( |
3469 | 241 |
collect: |
242 |
select: |
|
243 |
inject:into: |
|
244 |
count: |
|
245 |
collect:thenSelect: |
|
246 |
select:thenCollect: |
|
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
247 |
) |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
248 |
|
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
249 |
"Created: / 14-02-2012 / 15:56:59 / cg" |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
250 |
! |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
251 |
|
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
252 |
controlFlowSelectors |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
253 |
"these are considered wellknown, builtin selectors of very common |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
254 |
control flow constructs. Correspond to syntax or special forms in other |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
255 |
languages. These are optionally shown with another color (blue)" |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
256 |
|
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
257 |
^ #( |
3977 | 258 |
ifTrue: ifFalse: |
259 |
ifTrue:ifFalse: ifFalse:ifTrue: |
|
260 |
ifNil: ifNotNil: |
|
261 |
ifNil:ifNotNil: ifNotNil:ifNil: |
|
262 |
and: or: |
|
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
263 |
|
3977 | 264 |
whileTrue: |
265 |
whileFalse: |
|
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
266 |
|
3977 | 267 |
to:do: |
268 |
downTo:do: |
|
269 |
to:by:do: |
|
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
270 |
|
3977 | 271 |
loop |
272 |
repeat |
|
273 |
whileTrue |
|
274 |
whileFalse |
|
275 |
doWhile: |
|
276 |
doUntil: |
|
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
277 |
|
3977 | 278 |
do: |
279 |
doWithIndex: |
|
280 |
pairWiseDo: |
|
281 |
keysAndValuesDo: |
|
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
282 |
|
3977 | 283 |
withPriority:do: |
284 |
handle:do: |
|
285 |
on:do: |
|
286 |
catch: |
|
287 |
ignoreIn: |
|
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
288 |
|
3977 | 289 |
"/ newProcess |
290 |
fork: |
|
291 |
ensure: |
|
292 |
ifCurtailed: |
|
293 |
valueOnUnwindDo: |
|
294 |
valueNowOrOnUnwindDo: |
|
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
295 |
|
3977 | 296 |
caseOf: |
297 |
caseOf:otherwise: |
|
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
298 |
) |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
299 |
|
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
300 |
"Created: / 08-09-2006 / 15:56:47 / cg" |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
301 |
! |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
302 |
|
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
303 |
debugSelectors |
3235
6385bfe15842
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3231
diff
changeset
|
304 |
"these are considered harmful if left in a deployed application: |
6385bfe15842
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3231
diff
changeset
|
305 |
selectors for debugging which open a debugger (unless haltSignal is |
3469 | 306 |
caught or disabled, which end-user apps should do). |
3235
6385bfe15842
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3231
diff
changeset
|
307 |
These are optionally shown with another color (redish)" |
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
308 |
|
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
309 |
^ #( |
3469 | 310 |
halt halt: |
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
311 |
) |
3235
6385bfe15842
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3231
diff
changeset
|
312 |
|
6385bfe15842
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3231
diff
changeset
|
313 |
"Modified (comment): / 27-07-2013 / 11:45:07 / cg" |
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
314 |
! |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
315 |
|
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
316 |
errorRaisingSelectors |
3469 | 317 |
"these are error raisers. |
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
318 |
These are optionally shown with another color (red)" |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
319 |
|
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
320 |
^ #( |
4272 | 321 |
error error: error:mayProceed: proceedableError: |
322 |
raise raiseRequest: |
|
323 |
raiseErrorString: raiseRequestErrorString: |
|
324 |
raiseWith: raiseRequestWith: |
|
325 |
raiseWith:errorString: raiseRequestWith:errorString: |
|
326 |
subclassResponsibility |
|
327 |
obsoleteMethodWarning obsoleteMethodWarning: |
|
328 |
||
329 |
shouldNeverBeReached shouldNeverBeSent |
|
330 |
shouldNotImplement shouldImplement |
|
331 |
subscriptBoundsError typeCheckError |
|
332 |
||
333 |
elementBoundsError errorInvalidFormat |
|
334 |
elementNotCharacter elementNotInteger |
|
335 |
errorKeyNotFound: errorNotFound errorNotFound: |
|
336 |
indexNotInteger indexNotInteger: |
|
337 |
indexNotIntegerOrOutOfBounds: |
|
338 |
mustBeRectangle mustBeString notIndexed |
|
339 |
notYetImplemented primitiveFailed |
|
340 |
||
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
341 |
) |
4272 | 342 |
|
343 |
"Modified: / 28-05-2018 / 15:02:43 / Claus Gittinger" |
|
3342
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
344 |
! |
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
345 |
|
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
346 |
isControlFlowSelector:aSelector |
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
347 |
"these are considered wellknown, builtin selectors of very common |
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
348 |
control flow constructs. Correspond to syntax or special forms in other |
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
349 |
languages. These are optionally shown with another color (blue)" |
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
350 |
|
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
351 |
(self controlFlowSelectors includesIdentical:aSelector) ifTrue:[^ true]. |
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
352 |
|
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
353 |
true "((aSelector startsWith:'with') or:[ aSelector startsWith:'all'])" ifTrue:[ |
3469 | 354 |
((aSelector endsWith:'do:') or:[ aSelector endsWith:'Do:']) ifTrue:[ |
355 |
^ true |
|
356 |
] |
|
3342
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
357 |
]. |
d7aec03dc509
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3264
diff
changeset
|
358 |
^ false. |
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
359 |
! ! |
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
360 |
|
3732 | 361 |
!AbstractSyntaxHighlighter class methodsFor:'queries'! |
362 |
||
363 |
isAbstract |
|
364 |
^ self == AbstractSyntaxHighlighter |
|
365 |
! ! |
|
366 |
||
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
367 |
!AbstractSyntaxHighlighter class methodsFor:'utilities'! |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
368 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
369 |
mark:sourceText from:pos1 to:pos2 withAddedEmphasis:addedEmphasis |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
370 |
sourceText emphasisFrom:pos1 to:pos2 add:addedEmphasis |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
371 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
372 |
"Created: / 01-06-2012 / 21:43:36 / cg" |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
373 |
! |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
374 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
375 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn |
3352
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
376 |
self mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:nil |
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
377 |
! |
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
378 |
|
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
379 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontIn |
4202 | 380 |
"all positions are 1-based" |
381 |
||
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
382 |
|e p2 clr| |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
383 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
384 |
(clrIn isNil or:[clrIn = Color black]) ifTrue:[ |
4202 | 385 |
e := fontEmp |
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
386 |
] ifFalse:[ |
4202 | 387 |
clr := clrIn onDevice:Screen current. |
388 |
fontEmp isNil ifTrue:[ |
|
389 |
e := (#color->clr) |
|
390 |
] ifFalse:[ |
|
391 |
e := Text addEmphasis:fontEmp to:(#color->clr). |
|
392 |
] |
|
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
393 |
]. |
3352
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
394 |
fontIn notNil ifTrue:[ |
4202 | 395 |
e := Text addEmphasis:e to:(#font->fontIn) |
3352
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
396 |
]. |
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
397 |
|
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
398 |
(p2 := pos2) isNil ifTrue:[ |
4202 | 399 |
p2 := sourceText size |
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
400 |
] ifFalse:[ |
4202 | 401 |
p2 := p2 min:sourceText size |
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
402 |
]. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
403 |
sourceText emphasizeFrom:pos1 to:p2 with:e |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
404 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
405 |
"Created: / 01-06-2012 / 21:42:41 / cg" |
4202 | 406 |
"Modified (comment): / 21-10-2017 / 14:24:20 / cg" |
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
407 |
! |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
408 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
409 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
410 |
|e p2 clr fgClr| |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
411 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
412 |
fgClr := fgClr1 ? fgClr2. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
413 |
(fgClr isNil or:[fgClr = Color black]) ifTrue:[ |
3469 | 414 |
e := fontEmp |
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
415 |
] ifFalse:[ |
3469 | 416 |
clr := fgClr onDevice:Screen current. |
417 |
fontEmp isNil ifTrue:[ |
|
418 |
e := (#color->clr) |
|
419 |
] ifFalse:[ |
|
420 |
e := Text addEmphasis:fontEmp to:(#color->clr). |
|
421 |
] |
|
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
422 |
]. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
423 |
bgClr notNil ifTrue:[ |
3469 | 424 |
e := Text addEmphasis:(#backgroundColor->bgClr) to:e. |
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
425 |
]. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
426 |
(p2 := pos2) isNil ifTrue:[ |
3469 | 427 |
p2 := sourceText size |
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
428 |
] ifFalse:[ |
3469 | 429 |
p2 := p2 min:sourceText size |
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
430 |
]. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
431 |
sourceText emphasizeFrom:pos1 to:p2 with:e |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
432 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
433 |
"Created: / 01-06-2012 / 21:44:17 / cg" |
3561
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
434 |
! |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
435 |
|
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
436 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp ifNil:fontEmp2 color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
437 |
|e p2 clr fgClr| |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
438 |
|
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
439 |
fgClr := fgClr1 ? fgClr2. |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
440 |
(fgClr isNil or:[fgClr = Color black]) ifTrue:[ |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
441 |
e := fontEmp ? fontEmp2 |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
442 |
] ifFalse:[ |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
443 |
clr := fgClr onDevice:Screen current. |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
444 |
(fontEmp ? fontEmp2) isNil ifTrue:[ |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
445 |
e := (#color->clr) |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
446 |
] ifFalse:[ |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
447 |
e := Text addEmphasis:(fontEmp ? fontEmp2) to:(#color->clr). |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
448 |
] |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
449 |
]. |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
450 |
bgClr notNil ifTrue:[ |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
451 |
e := Text addEmphasis:(#backgroundColor->bgClr) to:e. |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
452 |
]. |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
453 |
(p2 := pos2) isNil ifTrue:[ |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
454 |
p2 := sourceText size |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
455 |
] ifFalse:[ |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
456 |
p2 := p2 min:sourceText size |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
457 |
]. |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
458 |
sourceText emphasizeFrom:pos1 to:p2 with:e |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
459 |
|
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
460 |
"Created: / 01-06-2012 / 21:44:17 / cg" |
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
461 |
! ! |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
462 |
|
2371 | 463 |
!AbstractSyntaxHighlighter methodsFor:'accessing'! |
464 |
||
4202 | 465 |
fetchHeavilyUsedPreferenceValues |
466 |
preferences isNil ifTrue:[ |
|
467 |
commentColor := commentEmphasis := commentFont := nil. |
|
468 |
constantColor := constantEmphasis := nil. |
|
469 |
^ self. |
|
470 |
]. |
|
471 |
||
472 |
commentColor := preferences commentColor. |
|
473 |
commentEmphasis := preferences commentEmphasis. |
|
474 |
commentFont := preferences commentFont. |
|
475 |
||
476 |
constantColor := preferences constantColor. |
|
477 |
constantEmphasis := preferences constantEmphasis. |
|
478 |
||
479 |
"Created: / 21-10-2017 / 14:13:33 / cg" |
|
480 |
! |
|
481 |
||
2371 | 482 |
method:aMethod |
2525 | 483 |
"the original method, if known (for subclasses which can make use of it)" |
484 |
||
485 |
method := aMethod. |
|
2371 | 486 |
|
487 |
"Created: / 28-04-2010 / 13:15:33 / cg" |
|
488 |
! |
|
489 |
||
4202 | 490 |
preferences:aUserPreferencesInstance |
491 |
preferences := aUserPreferencesInstance. |
|
492 |
||
493 |
fullSelectorCheck := preferences fullSelectorCheck. |
|
494 |
self fetchHeavilyUsedPreferenceValues. |
|
495 |
||
496 |
"Modified: / 21-10-2017 / 14:20:06 / cg" |
|
2371 | 497 |
! |
498 |
||
499 |
sourceText |
|
3599 | 500 |
"retrieve the updated source text after the highlighting process" |
501 |
||
2371 | 502 |
^ sourceText |
503 |
||
504 |
"Created: / 31.3.1998 / 11:49:05 / cg" |
|
505 |
! |
|
506 |
||
507 |
sourceText:aString |
|
3599 | 508 |
"this text will be updated by the highlighting process" |
509 |
||
2371 | 510 |
sourceText := aString. |
511 |
||
512 |
"Created: / 31-03-1998 / 11:49:05 / cg" |
|
513 |
"Modified: / 28-04-2010 / 13:22:27 / cg" |
|
514 |
! ! |
|
515 |
||
4568 | 516 |
!AbstractSyntaxHighlighter methodsFor:'api highlighting'! |
517 |
||
518 |
formatExpression:aString in:aClass |
|
519 |
"format (recolor) an expression in a given class. |
|
520 |
Return the text containing font changes and color information." |
|
521 |
||
522 |
|tree text| |
|
523 |
||
524 |
aString isNil ifTrue:[^ nil]. |
|
525 |
||
526 |
self ignoreErrors:true. |
|
527 |
self ignoreWarnings:true. |
|
528 |
self sourceText:(text := aString string asText). |
|
529 |
"/ use an array here - this can be changed much faster using #at:put: |
|
530 |
text emphasisCollection:(Array new:aString size). |
|
531 |
||
532 |
self nextToken. |
|
533 |
tree := self expression. |
|
4578 | 534 |
tree notNil ifTrue:[ |
535 |
"/ now, convert the emphasis-array to a runArray |
|
536 |
text emphasisCollection:(text emphasis asRunArray). |
|
4568 | 537 |
|
4578 | 538 |
tree == #Error ifTrue:[ |
539 |
^ self class colorize:text forErrorAtPosition:(self sourceStream position) withOriginal:aString. |
|
540 |
]. |
|
4568 | 541 |
]. |
542 |
^ text |
|
543 |
||
544 |
" |
|
545 |
self |
|
546 |
formatExpression:'(1 + 2) max:5' |
|
547 |
in:UndefinedObject |
|
548 |
" |
|
549 |
||
550 |
"Modified: / 7.4.1998 / 09:57:19 / cg" |
|
551 |
"Created: / 9.4.1998 / 16:57:16 / cg" |
|
552 |
! |
|
553 |
||
554 |
formatMethod:methodOrNil source:aString in:aClass using:preferencesOrNil |
|
555 |
"format (recolor) a method in a given class. |
|
556 |
Return the text containing font changes and color information." |
|
557 |
||
558 |
|tree newText| |
|
559 |
||
560 |
aString isNil ifTrue:[^ nil]. |
|
561 |
||
562 |
Error handle:[:ex | |
|
563 |
"/ Transcript showCR:ex description. |
|
564 |
"/ self breakPoint:#cg. |
|
565 |
||
566 |
(ParseError handles:ex) ifFalse:[ |
|
567 |
ex creator isHandled ifTrue:[ |
|
568 |
"/ Transcript showCR:'handled' . |
|
569 |
ex reject. |
|
570 |
]. |
|
571 |
"Parse error may happen when re-formatting incomplete code while editing" |
|
572 |
"/ ('SyntaxHighlighter [info]: error during highlight: ' , ex description) infoPrintCR. |
|
573 |
"/ ex suspendedContext fullPrintAll. |
|
574 |
]. |
|
575 |
^ self class colorize:(newText ? aString) forErrorAtPosition:(self sourceStream position) withOriginal:aString |
|
576 |
] do:[ |
|
577 |
|sourceString| |
|
578 |
||
579 |
sourceString := aString string. |
|
580 |
source := sourceString readStream. |
|
581 |
newText := sourceString asUnicode16String asText. |
|
582 |
"/ use an array here (instead of the RunArray) - this can be changed much faster using #at:put: |
|
583 |
newText emphasisCollection:(Array new:sourceString size). |
|
584 |
||
585 |
self method:methodOrNil. |
|
586 |
preferencesOrNil notNil ifTrue:[self preferences:preferencesOrNil]. |
|
587 |
"/ self ignoreErrors:true. |
|
588 |
self ignoreWarnings:true. |
|
589 |
self sourceText:newText. |
|
590 |
||
591 |
tree := self parseMethod. |
|
4578 | 592 |
tree notNil ifTrue:[ |
593 |
newText := self sourceText. "/ might have changed identity |
|
594 |
"/ now, convert the emphasis-array to a runArray |
|
595 |
newText emphasisCollection:(newText emphasis asRunArray). |
|
4568 | 596 |
|
4578 | 597 |
tree == #Error ifTrue:[ |
598 |
^ self class colorize:newText forErrorAtPosition:source position withOriginal:aString. |
|
599 |
]. |
|
600 |
self postProcessTree:tree forText:newText |
|
601 |
]. |
|
4568 | 602 |
^ newText |
603 |
] |
|
604 |
||
605 |
" |
|
606 |
self |
|
607 |
formatMethod:'foo |
|
608 |
^ self bar:''hello''. |
|
609 |
||
610 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
611 |
' |
|
612 |
in:UndefinedObject |
|
613 |
" |
|
614 |
||
615 |
"Created: / 28-04-2010 / 13:01:42 / cg" |
|
616 |
"Modified: / 05-07-2011 / 11:22:20 / cg" |
|
617 |
"Modified: / 22-12-2018 / 09:01:10 / Claus Gittinger" |
|
618 |
! ! |
|
619 |
||
2371 | 620 |
!AbstractSyntaxHighlighter methodsFor:'error handling'! |
621 |
||
622 |
parseError:aMessage position:position to:endPos |
|
623 |
"/ Transcript showCR:aMessage. |
|
624 |
super parseError:aMessage position:position to:endPos. |
|
625 |
||
4264 | 626 |
self markErrorFrom:position to:endPos |
2371 | 627 |
! |
628 |
||
629 |
showErrorMessage:aMessage position:pos |
|
630 |
"/ Transcript showCR:aMessage. |
|
631 |
super showErrorMessage:aMessage position:pos. |
|
632 |
||
4264 | 633 |
self markErrorFrom:pos to:nil "/ to the end |
2371 | 634 |
! |
635 |
||
636 |
syntaxError:aMessage position:position to:endPos |
|
637 |
"/ Transcript showCR:aMessage. |
|
638 |
super syntaxError:aMessage position:position to:endPos. |
|
639 |
||
4264 | 640 |
self markErrorFrom:position to:endPos |
2371 | 641 |
! |
642 |
||
643 |
warning:msg position:pos1 to:pos2 |
|
644 |
"/ self markUnknownIdentifierFrom:pos1 to:pos2 |
|
645 |
||
646 |
"/ self |
|
3469 | 647 |
"/ markFrom:pos1 to:pos2 |
2371 | 648 |
"/ withEmphasis:nil color:UserPreferences current errorColor |
649 |
||
650 |
"Modified: / 25.9.1999 / 18:42:30 / cg" |
|
651 |
! ! |
|
652 |
||
653 |
!AbstractSyntaxHighlighter methodsFor:'initialization'! |
|
654 |
||
655 |
initialize |
|
4114 | 656 |
<modifier: #super> "must be called if redefined" |
657 |
||
2371 | 658 |
super initialize. |
659 |
||
660 |
foldConstants := false. |
|
4202 | 661 |
self preferences:(UserPreferences current). |
2371 | 662 |
|
663 |
"Created: / 31-03-1998 / 15:12:55 / cg" |
|
4202 | 664 |
"Modified: / 21-10-2017 / 14:20:11 / cg" |
2371 | 665 |
! ! |
666 |
||
667 |
!AbstractSyntaxHighlighter methodsFor:'misc'! |
|
668 |
||
2817
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
669 |
collectionEnumerationSelectors |
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
670 |
^ self class collectionEnumerationSelectors |
2817
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
671 |
! |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
672 |
|
2371 | 673 |
controlFlowSelectors |
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
674 |
^ self class controlFlowSelectors |
2371 | 675 |
! |
676 |
||
3228
e276f545e004
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3216
diff
changeset
|
677 |
debugSelectors |
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
678 |
^ self class debugSelectors |
3228
e276f545e004
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3216
diff
changeset
|
679 |
! |
e276f545e004
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3216
diff
changeset
|
680 |
|
2371 | 681 |
defineAsUndeclaredVariable:aName |
682 |
"redefined to NOT declare undefined vars" |
|
683 |
||
684 |
^ VariableNode globalNamed:aName |
|
685 |
||
686 |
"Modified: / 19.10.1998 / 19:38:12 / cg" |
|
687 |
! |
|
688 |
||
3228
e276f545e004
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3216
diff
changeset
|
689 |
errorRaisingSelectors |
3231
44b2709db25e
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3228
diff
changeset
|
690 |
^ self class errorRaisingSelectors |
3228
e276f545e004
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3216
diff
changeset
|
691 |
! |
e276f545e004
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3216
diff
changeset
|
692 |
|
2371 | 693 |
isSyntaxHighlighter |
694 |
^ true |
|
695 |
||
696 |
! |
|
697 |
||
698 |
plausibilityCheck:aNode |
|
699 |
"redefined to NOT do checks" |
|
700 |
||
701 |
^ nil |
|
702 |
||
703 |
"Modified: / 19.10.1998 / 19:38:12 / cg" |
|
704 |
"Created: / 19.10.1998 / 19:57:18 / cg" |
|
705 |
! ! |
|
706 |
||
707 |
!AbstractSyntaxHighlighter methodsFor:'syntax detection'! |
|
708 |
||
4202 | 709 |
markCommentFrom:pos1 to:pos2 |
710 |
"all positions are 1-based" |
|
711 |
||
712 |
self |
|
713 |
markFrom:pos1 to:pos2 |
|
714 |
withEmphasis:commentEmphasis |
|
715 |
color:commentColor |
|
716 |
font:commentFont |
|
717 |
||
718 |
" |
|
719 |
UserPreferences current commentEmphasis |
|
720 |
UserPreferences current commentColor |
|
721 |
" |
|
722 |
||
723 |
"Modified (comment): / 21-10-2017 / 14:24:51 / cg" |
|
724 |
! |
|
725 |
||
726 |
markConstantFrom:pos1 to:pos2 |
|
727 |
self |
|
728 |
markFrom:pos1 to:pos2 |
|
729 |
withEmphasis:constantEmphasis |
|
730 |
color:constantColor |
|
731 |
||
732 |
"Created: / 31-03-1998 / 18:09:22 / cg" |
|
733 |
"Modified: / 21-10-2017 / 14:15:48 / cg" |
|
734 |
! |
|
735 |
||
4264 | 736 |
markErrorFrom:pos1 to:pos2 |
737 |
self |
|
738 |
markFrom:pos1 to:pos2 |
|
739 |
withEmphasis:nil color:UserPreferences current errorColor |
|
740 |
! |
|
741 |
||
4202 | 742 |
markFrom:pos1 length:len withEmphasis:fontEmp color:clrIn |
743 |
self markFrom:pos1 to:pos1+len-1 withEmphasis:fontEmp color:clrIn |
|
744 |
||
745 |
"Created: / 21-10-2017 / 14:47:46 / cg" |
|
746 |
! |
|
747 |
||
2371 | 748 |
markFrom:pos1 to:pos2 withAddedEmphasis:addedEmphasis |
3469 | 749 |
self class |
750 |
mark:sourceText from:pos1 to:pos2 withAddedEmphasis:addedEmphasis |
|
2371 | 751 |
|
752 |
"Created: / 15-01-2008 / 11:48:18 / cg" |
|
753 |
! |
|
754 |
||
755 |
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:clrIn |
|
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
756 |
self class |
3469 | 757 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn |
2371 | 758 |
|
759 |
"Created: / 31-03-1998 / 13:26:53 / cg" |
|
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
760 |
"Modified: / 01-06-2012 / 21:43:04 / cg" |
2371 | 761 |
! |
762 |
||
3352
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
763 |
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontInOrNil |
4202 | 764 |
"all positions are 1-based" |
765 |
||
3352
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
766 |
self class |
4202 | 767 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontInOrNil |
3352
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
768 |
|
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
769 |
"Created: / 31-03-1998 / 13:26:53 / cg" |
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
770 |
"Modified: / 01-06-2012 / 21:43:04 / cg" |
4202 | 771 |
"Modified (comment): / 21-10-2017 / 14:24:47 / cg" |
3352
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
772 |
! |
42a5ad1adb52
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3345
diff
changeset
|
773 |
|
2813
51e4b12f18dc
added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
2688
diff
changeset
|
774 |
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr |
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
775 |
self class |
3469 | 776 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr |
2813
51e4b12f18dc
added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
2688
diff
changeset
|
777 |
|
51e4b12f18dc
added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
2688
diff
changeset
|
778 |
"Created: / 13-02-2012 / 11:48:09 / cg" |
51e4b12f18dc
added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
2688
diff
changeset
|
779 |
! |
51e4b12f18dc
added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
2688
diff
changeset
|
780 |
|
3561
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
781 |
markFrom:pos1 to:pos2 withEmphasis:fontEmp ifNil:fontEmp2 color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
782 |
self class |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
783 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp ifNil:fontEmp2 color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
784 |
|
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
785 |
"Created: / 13-02-2012 / 11:48:09 / cg" |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
786 |
! |
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
787 |
|
2371 | 788 |
markVariable:v |
789 |
|pos endPos| |
|
790 |
||
791 |
pos := tokenPosition. |
|
792 |
endPos := pos+tokenName size-1. |
|
3189
5a4bb1727d08
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3145
diff
changeset
|
793 |
self markVariable:v from:pos to:endPos assigned:false |
2371 | 794 |
|
2464
595ec0d9efa9
comment/format in: #markVariable:
Claus Gittinger <cg@exept.de>
parents:
2392
diff
changeset
|
795 |
"Modified: / 30-11-2010 / 14:44:28 / cg" |
4578 | 796 |
! |
797 |
||
798 |
postProcessTree:tree forText:text |
|
799 |
"allows for additional checks to be done on the tree |
|
800 |
(checking arguments to a call-node in expecco, for example)" |
|
801 |
||
802 |
"/ intentionaly left blank here. |
|
803 |
||
2371 | 804 |
! ! |
805 |
||
806 |
!AbstractSyntaxHighlighter class methodsFor:'documentation'! |
|
807 |
||
2663
e94fe6b650ad
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2662
diff
changeset
|
808 |
version |
3675 | 809 |
^ '$Header$' |
2663
e94fe6b650ad
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2662
diff
changeset
|
810 |
! |
e94fe6b650ad
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2662
diff
changeset
|
811 |
|
2371 | 812 |
version_CVS |
3675 | 813 |
^ '$Header$' |
2506 | 814 |
! |
815 |
||
816 |
version_SVN |
|
3189
5a4bb1727d08
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3145
diff
changeset
|
817 |
^ '$ Id $' |
2371 | 818 |
! ! |
3561
f04a8db1590f
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
819 |