author | Claus Gittinger <cg@exept.de> |
Tue, 07 Apr 1998 11:11:39 +0200 | |
changeset 681 | 3add270b9c1e |
parent 680 | ebc432c71aec |
child 684 | dd691ac07f90 |
permissions | -rw-r--r-- |
662 | 1 |
" |
2 |
COPYRIGHT (c) 1998 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 |
||
13 |
||
14 |
||
15 |
Parser subclass:#SyntaxHighlighter |
|
16 |
instanceVariableNames:'sourceText identifierColor identifierEmphasis |
|
17 |
argumentIdentifierColor argumentIdentifierEmphasis |
|
18 |
localIdentifierColor localIdentifierEmphasis |
|
665 | 19 |
unknownIdentifierColor unknownIdentifierEmphasis |
662 | 20 |
globalIdentifierColor globalIdentifierEmphasis commentColor |
21 |
commentEmphasis methodSelectorEmphasis methodSelectorColor |
|
22 |
selectorEmphasis selectorColor stringColor stringEmphasis |
|
672 | 23 |
symbolColor symbolEmphasis selfColor selfEmphasis superColor |
24 |
superEmphasis hereColor hereEmphasis thisContextColor |
|
25 |
thisContextEmphasis booleanConstantColor booleanConstantEmphasis |
|
673 | 26 |
constantColor constantEmphasis bracketColor bracketEmphasis' |
662 | 27 |
classVariableNames:'' |
28 |
poolDictionaries:'' |
|
29 |
category:'System-Compiler' |
|
30 |
! |
|
31 |
||
32 |
!SyntaxHighlighter class methodsFor:'documentation'! |
|
33 |
||
34 |
copyright |
|
35 |
" |
|
36 |
COPYRIGHT (c) 1998 by eXept Software AG |
|
37 |
All Rights Reserved |
|
38 |
||
39 |
This software is furnished under a license and may be used |
|
40 |
only in accordance with the terms of that license and with the |
|
41 |
inclusion of the above copyright notice. This software may not |
|
42 |
be provided or otherwise made available to, or used by, any |
|
43 |
other person. No title to or ownership of the software is |
|
44 |
hereby transferred. |
|
45 |
" |
|
46 |
||
47 |
||
681 | 48 |
! |
49 |
||
50 |
documentation |
|
51 |
" |
|
52 |
colors a method. |
|
53 |
" |
|
54 |
||
55 |
||
662 | 56 |
! ! |
57 |
||
58 |
!SyntaxHighlighter class methodsFor:'highlighting'! |
|
59 |
||
60 |
formatMethod:aString in:aClass |
|
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
61 |
"format (recolor) a method in a given class. |
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
62 |
Return the text containing font changes and color information." |
662 | 63 |
|
678 | 64 |
|parser tree text endPos| |
662 | 65 |
|
66 |
aString isNil ifTrue:[^ nil]. |
|
67 |
||
674 | 68 |
parser := self for:(ReadStream on:aString string) in:aClass. |
662 | 69 |
parser ignoreErrors. |
70 |
parser ignoreWarnings. |
|
674 | 71 |
parser sourceText:(text := aString string asText). |
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
72 |
"/ use an array here - this can be changed much faster using #at:put: |
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
73 |
text emphasisCollection:(Array new:aString size). |
662 | 74 |
|
75 |
tree := parser parseMethod. |
|
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
76 |
"/ now, convert the emphasis-array to a runArray |
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
77 |
text emphasisCollection:(text emphasis asRunArray). |
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
78 |
|
667 | 79 |
tree == #Error ifTrue:[ |
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
80 |
"/ mhmh - which is better ... |
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
81 |
"/ alternative1: color rest after error in red |
674 | 82 |
"/ text |
83 |
"/ emphasizeFrom:(parser sourceStream position) |
|
84 |
"/ to:text size |
|
85 |
"/ with:(#color->Color red). |
|
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
86 |
|
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
87 |
|
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
88 |
"/ alternative2: take original emphasis for rest |
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
89 |
|
678 | 90 |
endPos := parser sourceStream position. |
91 |
endPos >= text size ifTrue:[ |
|
92 |
^ text |
|
93 |
]. |
|
94 |
^ (text copyTo:endPos) , (aString copyFrom:(endPos+1)) |
|
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
95 |
|
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
96 |
"/ alternative3: no emphasis for rest. |
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
97 |
|
674 | 98 |
"/ ^ text "/ aString |
667 | 99 |
]. |
662 | 100 |
^ text |
101 |
||
102 |
" |
|
103 |
self |
|
104 |
formatMethod:'foo |
|
105 |
^ self bar:''hello''. |
|
106 |
||
107 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
108 |
' |
|
109 |
in:UndefinedObject |
|
110 |
" |
|
111 |
||
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
112 |
"Modified: / 7.4.1998 / 09:57:19 / cg" |
662 | 113 |
! ! |
114 |
||
115 |
!SyntaxHighlighter methodsFor:'accessing'! |
|
116 |
||
117 |
sourceText |
|
118 |
"return the value of the instance variable 'sourceText' (automatically generated)" |
|
119 |
||
120 |
^ sourceText |
|
121 |
||
122 |
"Created: / 31.3.1998 / 11:49:05 / cg" |
|
123 |
! |
|
124 |
||
125 |
sourceText:something |
|
126 |
"set the value of the instance variable 'sourceText' (automatically generated)" |
|
127 |
||
128 |
sourceText := something. |
|
129 |
||
130 |
"Created: / 31.3.1998 / 11:49:05 / cg" |
|
131 |
! ! |
|
132 |
||
133 |
!SyntaxHighlighter methodsFor:'initialization'! |
|
134 |
||
135 |
initialize |
|
136 |
|prefs| |
|
137 |
||
138 |
super initialize. |
|
139 |
||
140 |
prefs := UserPreferences current. |
|
141 |
identifierEmphasis := prefs identifierEmphasis. |
|
142 |
identifierColor := prefs identifierColor. |
|
143 |
argumentIdentifierEmphasis := prefs argumentIdentifierEmphasis. |
|
144 |
argumentIdentifierColor := prefs argumentIdentifierColor. |
|
145 |
localIdentifierEmphasis := prefs localIdentifierEmphasis. |
|
146 |
localIdentifierColor := prefs localIdentifierColor. |
|
147 |
globalIdentifierEmphasis := prefs globalIdentifierEmphasis. |
|
148 |
globalIdentifierColor := prefs globalIdentifierColor. |
|
665 | 149 |
unknownIdentifierEmphasis := prefs unknownIdentifierEmphasis. |
150 |
unknownIdentifierColor := prefs unknownIdentifierColor. |
|
662 | 151 |
commentEmphasis := prefs commentEmphasis. |
152 |
commentColor := prefs commentColor. |
|
153 |
methodSelectorEmphasis := prefs methodSelectorEmphasis. |
|
154 |
methodSelectorColor := prefs methodSelectorColor. |
|
155 |
selectorEmphasis := prefs selectorEmphasis. |
|
156 |
selectorColor := prefs selectorColor. |
|
157 |
stringEmphasis := prefs stringEmphasis. |
|
158 |
stringColor := prefs stringColor. |
|
672 | 159 |
symbolEmphasis := prefs symbolEmphasis. |
160 |
symbolColor := prefs symbolColor. |
|
662 | 161 |
selfEmphasis := prefs selfEmphasis. |
162 |
selfColor := prefs selfColor. |
|
163 |
hereEmphasis := prefs hereEmphasis. |
|
164 |
hereColor := prefs hereColor. |
|
165 |
superEmphasis := prefs superEmphasis. |
|
166 |
superColor := prefs superColor. |
|
167 |
thisContextEmphasis := prefs thisContextEmphasis. |
|
168 |
thisContextColor := prefs thisContextColor. |
|
169 |
constantEmphasis := prefs constantEmphasis. |
|
170 |
constantColor := prefs constantColor. |
|
171 |
booleanConstantEmphasis := prefs booleanConstantEmphasis. |
|
172 |
booleanConstantColor := prefs booleanConstantColor. |
|
673 | 173 |
bracketEmphasis := prefs bracketEmphasis. |
174 |
bracketColor := prefs bracketColor. |
|
662 | 175 |
|
176 |
"Created: / 31.3.1998 / 15:12:55 / cg" |
|
672 | 177 |
"Modified: / 1.4.1998 / 12:57:48 / cg" |
662 | 178 |
! ! |
179 |
||
180 |
!SyntaxHighlighter methodsFor:'syntax detection'! |
|
181 |
||
182 |
markArgumentIdentifierFrom:pos1 to:pos2 |
|
183 |
self |
|
184 |
markFrom:pos1 to:pos2 |
|
185 |
withEmphasis:argumentIdentifierEmphasis color:argumentIdentifierColor |
|
186 |
||
187 |
"Modified: / 31.3.1998 / 18:01:27 / cg" |
|
188 |
! |
|
189 |
||
190 |
markBooleanConstantFrom:pos1 to:pos2 |
|
191 |
self |
|
192 |
markFrom:pos1 to:pos2 |
|
665 | 193 |
withEmphasis:booleanConstantEmphasis color:booleanConstantColor |
662 | 194 |
|
195 |
"Created: / 31.3.1998 / 18:09:01 / cg" |
|
665 | 196 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
662 | 197 |
! |
198 |
||
673 | 199 |
markBracketAt:pos |
200 |
self |
|
201 |
markFrom:pos to:pos |
|
202 |
withEmphasis:bracketEmphasis color:bracketColor |
|
203 |
||
204 |
"Created: / 31.3.1998 / 18:09:01 / cg" |
|
205 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
|
206 |
! |
|
207 |
||
662 | 208 |
markCommentFrom:pos1 to:pos2 |
209 |
self |
|
210 |
markFrom:pos1 to:pos2 |
|
211 |
withEmphasis:commentEmphasis color:commentColor |
|
212 |
||
213 |
"Modified: / 31.3.1998 / 18:01:55 / cg" |
|
214 |
! |
|
215 |
||
216 |
markConstantFrom:pos1 to:pos2 |
|
217 |
self |
|
218 |
markFrom:pos1 to:pos2 |
|
219 |
withEmphasis:constantEmphasis color:constantColor |
|
220 |
||
221 |
"Modified: / 31.3.1998 / 18:01:44 / cg" |
|
222 |
"Created: / 31.3.1998 / 18:09:22 / cg" |
|
223 |
! |
|
224 |
||
225 |
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:clr |
|
226 |
|e| |
|
227 |
||
669 | 228 |
clr = Color black ifTrue:[ |
229 |
e := fontEmp |
|
230 |
] ifFalse:[ |
|
231 |
e := Text addEmphasis:fontEmp to:(#color->clr). |
|
232 |
]. |
|
662 | 233 |
sourceText emphasizeFrom:pos1 to:pos2 with:e |
234 |
||
235 |
"Created: / 31.3.1998 / 13:26:53 / cg" |
|
669 | 236 |
"Modified: / 1.4.1998 / 12:51:56 / cg" |
662 | 237 |
! |
238 |
||
239 |
markGlobalIdentifierFrom:pos1 to:pos2 |
|
240 |
self |
|
241 |
markFrom:pos1 to:pos2 |
|
242 |
withEmphasis:globalIdentifierEmphasis color:globalIdentifierColor |
|
243 |
||
244 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
245 |
! |
|
246 |
||
247 |
markHereFrom:pos1 to:pos2 |
|
248 |
self |
|
249 |
markFrom:pos1 to:pos2 |
|
250 |
withEmphasis:hereEmphasis color:hereColor |
|
251 |
||
252 |
"Modified: / 31.3.1998 / 18:02:25 / cg" |
|
253 |
! |
|
254 |
||
255 |
markIdentifierFrom:pos1 to:pos2 |
|
256 |
self |
|
257 |
markFrom:pos1 to:pos2 |
|
258 |
withEmphasis:identifierEmphasis color:identifierColor |
|
259 |
||
260 |
"Modified: / 31.3.1998 / 18:02:39 / cg" |
|
261 |
"Created: / 31.3.1998 / 18:04:56 / cg" |
|
262 |
! |
|
263 |
||
264 |
markLocalIdentifierFrom:pos1 to:pos2 |
|
265 |
self |
|
266 |
markFrom:pos1 to:pos2 |
|
267 |
withEmphasis:localIdentifierEmphasis color:localIdentifierColor |
|
268 |
||
269 |
"Modified: / 31.3.1998 / 18:02:39 / cg" |
|
270 |
! |
|
271 |
||
272 |
markMethodSelectorFrom:pos1 to:pos2 |
|
273 |
self |
|
274 |
markFrom:pos1 to:pos2 |
|
275 |
withEmphasis:methodSelectorEmphasis color:methodSelectorColor |
|
276 |
||
277 |
"Modified: / 31.3.1998 / 18:02:52 / cg" |
|
278 |
! |
|
279 |
||
280 |
markSelectorFrom:pos1 to:pos2 |
|
672 | 281 |
|
282 |
"/ uncommenting the code below |
|
283 |
"/ will suppress highlighting of common selectors ... |
|
284 |
"/ |
|
285 |
"/ (#( |
|
286 |
"/ 'ifTrue:' |
|
287 |
"/ 'ifFalse:' |
|
288 |
"/ 'not' |
|
289 |
"/ 'and:' |
|
290 |
"/ 'or:' |
|
291 |
"/ '=' |
|
292 |
"/ '==' |
|
293 |
"/ '~=' |
|
294 |
"/ '~~' |
|
295 |
"/ ) includes:tokenName) ifTrue:[ |
|
296 |
"/ ^ self |
|
297 |
"/ ]. |
|
298 |
||
662 | 299 |
self |
300 |
markFrom:pos1 to:pos2 |
|
301 |
withEmphasis:selectorEmphasis color:selectorColor |
|
302 |
||
672 | 303 |
"Modified: / 1.4.1998 / 13:14:43 / cg" |
662 | 304 |
! |
305 |
||
306 |
markSelfFrom:pos1 to:pos2 |
|
307 |
self |
|
308 |
markFrom:pos1 to:pos2 |
|
309 |
withEmphasis:selfEmphasis color:selfColor |
|
310 |
||
311 |
"Modified: / 31.3.1998 / 18:03:10 / cg" |
|
312 |
! |
|
313 |
||
314 |
markStringFrom:pos1 to:pos2 |
|
315 |
self |
|
316 |
markFrom:pos1 to:pos2 |
|
317 |
withEmphasis:stringEmphasis color:stringColor |
|
318 |
||
319 |
"Modified: / 31.3.1998 / 18:03:18 / cg" |
|
320 |
! |
|
321 |
||
322 |
markSuperFrom:pos1 to:pos2 |
|
323 |
self |
|
324 |
markFrom:pos1 to:pos2 |
|
325 |
withEmphasis:superEmphasis color:superColor |
|
326 |
||
327 |
"Modified: / 31.3.1998 / 18:03:26 / cg" |
|
328 |
! |
|
329 |
||
672 | 330 |
markSymbolFrom:pos1 to:pos2 |
331 |
self |
|
332 |
markFrom:pos1 to:pos2 |
|
333 |
withEmphasis:symbolEmphasis color:symbolColor |
|
334 |
||
335 |
"Created: / 1.4.1998 / 12:56:47 / cg" |
|
336 |
"Modified: / 1.4.1998 / 12:58:00 / cg" |
|
337 |
! |
|
338 |
||
662 | 339 |
markThisContextFrom:pos1 to:pos2 |
340 |
self |
|
341 |
markFrom:pos1 to:pos2 |
|
342 |
withEmphasis:thisContextEmphasis color:thisContextColor |
|
343 |
||
344 |
"Modified: / 31.3.1998 / 18:03:36 / cg" |
|
665 | 345 |
! |
346 |
||
347 |
markUnknownIdentifierFrom:pos1 to:pos2 |
|
348 |
self |
|
349 |
markFrom:pos1 to:pos2 |
|
350 |
withEmphasis:unknownIdentifierEmphasis color:unknownIdentifierColor |
|
351 |
||
352 |
"Created: / 31.3.1998 / 19:09:26 / cg" |
|
353 |
"Modified: / 31.3.1998 / 19:10:30 / cg" |
|
662 | 354 |
! ! |
355 |
||
356 |
!SyntaxHighlighter class methodsFor:'documentation'! |
|
357 |
||
358 |
version |
|
681 | 359 |
^ '$Header: /cvs/stx/stx/libcomp/SyntaxHighlighter.st,v 1.10 1998-04-07 09:11:39 cg Exp $' |
662 | 360 |
! ! |