author | Claus Gittinger <cg@exept.de> |
Mon, 18 Dec 2000 23:12:54 +0100 | |
changeset 1132 | b5958fa3816e |
parent 1110 | 3e08a12956fd |
child 1143 | 3a9ddfa26b16 |
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 |
||
1110 | 15 |
"{ Package: 'stx:libcomp' }" |
16 |
||
662 | 17 |
Parser subclass:#SyntaxHighlighter |
18 |
instanceVariableNames:'sourceText identifierColor identifierEmphasis |
|
19 |
argumentIdentifierColor argumentIdentifierEmphasis |
|
20 |
localIdentifierColor localIdentifierEmphasis |
|
665 | 21 |
unknownIdentifierColor unknownIdentifierEmphasis |
884 | 22 |
badIdentifierColor badIdentifierEmphasis globalIdentifierColor |
23 |
globalIdentifierEmphasis commentColor commentEmphasis |
|
24 |
methodSelectorEmphasis methodSelectorColor selectorEmphasis |
|
25 |
selectorColor stringColor stringEmphasis symbolColor |
|
26 |
symbolEmphasis selfColor selfEmphasis superColor superEmphasis |
|
27 |
hereColor hereEmphasis thisContextColor thisContextEmphasis |
|
28 |
booleanConstantColor booleanConstantEmphasis constantColor |
|
29 |
constantEmphasis bracketColor bracketEmphasis |
|
838 | 30 |
instVarIdentifierColor instVarIdentifierEmphasis returnColor |
31 |
returnEmphasis globalClassIdentifierColor |
|
870 | 32 |
globalClassIdentifierEmphasis classVariableIdentifierColor |
33 |
classVariableIdentifierEmphasis unimplementedSelectorColor |
|
868 | 34 |
unimplementedSelectorEmphasis currentSuperclasses |
863 | 35 |
currentSubclasses fullSelectorCheck' |
662 | 36 |
classVariableNames:'' |
37 |
poolDictionaries:'' |
|
38 |
category:'System-Compiler' |
|
39 |
! |
|
40 |
||
41 |
!SyntaxHighlighter class methodsFor:'documentation'! |
|
42 |
||
43 |
copyright |
|
44 |
" |
|
45 |
COPYRIGHT (c) 1998 by eXept Software AG |
|
46 |
All Rights Reserved |
|
47 |
||
48 |
This software is furnished under a license and may be used |
|
49 |
only in accordance with the terms of that license and with the |
|
50 |
inclusion of the above copyright notice. This software may not |
|
51 |
be provided or otherwise made available to, or used by, any |
|
52 |
other person. No title to or ownership of the software is |
|
53 |
hereby transferred. |
|
54 |
" |
|
55 |
||
56 |
||
681 | 57 |
! |
58 |
||
59 |
documentation |
|
60 |
" |
|
61 |
colors a method. |
|
62 |
" |
|
63 |
||
64 |
||
662 | 65 |
! ! |
66 |
||
67 |
!SyntaxHighlighter class methodsFor:'highlighting'! |
|
68 |
||
684
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
69 |
formatExpression:aString in:aClass |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
70 |
"format (recolor) an expression in a given class. |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
71 |
Return the text containing font changes and color information." |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
72 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
73 |
|parser tree text endPos| |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
74 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
75 |
aString isNil ifTrue:[^ nil]. |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
76 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
77 |
parser := self for:(ReadStream on:aString string) in:aClass. |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
78 |
parser ignoreErrors. |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
79 |
parser ignoreWarnings. |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
80 |
parser sourceText:(text := aString string asText). |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
81 |
"/ use an array here - this can be changed much faster using #at:put: |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
82 |
text emphasisCollection:(Array new:aString size). |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
83 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
84 |
parser nextToken. |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
85 |
tree := parser expression. |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
86 |
"/ now, convert the emphasis-array to a runArray |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
87 |
text emphasisCollection:(text emphasis asRunArray). |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
88 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
89 |
tree == #Error ifTrue:[ |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
90 |
"/ mhmh - which is better ... |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
91 |
"/ alternative1: color rest after error in red |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
92 |
"/ text |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
93 |
"/ emphasizeFrom:(parser sourceStream position) |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
94 |
"/ to:text size |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
95 |
"/ with:(#color->Color red). |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
96 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
97 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
98 |
"/ alternative2: take original emphasis for rest |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
99 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
100 |
endPos := parser sourceStream position. |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
101 |
endPos >= text size ifTrue:[ |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
102 |
^ text |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
103 |
]. |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
104 |
^ (text copyTo:endPos) , (aString copyFrom:(endPos+1)) |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
105 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
106 |
"/ alternative3: no emphasis for rest. |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
107 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
108 |
"/ ^ text "/ aString |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
109 |
]. |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
110 |
^ text |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
111 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
112 |
" |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
113 |
self |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
114 |
formatExpression:'(1 + 2) max:5' |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
115 |
in:UndefinedObject |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
116 |
" |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
117 |
|
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
118 |
"Modified: / 7.4.1998 / 09:57:19 / cg" |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
119 |
"Created: / 9.4.1998 / 16:57:16 / cg" |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
120 |
! |
dd691ac07f90
added entry to color an expression
Claus Gittinger <cg@exept.de>
parents:
681
diff
changeset
|
121 |
|
662 | 122 |
formatMethod:aString in:aClass |
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
123 |
"format (recolor) a method in a given class. |
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
124 |
Return the text containing font changes and color information." |
662 | 125 |
|
889 | 126 |
|parser tree text endPos eColor| |
662 | 127 |
|
128 |
aString isNil ifTrue:[^ nil]. |
|
129 |
||
1110 | 130 |
Error handle:[:ex | |
689 | 131 |
^ aString |
132 |
] do:[ |
|
133 |
parser := self for:(ReadStream on:aString string) in:aClass. |
|
134 |
parser ignoreErrors. |
|
135 |
parser ignoreWarnings. |
|
136 |
parser sourceText:(text := aString string asText). |
|
137 |
"/ use an array here - this can be changed much faster using #at:put: |
|
138 |
text emphasisCollection:(Array new:aString size). |
|
662 | 139 |
|
689 | 140 |
tree := parser parseMethod. |
141 |
"/ now, convert the emphasis-array to a runArray |
|
142 |
text emphasisCollection:(text emphasis asRunArray). |
|
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
143 |
|
689 | 144 |
tree == #Error ifTrue:[ |
889 | 145 |
eColor := UserPreferences current errorColor. |
146 |
eColor notNil ifTrue:[ |
|
147 |
"/ mhmh - which is better ... |
|
148 |
"/ alternative1: color rest after error in red |
|
149 |
text |
|
150 |
emphasizeFrom:(parser sourceStream position) |
|
151 |
to:text size |
|
152 |
with:(#color->eColor). |
|
153 |
] ifFalse:[ |
|
154 |
"/ alternative2: take original emphasis for rest |
|
680
ebc432c71aec
much faster (due to runArray changes.
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
155 |
|
889 | 156 |
endPos := parser sourceStream position. |
157 |
endPos >= text size ifTrue:[ |
|
158 |
^ text |
|
159 |
]. |
|
160 |
^ (text copyTo:endPos) , (aString copyFrom:(endPos+1)) |
|
689 | 161 |
]. |
162 |
"/ alternative3: no emphasis for rest. |
|
678 | 163 |
]. |
689 | 164 |
^ text |
165 |
] |
|
662 | 166 |
" |
167 |
self |
|
168 |
formatMethod:'foo |
|
169 |
^ self bar:''hello''. |
|
170 |
||
171 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
172 |
' |
|
173 |
in:UndefinedObject |
|
174 |
" |
|
175 |
||
794
459868dcb591
highlight text after any error in red color.
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
176 |
"Modified: / 23.10.1998 / 22:48:45 / cg" |
662 | 177 |
! ! |
178 |
||
179 |
!SyntaxHighlighter methodsFor:'accessing'! |
|
180 |
||
181 |
sourceText |
|
182 |
"return the value of the instance variable 'sourceText' (automatically generated)" |
|
183 |
||
184 |
^ sourceText |
|
185 |
||
186 |
"Created: / 31.3.1998 / 11:49:05 / cg" |
|
187 |
! |
|
188 |
||
189 |
sourceText:something |
|
190 |
"set the value of the instance variable 'sourceText' (automatically generated)" |
|
191 |
||
192 |
sourceText := something. |
|
193 |
||
194 |
"Created: / 31.3.1998 / 11:49:05 / cg" |
|
195 |
! ! |
|
196 |
||
948
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
197 |
!SyntaxHighlighter methodsFor:'error handling'! |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
198 |
|
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
199 |
parseError:aMessage position:position to:endPos |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
200 |
super parseError:aMessage position:position to:endPos. |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
201 |
|
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
202 |
self |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
203 |
markFrom:position to:endPos |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
204 |
withEmphasis:nil color:UserPreferences current errorColor |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
205 |
|
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
206 |
|
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
207 |
! |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
208 |
|
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
209 |
showErrorMessage:aMessage position:pos |
978 | 210 |
Transcript showCR:aMessage. |
948
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
211 |
super showErrorMessage:aMessage position:pos. |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
212 |
|
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
213 |
self |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
214 |
markFrom:pos to:nil |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
215 |
withEmphasis:nil color:UserPreferences current errorColor |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
216 |
|
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
217 |
|
978 | 218 |
! |
219 |
||
220 |
warning:msg position:pos1 to:pos2 |
|
979 | 221 |
"/ self markUnknownIdentifierFrom:pos1 to:pos2 |
222 |
||
978 | 223 |
"/ self |
224 |
"/ markFrom:pos1 to:pos2 |
|
225 |
"/ withEmphasis:nil color:UserPreferences current errorColor |
|
226 |
||
979 | 227 |
"Modified: / 25.9.1999 / 18:42:30 / cg" |
948
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
228 |
! ! |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
229 |
|
662 | 230 |
!SyntaxHighlighter methodsFor:'initialization'! |
231 |
||
232 |
initialize |
|
233 |
|prefs| |
|
234 |
||
235 |
super initialize. |
|
236 |
||
990
cd1aa00086fd
dont care to fold constants during syntaxHighlight
Claus Gittinger <cg@exept.de>
parents:
987
diff
changeset
|
237 |
foldConstants := false. |
1132 | 238 |
allowDollarInIdentifier := true. |
990
cd1aa00086fd
dont care to fold constants during syntaxHighlight
Claus Gittinger <cg@exept.de>
parents:
987
diff
changeset
|
239 |
|
662 | 240 |
prefs := UserPreferences current. |
868 | 241 |
|
863 | 242 |
fullSelectorCheck := prefs fullSelectorCheck. |
662 | 243 |
identifierEmphasis := prefs identifierEmphasis. |
244 |
identifierColor := prefs identifierColor. |
|
245 |
argumentIdentifierEmphasis := prefs argumentIdentifierEmphasis. |
|
246 |
argumentIdentifierColor := prefs argumentIdentifierColor. |
|
247 |
localIdentifierEmphasis := prefs localIdentifierEmphasis. |
|
248 |
localIdentifierColor := prefs localIdentifierColor. |
|
838 | 249 |
returnEmphasis := prefs returnEmphasis. |
250 |
returnColor := prefs returnColor. |
|
686 | 251 |
instVarIdentifierEmphasis := prefs instVarIdentifierEmphasis. |
252 |
instVarIdentifierColor := prefs instVarIdentifierColor. |
|
662 | 253 |
globalIdentifierEmphasis := prefs globalIdentifierEmphasis. |
254 |
globalIdentifierColor := prefs globalIdentifierColor. |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
255 |
globalClassIdentifierEmphasis := prefs globalClassIdentifierEmphasis. |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
256 |
globalClassIdentifierColor := prefs globalClassIdentifierColor. |
870 | 257 |
classVariableIdentifierEmphasis := prefs classVariableIdentifierEmphasis. |
258 |
classVariableIdentifierColor := prefs classVariableIdentifierColor. |
|
665 | 259 |
unknownIdentifierEmphasis := prefs unknownIdentifierEmphasis. |
260 |
unknownIdentifierColor := prefs unknownIdentifierColor. |
|
884 | 261 |
badIdentifierEmphasis := prefs badIdentifierEmphasis. |
262 |
badIdentifierColor := prefs badIdentifierColor. |
|
662 | 263 |
commentEmphasis := prefs commentEmphasis. |
264 |
commentColor := prefs commentColor. |
|
265 |
methodSelectorEmphasis := prefs methodSelectorEmphasis. |
|
266 |
methodSelectorColor := prefs methodSelectorColor. |
|
267 |
selectorEmphasis := prefs selectorEmphasis. |
|
268 |
selectorColor := prefs selectorColor. |
|
868 | 269 |
unimplementedSelectorEmphasis := prefs unimplementedSelectorEmphasis. |
270 |
unimplementedSelectorColor := prefs unimplementedSelectorColor. |
|
662 | 271 |
stringEmphasis := prefs stringEmphasis. |
272 |
stringColor := prefs stringColor. |
|
672 | 273 |
symbolEmphasis := prefs symbolEmphasis. |
274 |
symbolColor := prefs symbolColor. |
|
662 | 275 |
selfEmphasis := prefs selfEmphasis. |
276 |
selfColor := prefs selfColor. |
|
277 |
hereEmphasis := prefs hereEmphasis. |
|
278 |
hereColor := prefs hereColor. |
|
279 |
superEmphasis := prefs superEmphasis. |
|
280 |
superColor := prefs superColor. |
|
281 |
thisContextEmphasis := prefs thisContextEmphasis. |
|
282 |
thisContextColor := prefs thisContextColor. |
|
283 |
constantEmphasis := prefs constantEmphasis. |
|
284 |
constantColor := prefs constantColor. |
|
285 |
booleanConstantEmphasis := prefs booleanConstantEmphasis. |
|
286 |
booleanConstantColor := prefs booleanConstantColor. |
|
673 | 287 |
bracketEmphasis := prefs bracketEmphasis. |
288 |
bracketColor := prefs bracketColor. |
|
662 | 289 |
|
290 |
"Created: / 31.3.1998 / 15:12:55 / cg" |
|
838 | 291 |
"Modified: / 5.1.1980 / 00:44:03 / cg" |
662 | 292 |
! ! |
293 |
||
788
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
294 |
!SyntaxHighlighter methodsFor:'misc'! |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
295 |
|
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
296 |
defineAsUndeclaredVariable:aName |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
297 |
"redefined to NOT declare undefined vars" |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
298 |
|
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
299 |
^ VariableNode type:#GlobalVariable name:aName |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
300 |
|
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
301 |
"Modified: / 19.10.1998 / 19:38:12 / cg" |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
302 |
! |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
303 |
|
884 | 304 |
isSyntaxHighlighter |
305 |
^ true |
|
306 |
||
307 |
! |
|
308 |
||
788
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
309 |
plausibilityCheck:aNode |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
310 |
"redefined to NOT do checks" |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
311 |
|
902 | 312 |
^ nil |
788
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
313 |
|
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
314 |
"Modified: / 19.10.1998 / 19:38:12 / cg" |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
315 |
"Created: / 19.10.1998 / 19:57:18 / cg" |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
316 |
! ! |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
317 |
|
662 | 318 |
!SyntaxHighlighter methodsFor:'syntax detection'! |
319 |
||
320 |
markArgumentIdentifierFrom:pos1 to:pos2 |
|
321 |
self |
|
322 |
markFrom:pos1 to:pos2 |
|
323 |
withEmphasis:argumentIdentifierEmphasis color:argumentIdentifierColor |
|
324 |
||
325 |
"Modified: / 31.3.1998 / 18:01:27 / cg" |
|
326 |
! |
|
327 |
||
884 | 328 |
markBadIdentifierFrom:pos1 to:pos2 |
329 |
self |
|
330 |
markFrom:pos1 to:pos2 |
|
331 |
withEmphasis:badIdentifierEmphasis color:badIdentifierColor |
|
332 |
||
333 |
! |
|
334 |
||
662 | 335 |
markBooleanConstantFrom:pos1 to:pos2 |
336 |
self |
|
337 |
markFrom:pos1 to:pos2 |
|
665 | 338 |
withEmphasis:booleanConstantEmphasis color:booleanConstantColor |
662 | 339 |
|
340 |
"Created: / 31.3.1998 / 18:09:01 / cg" |
|
665 | 341 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
662 | 342 |
! |
343 |
||
673 | 344 |
markBracketAt:pos |
345 |
self |
|
346 |
markFrom:pos to:pos |
|
347 |
withEmphasis:bracketEmphasis color:bracketColor |
|
348 |
||
349 |
"Created: / 31.3.1998 / 18:09:01 / cg" |
|
350 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
|
351 |
! |
|
352 |
||
870 | 353 |
markClassVariableIdentifierFrom:pos1 to:pos2 |
354 |
self |
|
355 |
markFrom:pos1 to:pos2 |
|
356 |
withEmphasis:classVariableIdentifierEmphasis color:classVariableIdentifierColor |
|
357 |
||
358 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
359 |
! |
|
360 |
||
662 | 361 |
markCommentFrom:pos1 to:pos2 |
362 |
self |
|
363 |
markFrom:pos1 to:pos2 |
|
364 |
withEmphasis:commentEmphasis color:commentColor |
|
365 |
||
366 |
"Modified: / 31.3.1998 / 18:01:55 / cg" |
|
367 |
! |
|
368 |
||
369 |
markConstantFrom:pos1 to:pos2 |
|
370 |
self |
|
371 |
markFrom:pos1 to:pos2 |
|
372 |
withEmphasis:constantEmphasis color:constantColor |
|
373 |
||
374 |
"Modified: / 31.3.1998 / 18:01:44 / cg" |
|
375 |
"Created: / 31.3.1998 / 18:09:22 / cg" |
|
376 |
! |
|
377 |
||
987
49a05e400448
aquire device colors - faster on pseudoColor devices.
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
378 |
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:clrIn |
49a05e400448
aquire device colors - faster on pseudoColor devices.
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
379 |
|e p2 clr| |
49a05e400448
aquire device colors - faster on pseudoColor devices.
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
380 |
|
49a05e400448
aquire device colors - faster on pseudoColor devices.
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
381 |
clr := clrIn onDevice:Screen current. |
662 | 382 |
|
669 | 383 |
clr = Color black ifTrue:[ |
384 |
e := fontEmp |
|
385 |
] ifFalse:[ |
|
948
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
386 |
fontEmp isNil ifTrue:[ |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
387 |
e := (#color->clr) |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
388 |
] ifFalse:[ |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
389 |
e := Text addEmphasis:fontEmp to:(#color->clr). |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
390 |
] |
669 | 391 |
]. |
948
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
392 |
(p2 := pos2) isNil ifTrue:[ |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
393 |
p2 := sourceText size |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
394 |
]. |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
395 |
sourceText emphasizeFrom:pos1 to:p2 with:e |
662 | 396 |
|
397 |
"Created: / 31.3.1998 / 13:26:53 / cg" |
|
669 | 398 |
"Modified: / 1.4.1998 / 12:51:56 / cg" |
662 | 399 |
! |
400 |
||
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
401 |
markGlobalClassIdentifierFrom:pos1 to:pos2 |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
402 |
self |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
403 |
markFrom:pos1 to:pos2 |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
404 |
withEmphasis:globalClassIdentifierEmphasis color:globalClassIdentifierColor |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
405 |
|
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
406 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
407 |
"Created: / 4.3.1999 / 12:53:02 / cg" |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
408 |
! |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
409 |
|
662 | 410 |
markGlobalIdentifierFrom:pos1 to:pos2 |
411 |
self |
|
412 |
markFrom:pos1 to:pos2 |
|
413 |
withEmphasis:globalIdentifierEmphasis color:globalIdentifierColor |
|
414 |
||
415 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
416 |
! |
|
417 |
||
418 |
markHereFrom:pos1 to:pos2 |
|
419 |
self |
|
420 |
markFrom:pos1 to:pos2 |
|
421 |
withEmphasis:hereEmphasis color:hereColor |
|
422 |
||
423 |
"Modified: / 31.3.1998 / 18:02:25 / cg" |
|
424 |
! |
|
425 |
||
426 |
markIdentifierFrom:pos1 to:pos2 |
|
427 |
self |
|
428 |
markFrom:pos1 to:pos2 |
|
429 |
withEmphasis:identifierEmphasis color:identifierColor |
|
430 |
||
431 |
"Modified: / 31.3.1998 / 18:02:39 / cg" |
|
432 |
"Created: / 31.3.1998 / 18:04:56 / cg" |
|
433 |
! |
|
434 |
||
686 | 435 |
markInstVarIdentifierFrom:pos1 to:pos2 |
436 |
self |
|
437 |
markFrom:pos1 to:pos2 |
|
438 |
withEmphasis:instVarIdentifierEmphasis color:instVarIdentifierColor |
|
439 |
||
440 |
"Created: / 16.4.1998 / 18:35:40 / cg" |
|
441 |
"Modified: / 16.4.1998 / 18:37:30 / cg" |
|
442 |
! |
|
443 |
||
662 | 444 |
markLocalIdentifierFrom:pos1 to:pos2 |
445 |
self |
|
446 |
markFrom:pos1 to:pos2 |
|
447 |
withEmphasis:localIdentifierEmphasis color:localIdentifierColor |
|
448 |
||
449 |
"Modified: / 31.3.1998 / 18:02:39 / cg" |
|
450 |
! |
|
451 |
||
452 |
markMethodSelectorFrom:pos1 to:pos2 |
|
453 |
self |
|
454 |
markFrom:pos1 to:pos2 |
|
455 |
withEmphasis:methodSelectorEmphasis color:methodSelectorColor |
|
456 |
||
457 |
"Modified: / 31.3.1998 / 18:02:52 / cg" |
|
458 |
! |
|
459 |
||
838 | 460 |
markReturnAt:pos |
461 |
self |
|
462 |
markFrom:pos to:pos |
|
463 |
withEmphasis:returnEmphasis color:returnColor |
|
464 |
||
465 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
|
466 |
"Created: / 5.1.1980 / 00:44:27 / cg" |
|
467 |
! |
|
468 |
||
863 | 469 |
markSelector:selectorString from:pos1 to:pos2 receiverNode:aReceiverNode |
868 | 470 |
|fg bg sel check ok rec em| |
863 | 471 |
|
472 |
"/ uncommenting the code below |
|
473 |
"/ will suppress highlighting of common selectors ... |
|
474 |
"/ |
|
475 |
"/ (#( |
|
476 |
"/ 'ifTrue:' |
|
477 |
"/ 'ifFalse:' |
|
478 |
"/ 'not' |
|
479 |
"/ 'and:' |
|
480 |
"/ 'or:' |
|
481 |
"/ '=' |
|
482 |
"/ '==' |
|
483 |
"/ '~=' |
|
484 |
"/ '~~' |
|
485 |
"/ ) includes:sel) ifTrue:[ |
|
486 |
"/ ^ self |
|
487 |
"/ ]. |
|
488 |
||
489 |
fg := selectorColor. |
|
868 | 490 |
em := selectorEmphasis. |
863 | 491 |
selectorString knownAsSymbol ifFalse:[ |
492 |
fg := Color red. |
|
493 |
] ifTrue:[ |
|
494 |
fullSelectorCheck == true ifTrue:[ |
|
495 |
sel := selectorString asSymbol. |
|
496 |
||
497 |
check := [:cls | (cls includesSelector:sel) |
|
498 |
or:[cls class includesSelector:sel]]. |
|
499 |
||
500 |
ok := false. |
|
501 |
||
502 |
"/ limit search if possible |
|
503 |
(classToCompileFor notNil |
|
504 |
and:[aReceiverNode isSelf or:[aReceiverNode isSuper]]) ifTrue:[ |
|
505 |
currentSuperclasses isNil ifTrue:[ |
|
506 |
currentSuperclasses := classToCompileFor withAllSuperclasses. |
|
507 |
]. |
|
508 |
ok := currentSuperclasses contains:check. |
|
509 |
(ok not and:[aReceiverNode isSelf]) ifTrue:[ |
|
510 |
currentSubclasses isNil ifTrue:[ |
|
511 |
currentSubclasses := classToCompileFor allSubclasses. |
|
512 |
]. |
|
513 |
ok := currentSubclasses contains:check. |
|
514 |
]. |
|
515 |
] ifFalse:[ |
|
516 |
aReceiverNode isConstant ifTrue:[ |
|
517 |
ok := aReceiverNode evaluate class withAllSuperclasses contains:check. |
|
518 |
] ifFalse:[ |
|
519 |
(aReceiverNode isGlobal |
|
520 |
and:[(rec := aReceiverNode evaluate) isBehavior]) ifTrue:[ |
|
521 |
ok := rec class withAllSuperclasses contains:check. |
|
522 |
] ifFalse:[ |
|
523 |
ok := Smalltalk allClasses contains:check |
|
524 |
] |
|
525 |
] |
|
526 |
]. |
|
527 |
||
528 |
ok ifFalse:[ |
|
868 | 529 |
em := unimplementedSelectorEmphasis. |
530 |
fg := unimplementedSelectorColor. |
|
863 | 531 |
] |
532 |
] |
|
533 |
]. |
|
534 |
self |
|
535 |
markFrom:pos1 to:pos2 |
|
868 | 536 |
withEmphasis:em color:fg |
863 | 537 |
|
538 |
"Modified: / 1.4.1998 / 13:14:43 / cg" |
|
539 |
! |
|
540 |
||
662 | 541 |
markSelfFrom:pos1 to:pos2 |
542 |
self |
|
543 |
markFrom:pos1 to:pos2 |
|
544 |
withEmphasis:selfEmphasis color:selfColor |
|
545 |
||
546 |
"Modified: / 31.3.1998 / 18:03:10 / cg" |
|
547 |
! |
|
548 |
||
549 |
markStringFrom:pos1 to:pos2 |
|
550 |
self |
|
551 |
markFrom:pos1 to:pos2 |
|
552 |
withEmphasis:stringEmphasis color:stringColor |
|
553 |
||
554 |
"Modified: / 31.3.1998 / 18:03:18 / cg" |
|
555 |
! |
|
556 |
||
557 |
markSuperFrom:pos1 to:pos2 |
|
558 |
self |
|
559 |
markFrom:pos1 to:pos2 |
|
560 |
withEmphasis:superEmphasis color:superColor |
|
561 |
||
562 |
"Modified: / 31.3.1998 / 18:03:26 / cg" |
|
563 |
! |
|
564 |
||
672 | 565 |
markSymbolFrom:pos1 to:pos2 |
566 |
self |
|
567 |
markFrom:pos1 to:pos2 |
|
568 |
withEmphasis:symbolEmphasis color:symbolColor |
|
569 |
||
570 |
"Created: / 1.4.1998 / 12:56:47 / cg" |
|
571 |
"Modified: / 1.4.1998 / 12:58:00 / cg" |
|
572 |
! |
|
573 |
||
662 | 574 |
markThisContextFrom:pos1 to:pos2 |
575 |
self |
|
576 |
markFrom:pos1 to:pos2 |
|
577 |
withEmphasis:thisContextEmphasis color:thisContextColor |
|
578 |
||
579 |
"Modified: / 31.3.1998 / 18:03:36 / cg" |
|
665 | 580 |
! |
581 |
||
582 |
markUnknownIdentifierFrom:pos1 to:pos2 |
|
583 |
self |
|
584 |
markFrom:pos1 to:pos2 |
|
585 |
withEmphasis:unknownIdentifierEmphasis color:unknownIdentifierColor |
|
586 |
||
587 |
"Created: / 31.3.1998 / 19:09:26 / cg" |
|
588 |
"Modified: / 31.3.1998 / 19:10:30 / cg" |
|
686 | 589 |
! |
590 |
||
591 |
markVariable:v |
|
592 |
"support for syntaxColoring" |
|
593 |
||
594 |
|pos endPos| |
|
595 |
||
596 |
pos := tokenPosition. |
|
597 |
endPos := pos+tokenName size-1. |
|
598 |
self markVariable:v from:pos to:endPos |
|
599 |
||
600 |
"Modified: / 16.4.1998 / 18:49:51 / cg" |
|
601 |
! |
|
602 |
||
603 |
markVariable:v from:pos to:endPos |
|
604 |
"support for syntaxColoring" |
|
605 |
||
823 | 606 |
|type globalValue nameSym| |
686 | 607 |
|
608 |
type := v type. |
|
609 |
(type == #BlockArg |
|
610 |
or:[type == #MethodArg]) ifTrue:[ |
|
611 |
self markArgumentIdentifierFrom:pos to:endPos. |
|
612 |
^ self |
|
613 |
]. |
|
614 |
(type == #BlockVariable |
|
615 |
or:[type == #MethodVariable]) ifTrue:[ |
|
616 |
self markLocalIdentifierFrom:pos to:endPos. |
|
617 |
^ self |
|
618 |
]. |
|
619 |
(type == #GlobalVariable) ifTrue:[ |
|
823 | 620 |
nameSym := v name asSymbolIfInterned. |
621 |
nameSym notNil ifTrue:[ |
|
622 |
globalValue := Smalltalk at:nameSym ifAbsent:nil. |
|
623 |
]. |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
624 |
globalValue isBehavior ifTrue:[ |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
625 |
self markGlobalClassIdentifierFrom:pos to:endPos. |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
626 |
] ifFalse:[ |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
627 |
self markGlobalIdentifierFrom:pos to:endPos. |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
628 |
]. |
686 | 629 |
^ self |
630 |
]. |
|
870 | 631 |
(type == #ClassVariable) ifTrue:[ |
632 |
self markClassVariableIdentifierFrom:pos to:endPos. |
|
633 |
^ self |
|
634 |
]. |
|
686 | 635 |
(type == #InstanceVariable) ifTrue:[ |
636 |
self markInstVarIdentifierFrom:pos to:endPos. |
|
637 |
^ self |
|
638 |
]. |
|
639 |
||
640 |
self markIdentifierFrom:pos to:endPos. |
|
641 |
||
642 |
"Created: / 16.4.1998 / 18:49:34 / cg" |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
643 |
"Modified: / 4.3.1999 / 12:56:13 / cg" |
662 | 644 |
! ! |
645 |
||
646 |
!SyntaxHighlighter class methodsFor:'documentation'! |
|
647 |
||
648 |
version |
|
1132 | 649 |
^ '$Header: /cvs/stx/stx/libcomp/SyntaxHighlighter.st,v 1.32 2000-12-18 22:12:54 cg Exp $' |
662 | 650 |
! ! |