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