author | Claus Gittinger <cg@exept.de> |
Wed, 08 Nov 2000 13:37:36 +0100 | |
changeset 1110 | 3e08a12956fd |
parent 990 | cd1aa00086fd |
child 1132 | b5958fa3816e |
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. |
cd1aa00086fd
dont care to fold constants during syntaxHighlight
Claus Gittinger <cg@exept.de>
parents:
987
diff
changeset
|
238 |
|
662 | 239 |
prefs := UserPreferences current. |
868 | 240 |
|
863 | 241 |
fullSelectorCheck := prefs fullSelectorCheck. |
662 | 242 |
identifierEmphasis := prefs identifierEmphasis. |
243 |
identifierColor := prefs identifierColor. |
|
244 |
argumentIdentifierEmphasis := prefs argumentIdentifierEmphasis. |
|
245 |
argumentIdentifierColor := prefs argumentIdentifierColor. |
|
246 |
localIdentifierEmphasis := prefs localIdentifierEmphasis. |
|
247 |
localIdentifierColor := prefs localIdentifierColor. |
|
838 | 248 |
returnEmphasis := prefs returnEmphasis. |
249 |
returnColor := prefs returnColor. |
|
686 | 250 |
instVarIdentifierEmphasis := prefs instVarIdentifierEmphasis. |
251 |
instVarIdentifierColor := prefs instVarIdentifierColor. |
|
662 | 252 |
globalIdentifierEmphasis := prefs globalIdentifierEmphasis. |
253 |
globalIdentifierColor := prefs globalIdentifierColor. |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
254 |
globalClassIdentifierEmphasis := prefs globalClassIdentifierEmphasis. |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
255 |
globalClassIdentifierColor := prefs globalClassIdentifierColor. |
870 | 256 |
classVariableIdentifierEmphasis := prefs classVariableIdentifierEmphasis. |
257 |
classVariableIdentifierColor := prefs classVariableIdentifierColor. |
|
665 | 258 |
unknownIdentifierEmphasis := prefs unknownIdentifierEmphasis. |
259 |
unknownIdentifierColor := prefs unknownIdentifierColor. |
|
884 | 260 |
badIdentifierEmphasis := prefs badIdentifierEmphasis. |
261 |
badIdentifierColor := prefs badIdentifierColor. |
|
662 | 262 |
commentEmphasis := prefs commentEmphasis. |
263 |
commentColor := prefs commentColor. |
|
264 |
methodSelectorEmphasis := prefs methodSelectorEmphasis. |
|
265 |
methodSelectorColor := prefs methodSelectorColor. |
|
266 |
selectorEmphasis := prefs selectorEmphasis. |
|
267 |
selectorColor := prefs selectorColor. |
|
868 | 268 |
unimplementedSelectorEmphasis := prefs unimplementedSelectorEmphasis. |
269 |
unimplementedSelectorColor := prefs unimplementedSelectorColor. |
|
662 | 270 |
stringEmphasis := prefs stringEmphasis. |
271 |
stringColor := prefs stringColor. |
|
672 | 272 |
symbolEmphasis := prefs symbolEmphasis. |
273 |
symbolColor := prefs symbolColor. |
|
662 | 274 |
selfEmphasis := prefs selfEmphasis. |
275 |
selfColor := prefs selfColor. |
|
276 |
hereEmphasis := prefs hereEmphasis. |
|
277 |
hereColor := prefs hereColor. |
|
278 |
superEmphasis := prefs superEmphasis. |
|
279 |
superColor := prefs superColor. |
|
280 |
thisContextEmphasis := prefs thisContextEmphasis. |
|
281 |
thisContextColor := prefs thisContextColor. |
|
282 |
constantEmphasis := prefs constantEmphasis. |
|
283 |
constantColor := prefs constantColor. |
|
284 |
booleanConstantEmphasis := prefs booleanConstantEmphasis. |
|
285 |
booleanConstantColor := prefs booleanConstantColor. |
|
673 | 286 |
bracketEmphasis := prefs bracketEmphasis. |
287 |
bracketColor := prefs bracketColor. |
|
662 | 288 |
|
289 |
"Created: / 31.3.1998 / 15:12:55 / cg" |
|
838 | 290 |
"Modified: / 5.1.1980 / 00:44:03 / cg" |
662 | 291 |
! ! |
292 |
||
788
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
293 |
!SyntaxHighlighter methodsFor:'misc'! |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
294 |
|
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
295 |
defineAsUndeclaredVariable:aName |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
296 |
"redefined to NOT declare undefined vars" |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
297 |
|
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
298 |
^ VariableNode type:#GlobalVariable name:aName |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
299 |
|
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
300 |
"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
|
301 |
! |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
302 |
|
884 | 303 |
isSyntaxHighlighter |
304 |
^ true |
|
305 |
||
306 |
! |
|
307 |
||
788
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
308 |
plausibilityCheck:aNode |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
309 |
"redefined to NOT do checks" |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
310 |
|
902 | 311 |
^ nil |
788
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
312 |
|
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
313 |
"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
|
314 |
"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
|
315 |
! ! |
5307f69829c6
do not enter undeclared vars into Undeclared.
Claus Gittinger <cg@exept.de>
parents:
689
diff
changeset
|
316 |
|
662 | 317 |
!SyntaxHighlighter methodsFor:'syntax detection'! |
318 |
||
319 |
markArgumentIdentifierFrom:pos1 to:pos2 |
|
320 |
self |
|
321 |
markFrom:pos1 to:pos2 |
|
322 |
withEmphasis:argumentIdentifierEmphasis color:argumentIdentifierColor |
|
323 |
||
324 |
"Modified: / 31.3.1998 / 18:01:27 / cg" |
|
325 |
! |
|
326 |
||
884 | 327 |
markBadIdentifierFrom:pos1 to:pos2 |
328 |
self |
|
329 |
markFrom:pos1 to:pos2 |
|
330 |
withEmphasis:badIdentifierEmphasis color:badIdentifierColor |
|
331 |
||
332 |
! |
|
333 |
||
662 | 334 |
markBooleanConstantFrom:pos1 to:pos2 |
335 |
self |
|
336 |
markFrom:pos1 to:pos2 |
|
665 | 337 |
withEmphasis:booleanConstantEmphasis color:booleanConstantColor |
662 | 338 |
|
339 |
"Created: / 31.3.1998 / 18:09:01 / cg" |
|
665 | 340 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
662 | 341 |
! |
342 |
||
673 | 343 |
markBracketAt:pos |
344 |
self |
|
345 |
markFrom:pos to:pos |
|
346 |
withEmphasis:bracketEmphasis color:bracketColor |
|
347 |
||
348 |
"Created: / 31.3.1998 / 18:09:01 / cg" |
|
349 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
|
350 |
! |
|
351 |
||
870 | 352 |
markClassVariableIdentifierFrom:pos1 to:pos2 |
353 |
self |
|
354 |
markFrom:pos1 to:pos2 |
|
355 |
withEmphasis:classVariableIdentifierEmphasis color:classVariableIdentifierColor |
|
356 |
||
357 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
358 |
! |
|
359 |
||
662 | 360 |
markCommentFrom:pos1 to:pos2 |
361 |
self |
|
362 |
markFrom:pos1 to:pos2 |
|
363 |
withEmphasis:commentEmphasis color:commentColor |
|
364 |
||
365 |
"Modified: / 31.3.1998 / 18:01:55 / cg" |
|
366 |
! |
|
367 |
||
368 |
markConstantFrom:pos1 to:pos2 |
|
369 |
self |
|
370 |
markFrom:pos1 to:pos2 |
|
371 |
withEmphasis:constantEmphasis color:constantColor |
|
372 |
||
373 |
"Modified: / 31.3.1998 / 18:01:44 / cg" |
|
374 |
"Created: / 31.3.1998 / 18:09:22 / cg" |
|
375 |
! |
|
376 |
||
987
49a05e400448
aquire device colors - faster on pseudoColor devices.
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
377 |
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
|
378 |
|e p2 clr| |
49a05e400448
aquire device colors - faster on pseudoColor devices.
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
379 |
|
49a05e400448
aquire device colors - faster on pseudoColor devices.
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
380 |
clr := clrIn onDevice:Screen current. |
662 | 381 |
|
669 | 382 |
clr = Color black ifTrue:[ |
383 |
e := fontEmp |
|
384 |
] ifFalse:[ |
|
948
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
385 |
fontEmp isNil ifTrue:[ |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
386 |
e := (#color->clr) |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
387 |
] ifFalse:[ |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
388 |
e := Text addEmphasis:fontEmp to:(#color->clr). |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
389 |
] |
669 | 390 |
]. |
948
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
391 |
(p2 := pos2) isNil ifTrue:[ |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
392 |
p2 := sourceText size |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
393 |
]. |
6ba29fe774f2
show earliest possible error position.
Claus Gittinger <cg@exept.de>
parents:
902
diff
changeset
|
394 |
sourceText emphasizeFrom:pos1 to:p2 with:e |
662 | 395 |
|
396 |
"Created: / 31.3.1998 / 13:26:53 / cg" |
|
669 | 397 |
"Modified: / 1.4.1998 / 12:51:56 / cg" |
662 | 398 |
! |
399 |
||
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
400 |
markGlobalClassIdentifierFrom:pos1 to:pos2 |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
401 |
self |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
402 |
markFrom:pos1 to:pos2 |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
403 |
withEmphasis:globalClassIdentifierEmphasis color:globalClassIdentifierColor |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
404 |
|
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
405 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
406 |
"Created: / 4.3.1999 / 12:53:02 / cg" |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
407 |
! |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
408 |
|
662 | 409 |
markGlobalIdentifierFrom:pos1 to:pos2 |
410 |
self |
|
411 |
markFrom:pos1 to:pos2 |
|
412 |
withEmphasis:globalIdentifierEmphasis color:globalIdentifierColor |
|
413 |
||
414 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
415 |
! |
|
416 |
||
417 |
markHereFrom:pos1 to:pos2 |
|
418 |
self |
|
419 |
markFrom:pos1 to:pos2 |
|
420 |
withEmphasis:hereEmphasis color:hereColor |
|
421 |
||
422 |
"Modified: / 31.3.1998 / 18:02:25 / cg" |
|
423 |
! |
|
424 |
||
425 |
markIdentifierFrom:pos1 to:pos2 |
|
426 |
self |
|
427 |
markFrom:pos1 to:pos2 |
|
428 |
withEmphasis:identifierEmphasis color:identifierColor |
|
429 |
||
430 |
"Modified: / 31.3.1998 / 18:02:39 / cg" |
|
431 |
"Created: / 31.3.1998 / 18:04:56 / cg" |
|
432 |
! |
|
433 |
||
686 | 434 |
markInstVarIdentifierFrom:pos1 to:pos2 |
435 |
self |
|
436 |
markFrom:pos1 to:pos2 |
|
437 |
withEmphasis:instVarIdentifierEmphasis color:instVarIdentifierColor |
|
438 |
||
439 |
"Created: / 16.4.1998 / 18:35:40 / cg" |
|
440 |
"Modified: / 16.4.1998 / 18:37:30 / cg" |
|
441 |
! |
|
442 |
||
662 | 443 |
markLocalIdentifierFrom:pos1 to:pos2 |
444 |
self |
|
445 |
markFrom:pos1 to:pos2 |
|
446 |
withEmphasis:localIdentifierEmphasis color:localIdentifierColor |
|
447 |
||
448 |
"Modified: / 31.3.1998 / 18:02:39 / cg" |
|
449 |
! |
|
450 |
||
451 |
markMethodSelectorFrom:pos1 to:pos2 |
|
452 |
self |
|
453 |
markFrom:pos1 to:pos2 |
|
454 |
withEmphasis:methodSelectorEmphasis color:methodSelectorColor |
|
455 |
||
456 |
"Modified: / 31.3.1998 / 18:02:52 / cg" |
|
457 |
! |
|
458 |
||
838 | 459 |
markReturnAt:pos |
460 |
self |
|
461 |
markFrom:pos to:pos |
|
462 |
withEmphasis:returnEmphasis color:returnColor |
|
463 |
||
464 |
"Modified: / 31.3.1998 / 19:36:44 / cg" |
|
465 |
"Created: / 5.1.1980 / 00:44:27 / cg" |
|
466 |
! |
|
467 |
||
863 | 468 |
markSelector:selectorString from:pos1 to:pos2 receiverNode:aReceiverNode |
868 | 469 |
|fg bg sel check ok rec em| |
863 | 470 |
|
471 |
"/ uncommenting the code below |
|
472 |
"/ will suppress highlighting of common selectors ... |
|
473 |
"/ |
|
474 |
"/ (#( |
|
475 |
"/ 'ifTrue:' |
|
476 |
"/ 'ifFalse:' |
|
477 |
"/ 'not' |
|
478 |
"/ 'and:' |
|
479 |
"/ 'or:' |
|
480 |
"/ '=' |
|
481 |
"/ '==' |
|
482 |
"/ '~=' |
|
483 |
"/ '~~' |
|
484 |
"/ ) includes:sel) ifTrue:[ |
|
485 |
"/ ^ self |
|
486 |
"/ ]. |
|
487 |
||
488 |
fg := selectorColor. |
|
868 | 489 |
em := selectorEmphasis. |
863 | 490 |
selectorString knownAsSymbol ifFalse:[ |
491 |
fg := Color red. |
|
492 |
] ifTrue:[ |
|
493 |
fullSelectorCheck == true ifTrue:[ |
|
494 |
sel := selectorString asSymbol. |
|
495 |
||
496 |
check := [:cls | (cls includesSelector:sel) |
|
497 |
or:[cls class includesSelector:sel]]. |
|
498 |
||
499 |
ok := false. |
|
500 |
||
501 |
"/ limit search if possible |
|
502 |
(classToCompileFor notNil |
|
503 |
and:[aReceiverNode isSelf or:[aReceiverNode isSuper]]) ifTrue:[ |
|
504 |
currentSuperclasses isNil ifTrue:[ |
|
505 |
currentSuperclasses := classToCompileFor withAllSuperclasses. |
|
506 |
]. |
|
507 |
ok := currentSuperclasses contains:check. |
|
508 |
(ok not and:[aReceiverNode isSelf]) ifTrue:[ |
|
509 |
currentSubclasses isNil ifTrue:[ |
|
510 |
currentSubclasses := classToCompileFor allSubclasses. |
|
511 |
]. |
|
512 |
ok := currentSubclasses contains:check. |
|
513 |
]. |
|
514 |
] ifFalse:[ |
|
515 |
aReceiverNode isConstant ifTrue:[ |
|
516 |
ok := aReceiverNode evaluate class withAllSuperclasses contains:check. |
|
517 |
] ifFalse:[ |
|
518 |
(aReceiverNode isGlobal |
|
519 |
and:[(rec := aReceiverNode evaluate) isBehavior]) ifTrue:[ |
|
520 |
ok := rec class withAllSuperclasses contains:check. |
|
521 |
] ifFalse:[ |
|
522 |
ok := Smalltalk allClasses contains:check |
|
523 |
] |
|
524 |
] |
|
525 |
]. |
|
526 |
||
527 |
ok ifFalse:[ |
|
868 | 528 |
em := unimplementedSelectorEmphasis. |
529 |
fg := unimplementedSelectorColor. |
|
863 | 530 |
] |
531 |
] |
|
532 |
]. |
|
533 |
self |
|
534 |
markFrom:pos1 to:pos2 |
|
868 | 535 |
withEmphasis:em color:fg |
863 | 536 |
|
537 |
"Modified: / 1.4.1998 / 13:14:43 / cg" |
|
538 |
! |
|
539 |
||
662 | 540 |
markSelfFrom:pos1 to:pos2 |
541 |
self |
|
542 |
markFrom:pos1 to:pos2 |
|
543 |
withEmphasis:selfEmphasis color:selfColor |
|
544 |
||
545 |
"Modified: / 31.3.1998 / 18:03:10 / cg" |
|
546 |
! |
|
547 |
||
548 |
markStringFrom:pos1 to:pos2 |
|
549 |
self |
|
550 |
markFrom:pos1 to:pos2 |
|
551 |
withEmphasis:stringEmphasis color:stringColor |
|
552 |
||
553 |
"Modified: / 31.3.1998 / 18:03:18 / cg" |
|
554 |
! |
|
555 |
||
556 |
markSuperFrom:pos1 to:pos2 |
|
557 |
self |
|
558 |
markFrom:pos1 to:pos2 |
|
559 |
withEmphasis:superEmphasis color:superColor |
|
560 |
||
561 |
"Modified: / 31.3.1998 / 18:03:26 / cg" |
|
562 |
! |
|
563 |
||
672 | 564 |
markSymbolFrom:pos1 to:pos2 |
565 |
self |
|
566 |
markFrom:pos1 to:pos2 |
|
567 |
withEmphasis:symbolEmphasis color:symbolColor |
|
568 |
||
569 |
"Created: / 1.4.1998 / 12:56:47 / cg" |
|
570 |
"Modified: / 1.4.1998 / 12:58:00 / cg" |
|
571 |
! |
|
572 |
||
662 | 573 |
markThisContextFrom:pos1 to:pos2 |
574 |
self |
|
575 |
markFrom:pos1 to:pos2 |
|
576 |
withEmphasis:thisContextEmphasis color:thisContextColor |
|
577 |
||
578 |
"Modified: / 31.3.1998 / 18:03:36 / cg" |
|
665 | 579 |
! |
580 |
||
581 |
markUnknownIdentifierFrom:pos1 to:pos2 |
|
582 |
self |
|
583 |
markFrom:pos1 to:pos2 |
|
584 |
withEmphasis:unknownIdentifierEmphasis color:unknownIdentifierColor |
|
585 |
||
586 |
"Created: / 31.3.1998 / 19:09:26 / cg" |
|
587 |
"Modified: / 31.3.1998 / 19:10:30 / cg" |
|
686 | 588 |
! |
589 |
||
590 |
markVariable:v |
|
591 |
"support for syntaxColoring" |
|
592 |
||
593 |
|pos endPos| |
|
594 |
||
595 |
pos := tokenPosition. |
|
596 |
endPos := pos+tokenName size-1. |
|
597 |
self markVariable:v from:pos to:endPos |
|
598 |
||
599 |
"Modified: / 16.4.1998 / 18:49:51 / cg" |
|
600 |
! |
|
601 |
||
602 |
markVariable:v from:pos to:endPos |
|
603 |
"support for syntaxColoring" |
|
604 |
||
823 | 605 |
|type globalValue nameSym| |
686 | 606 |
|
607 |
type := v type. |
|
608 |
(type == #BlockArg |
|
609 |
or:[type == #MethodArg]) ifTrue:[ |
|
610 |
self markArgumentIdentifierFrom:pos to:endPos. |
|
611 |
^ self |
|
612 |
]. |
|
613 |
(type == #BlockVariable |
|
614 |
or:[type == #MethodVariable]) ifTrue:[ |
|
615 |
self markLocalIdentifierFrom:pos to:endPos. |
|
616 |
^ self |
|
617 |
]. |
|
618 |
(type == #GlobalVariable) ifTrue:[ |
|
823 | 619 |
nameSym := v name asSymbolIfInterned. |
620 |
nameSym notNil ifTrue:[ |
|
621 |
globalValue := Smalltalk at:nameSym ifAbsent:nil. |
|
622 |
]. |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
623 |
globalValue isBehavior ifTrue:[ |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
624 |
self markGlobalClassIdentifierFrom:pos to:endPos. |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
625 |
] ifFalse:[ |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
626 |
self markGlobalIdentifierFrom:pos to:endPos. |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
627 |
]. |
686 | 628 |
^ self |
629 |
]. |
|
870 | 630 |
(type == #ClassVariable) ifTrue:[ |
631 |
self markClassVariableIdentifierFrom:pos to:endPos. |
|
632 |
^ self |
|
633 |
]. |
|
686 | 634 |
(type == #InstanceVariable) ifTrue:[ |
635 |
self markInstVarIdentifierFrom:pos to:endPos. |
|
636 |
^ self |
|
637 |
]. |
|
638 |
||
639 |
self markIdentifierFrom:pos to:endPos. |
|
640 |
||
641 |
"Created: / 16.4.1998 / 18:49:34 / cg" |
|
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
794
diff
changeset
|
642 |
"Modified: / 4.3.1999 / 12:56:13 / cg" |
662 | 643 |
! ! |
644 |
||
645 |
!SyntaxHighlighter class methodsFor:'documentation'! |
|
646 |
||
647 |
version |
|
1110 | 648 |
^ '$Header: /cvs/stx/stx/libcomp/SyntaxHighlighter.st,v 1.31 2000-11-08 12:37:36 cg Exp $' |
662 | 649 |
! ! |