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