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