author | Claus Gittinger <cg@exept.de> |
Fri, 21 Jun 2013 00:52:56 +0200 | |
changeset 3201 | 13eb554c3f26 |
parent 3191 | e538b29d3cfb |
child 3216 | 063544a8ec32 |
permissions | -rw-r--r-- |
2506 | 1 |
" |
2 |
COPYRIGHT (c) 2006 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 |
" |
|
2371 | 12 |
"{ Package: 'stx:libcomp' }" |
13 |
||
14 |
Parser subclass:#AbstractSyntaxHighlighter |
|
2525 | 15 |
instanceVariableNames:'method sourceText preferences fullSelectorCheck' |
2371 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'System-Compiler' |
|
19 |
! |
|
20 |
||
2506 | 21 |
!AbstractSyntaxHighlighter class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! ! |
|
2371 | 36 |
|
37 |
!AbstractSyntaxHighlighter class methodsFor:'api highlighting'! |
|
38 |
||
39 |
formatClassDefinition:aString in:aClass |
|
40 |
"format (recolor) a class definition expression in a given class. |
|
41 |
Return the text containing font changes and color information." |
|
42 |
||
43 |
^ self formatExpression:aString in:aClass |
|
44 |
! |
|
45 |
||
2506 | 46 |
formatClassDefinition:aString in:aClass elementsInto: elements |
47 |
"format (recolor) a class definition expression in a given class. |
|
48 |
Return the text containing font changes and color information." |
|
49 |
||
50 |
^ self formatExpression:aString in:aClass |
|
51 |
||
52 |
"Created: / 10-04-2011 / 18:18:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
53 |
! |
|
54 |
||
2371 | 55 |
formatExpression:aString in:aClass |
56 |
"format (recolor) an expression in a given class. |
|
57 |
Return the text containing font changes and color information." |
|
58 |
||
59 |
|parser tree text endPos| |
|
60 |
||
61 |
aString isNil ifTrue:[^ nil]. |
|
62 |
||
63 |
parser := self for:(ReadStream on:aString string) in:aClass. |
|
64 |
parser ignoreErrors:true. |
|
65 |
parser ignoreWarnings:true. |
|
66 |
parser sourceText:(text := aString string asText). |
|
67 |
"/ use an array here - this can be changed much faster using #at:put: |
|
68 |
text emphasisCollection:(Array new:aString size). |
|
69 |
||
70 |
parser nextToken. |
|
71 |
tree := parser expression. |
|
72 |
"/ now, convert the emphasis-array to a runArray |
|
73 |
text emphasisCollection:(text emphasis asRunArray). |
|
74 |
||
75 |
tree == #Error ifTrue:[ |
|
76 |
"/ mhmh - which is better ... |
|
77 |
"/ alternative1: color rest after error in red |
|
78 |
"/ text |
|
79 |
"/ emphasizeFrom:(parser sourceStream position) |
|
80 |
"/ to:text size |
|
81 |
"/ with:(#color->Color red). |
|
82 |
||
83 |
||
84 |
"/ alternative2: take original emphasis for rest |
|
85 |
||
86 |
endPos := parser sourceStream position1Based. |
|
87 |
endPos >= text size ifTrue:[ |
|
88 |
^ text |
|
89 |
]. |
|
90 |
^ (text copyTo:endPos) , (aString copyFrom:(endPos+1)) |
|
91 |
||
92 |
"/ alternative3: no emphasis for rest. |
|
93 |
||
94 |
"/ ^ text "/ aString |
|
95 |
]. |
|
96 |
^ text |
|
97 |
||
98 |
" |
|
99 |
self |
|
100 |
formatExpression:'(1 + 2) max:5' |
|
101 |
in:UndefinedObject |
|
102 |
" |
|
103 |
||
104 |
"Modified: / 7.4.1998 / 09:57:19 / cg" |
|
105 |
"Created: / 9.4.1998 / 16:57:16 / cg" |
|
106 |
! |
|
107 |
||
108 |
formatMethod:aString in:aClass |
|
3191 | 109 |
<resource: #obsolete> |
2371 | 110 |
"format (recolor) a method in a given class. |
111 |
Return the text containing font changes and color information." |
|
112 |
||
113 |
self obsoleteMethodWarning:'use #formatMethodSource:in:'. |
|
114 |
^ self formatMethod:nil source:aString in:aClass using:nil |
|
115 |
||
116 |
" |
|
117 |
self |
|
118 |
formatMethod:'foo |
|
119 |
^ self bar:''hello''. |
|
120 |
||
121 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
122 |
' |
|
123 |
in:UndefinedObject |
|
124 |
" |
|
125 |
||
126 |
"Modified: / 28-04-2010 / 13:03:04 / cg" |
|
127 |
! |
|
128 |
||
129 |
formatMethod:aString in:aClass using:preferencesOrNil |
|
3191 | 130 |
<resource: #obsolete> |
2371 | 131 |
"format (recolor) a method in a given class. |
132 |
Return the text containing font changes and color information." |
|
133 |
||
134 |
self obsoleteMethodWarning:'use #formatMethodSource:in:using:'. |
|
135 |
^ self formatMethod:nil source:aString in:aClass using:preferencesOrNil |
|
136 |
||
137 |
"Modified: / 28-04-2010 / 13:03:15 / cg" |
|
138 |
! |
|
139 |
||
140 |
formatMethod:methodOrNil source:aString in:aClass |
|
141 |
"format (recolor) a method in a given class. |
|
142 |
Return the text containing font changes and color information." |
|
143 |
||
144 |
^ self formatMethod:methodOrNil source:aString in:aClass using:nil |
|
145 |
||
146 |
" |
|
147 |
self |
|
148 |
formatMethod:'foo |
|
149 |
^ self bar:''hello''. |
|
150 |
||
151 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
152 |
' |
|
153 |
in:UndefinedObject |
|
154 |
" |
|
155 |
||
156 |
"Created: / 28-04-2010 / 13:44:24 / cg" |
|
157 |
! |
|
158 |
||
159 |
formatMethod:methodOrNil source:aString in:aClass using:preferencesOrNil |
|
160 |
"format (recolor) a method in a given class. |
|
161 |
Return the text containing font changes and color information." |
|
162 |
||
163 |
|highlighter tree text endPos eColor| |
|
164 |
||
165 |
aString isNil ifTrue:[^ nil]. |
|
166 |
||
167 |
Error handle:[:ex | |
|
3201
13eb554c3f26
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
168 |
Transcript showCR:ex description. |
13eb554c3f26
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
169 |
self breakPoint:#cg. |
13eb554c3f26
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
170 |
|
3145
f3b8c89756fb
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3072
diff
changeset
|
171 |
ex creator isHandled ifTrue:[ |
2371 | 172 |
ex reject. |
173 |
]. |
|
3072
51ffc65ee7b5
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
2873
diff
changeset
|
174 |
(ParseError handles:ex) ifFalse:[ |
2371 | 175 |
"Parse error may happen when re-formatting incomplete code while editing" |
176 |
('SyntaxHighlighter [info]: error during highlight: ' , ex description) infoPrintCR. |
|
177 |
"/ ex suspendedContext fullPrintAll. |
|
178 |
]. |
|
179 |
^ aString |
|
180 |
] do:[ |
|
181 |
highlighter := self for:(ReadStream on:aString string) in:aClass. |
|
2527
a87cf2c8edf2
changed: #formatMethod:source:in:using:
Claus Gittinger <cg@exept.de>
parents:
2526
diff
changeset
|
182 |
highlighter method:methodOrNil. |
2371 | 183 |
preferencesOrNil notNil ifTrue:[highlighter preferences:preferencesOrNil]. |
184 |
"/ highlighter ignoreErrors:true. |
|
185 |
highlighter ignoreWarnings:true. |
|
186 |
highlighter sourceText:(text := aString string asText). |
|
187 |
||
188 |
"/ use an array here - this can be changed much faster using #at:put: |
|
189 |
text emphasisCollection:(Array new:aString size). |
|
190 |
||
191 |
tree := highlighter parseMethod. |
|
192 |
"/ now, convert the emphasis-array to a runArray |
|
193 |
text emphasisCollection:(text emphasis asRunArray). |
|
194 |
||
195 |
tree == #Error ifTrue:[ |
|
196 |
eColor := UserPreferences current errorColor. |
|
197 |
eColor notNil ifTrue:[ |
|
198 |
"/ mhmh - which is better ... |
|
199 |
"/ alternative1: color rest after error in red |
|
200 |
text |
|
201 |
emphasizeFrom:(highlighter sourceStream position1Based) |
|
202 |
to:text size |
|
203 |
with:(#color->eColor). |
|
204 |
] ifFalse:[ |
|
205 |
"/ alternative2: take original emphasis for rest |
|
206 |
||
207 |
endPos := highlighter sourceStream position1Based. |
|
208 |
endPos >= text size ifTrue:[ |
|
209 |
^ text |
|
210 |
]. |
|
211 |
^ (text copyTo:endPos) , (aString copyFrom:(endPos+1)) |
|
212 |
]. |
|
213 |
"/ alternative3: no emphasis for rest. |
|
214 |
]. |
|
215 |
^ text |
|
216 |
] |
|
217 |
" |
|
218 |
self |
|
219 |
formatMethod:'foo |
|
220 |
^ self bar:''hello''. |
|
221 |
||
222 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
223 |
' |
|
224 |
in:UndefinedObject |
|
225 |
" |
|
226 |
||
227 |
"Created: / 28-04-2010 / 13:01:42 / cg" |
|
2527
a87cf2c8edf2
changed: #formatMethod:source:in:using:
Claus Gittinger <cg@exept.de>
parents:
2526
diff
changeset
|
228 |
"Modified: / 05-07-2011 / 11:22:20 / cg" |
2371 | 229 |
! |
230 |
||
2526
ecd1ee8f03bc
category of: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents:
2525
diff
changeset
|
231 |
formatMethod:aMethodOrNil source:aString in:aClass using:preferencesOrNil elementsInto: elements |
2568
44f3c6ce19f1
fixed #formatMethod:source:in:using:elementsInto:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2527
diff
changeset
|
232 |
|
44f3c6ce19f1
fixed #formatMethod:source:in:using:elementsInto:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2527
diff
changeset
|
233 |
^ self formatMethod:aMethodOrNil source:aString in:aClass using:preferencesOrNil |
2526
ecd1ee8f03bc
category of: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents:
2525
diff
changeset
|
234 |
|
ecd1ee8f03bc
category of: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents:
2525
diff
changeset
|
235 |
"Created: / 05-07-2011 / 10:41:14 / cg" |
2568
44f3c6ce19f1
fixed #formatMethod:source:in:using:elementsInto:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2527
diff
changeset
|
236 |
"Modified: / 20-07-2011 / 16:29:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2526
ecd1ee8f03bc
category of: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents:
2525
diff
changeset
|
237 |
! |
ecd1ee8f03bc
category of: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents:
2525
diff
changeset
|
238 |
|
2371 | 239 |
formatMethodSource:aString in:aClass |
240 |
"format (recolor) a method in a given class. |
|
241 |
Return the text containing font changes and color information." |
|
242 |
||
243 |
^ self formatMethod:nil source:aString in:aClass using:nil |
|
244 |
||
245 |
" |
|
246 |
self |
|
247 |
formatMethod:'foo |
|
248 |
^ self bar:''hello''. |
|
249 |
||
250 |
' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , ' |
|
251 |
' |
|
252 |
in:UndefinedObject |
|
253 |
" |
|
254 |
||
255 |
"Created: / 28-04-2010 / 12:58:13 / cg" |
|
256 |
! |
|
257 |
||
258 |
formatMethodSource:aString in:aClass using:preferencesOrNil |
|
259 |
"format (recolor) a method in a given class. |
|
260 |
Return the text containing font changes and color information." |
|
261 |
||
262 |
^ self formatMethod:nil source:aString in:aClass using:preferencesOrNil |
|
263 |
||
264 |
"Modified: / 28-04-2010 / 13:02:11 / cg" |
|
265 |
! ! |
|
266 |
||
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
267 |
!AbstractSyntaxHighlighter class methodsFor:'utilities'! |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
268 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
269 |
mark:sourceText from:pos1 to:pos2 withAddedEmphasis:addedEmphasis |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
270 |
sourceText emphasisFrom:pos1 to:pos2 add:addedEmphasis |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
271 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
272 |
"Created: / 01-06-2012 / 21:43:36 / cg" |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
273 |
! |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
274 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
275 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
276 |
|e p2 clr| |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
277 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
278 |
(clrIn isNil or:[clrIn = Color black]) ifTrue:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
279 |
e := fontEmp |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
280 |
] ifFalse:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
281 |
clr := clrIn onDevice:Screen current. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
282 |
fontEmp isNil ifTrue:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
283 |
e := (#color->clr) |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
284 |
] ifFalse:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
285 |
e := Text addEmphasis:fontEmp to:(#color->clr). |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
286 |
] |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
287 |
]. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
288 |
(p2 := pos2) isNil ifTrue:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
289 |
p2 := sourceText size |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
290 |
] ifFalse:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
291 |
p2 := p2 min:sourceText size |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
292 |
]. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
293 |
sourceText emphasizeFrom:pos1 to:p2 with:e |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
294 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
295 |
"Created: / 01-06-2012 / 21:42:41 / cg" |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
296 |
! |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
297 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
298 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
299 |
|e p2 clr fgClr| |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
300 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
301 |
fgClr := fgClr1 ? fgClr2. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
302 |
(fgClr isNil or:[fgClr = Color black]) ifTrue:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
303 |
e := fontEmp |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
304 |
] ifFalse:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
305 |
clr := fgClr onDevice:Screen current. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
306 |
fontEmp isNil ifTrue:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
307 |
e := (#color->clr) |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
308 |
] ifFalse:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
309 |
e := Text addEmphasis:fontEmp to:(#color->clr). |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
310 |
] |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
311 |
]. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
312 |
bgClr notNil ifTrue:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
313 |
e := Text addEmphasis:(#backgroundColor->bgClr) to:e. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
314 |
]. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
315 |
(p2 := pos2) isNil ifTrue:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
316 |
p2 := sourceText size |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
317 |
] ifFalse:[ |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
318 |
p2 := p2 min:sourceText size |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
319 |
]. |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
320 |
sourceText emphasizeFrom:pos1 to:p2 with:e |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
321 |
|
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
322 |
"Created: / 01-06-2012 / 21:44:17 / cg" |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
323 |
! ! |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
324 |
|
2371 | 325 |
!AbstractSyntaxHighlighter methodsFor:'accessing'! |
326 |
||
327 |
method:aMethod |
|
2525 | 328 |
"the original method, if known (for subclasses which can make use of it)" |
329 |
||
330 |
method := aMethod. |
|
2371 | 331 |
|
332 |
"Created: / 28-04-2010 / 13:15:33 / cg" |
|
333 |
! |
|
334 |
||
335 |
preferences:something |
|
336 |
preferences := something. |
|
337 |
! |
|
338 |
||
339 |
sourceText |
|
340 |
^ sourceText |
|
341 |
||
342 |
"Created: / 31.3.1998 / 11:49:05 / cg" |
|
343 |
! |
|
344 |
||
345 |
sourceText:aString |
|
346 |
sourceText := aString. |
|
347 |
||
348 |
"Created: / 31-03-1998 / 11:49:05 / cg" |
|
349 |
"Modified: / 28-04-2010 / 13:22:27 / cg" |
|
350 |
! ! |
|
351 |
||
352 |
!AbstractSyntaxHighlighter methodsFor:'error handling'! |
|
353 |
||
354 |
parseError:aMessage position:position to:endPos |
|
355 |
"/ Transcript showCR:aMessage. |
|
356 |
super parseError:aMessage position:position to:endPos. |
|
357 |
||
358 |
self |
|
359 |
markFrom:position to:endPos |
|
360 |
withEmphasis:nil color:UserPreferences current errorColor |
|
361 |
! |
|
362 |
||
363 |
showErrorMessage:aMessage position:pos |
|
364 |
"/ Transcript showCR:aMessage. |
|
365 |
super showErrorMessage:aMessage position:pos. |
|
366 |
||
367 |
self |
|
368 |
markFrom:pos to:nil |
|
369 |
withEmphasis:nil color:UserPreferences current errorColor |
|
370 |
! |
|
371 |
||
372 |
syntaxError:aMessage position:position to:endPos |
|
373 |
"/ Transcript showCR:aMessage. |
|
374 |
super syntaxError:aMessage position:position to:endPos. |
|
375 |
||
376 |
self |
|
377 |
markFrom:position to:endPos |
|
378 |
withEmphasis:nil color:UserPreferences current errorColor |
|
379 |
! |
|
380 |
||
381 |
warning:msg position:pos1 to:pos2 |
|
382 |
"/ self markUnknownIdentifierFrom:pos1 to:pos2 |
|
383 |
||
384 |
"/ self |
|
385 |
"/ markFrom:pos1 to:pos2 |
|
386 |
"/ withEmphasis:nil color:UserPreferences current errorColor |
|
387 |
||
388 |
"Modified: / 25.9.1999 / 18:42:30 / cg" |
|
389 |
! ! |
|
390 |
||
391 |
!AbstractSyntaxHighlighter methodsFor:'initialization'! |
|
392 |
||
393 |
initialize |
|
394 |
super initialize. |
|
395 |
||
396 |
foldConstants := false. |
|
397 |
preferences := UserPreferences current. |
|
398 |
fullSelectorCheck := preferences fullSelectorCheck. |
|
399 |
||
400 |
"Created: / 31-03-1998 / 15:12:55 / cg" |
|
401 |
"Modified: / 28-04-2010 / 13:17:45 / cg" |
|
402 |
! ! |
|
403 |
||
404 |
!AbstractSyntaxHighlighter methodsFor:'misc'! |
|
405 |
||
2817
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
406 |
collectionEnumerationSelectors |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
407 |
"these are considered wellknown, builtin selectors of very common |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
408 |
collection enumeration methods. |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
409 |
These are optionally shown with another color (dark green)" |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
410 |
|
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
411 |
^ #( |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
412 |
collect: |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
413 |
select: |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
414 |
inject:into: |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
415 |
count: |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
416 |
collect:thenSelect: |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
417 |
select:thenCollect: |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
418 |
) |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
419 |
|
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
420 |
"Created: / 14-02-2012 / 15:56:59 / cg" |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
421 |
! |
b92ea70a5a9f
added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents:
2813
diff
changeset
|
422 |
|
2371 | 423 |
controlFlowSelectors |
2660
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
424 |
"these are considered wellknown, builtin selectors of very common |
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
425 |
control flow constructs. Correspond to syntax or special forms in other |
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
426 |
languages. These are optionally shown with another color (blue)" |
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
427 |
|
2371 | 428 |
^ #( |
2687
aaaa9b5dd620
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2663
diff
changeset
|
429 |
ifTrue: ifFalse: |
aaaa9b5dd620
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2663
diff
changeset
|
430 |
ifTrue:ifFalse: ifFalse:ifTrue: |
2688
a08501ca4403
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2687
diff
changeset
|
431 |
ifNil: ifNotNil: |
2687
aaaa9b5dd620
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2663
diff
changeset
|
432 |
ifNil:ifNotNil: ifNotNil:ifNil: |
aaaa9b5dd620
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2663
diff
changeset
|
433 |
and: or: |
2371 | 434 |
|
435 |
whileTrue: |
|
436 |
whileFalse: |
|
437 |
||
438 |
to:do: |
|
439 |
downTo:do: |
|
440 |
to:by:do: |
|
441 |
||
442 |
loop |
|
443 |
whileTrue |
|
444 |
whileFalse |
|
445 |
doWhile: |
|
446 |
doUntil: |
|
447 |
||
448 |
do: |
|
2660
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
449 |
doWithIndex: |
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
450 |
pairWiseDo: |
2371 | 451 |
keysAndValuesDo: |
2660
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
452 |
|
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
453 |
withPriority:do: |
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
454 |
handle:do: |
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
455 |
"/ newProcess |
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
456 |
fork: |
1f8eccda27db
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2568
diff
changeset
|
457 |
ensure: |
2662
a1b97a48e44e
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2660
diff
changeset
|
458 |
ifCurtailed: |
2873
6cf23616a42d
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2872
diff
changeset
|
459 |
|
6cf23616a42d
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2872
diff
changeset
|
460 |
caseOf: |
6cf23616a42d
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2872
diff
changeset
|
461 |
caseOf:otherwise: |
2371 | 462 |
) |
463 |
||
464 |
"Created: / 08-09-2006 / 15:56:47 / cg" |
|
465 |
! |
|
466 |
||
467 |
defineAsUndeclaredVariable:aName |
|
468 |
"redefined to NOT declare undefined vars" |
|
469 |
||
470 |
^ VariableNode globalNamed:aName |
|
471 |
||
472 |
"Modified: / 19.10.1998 / 19:38:12 / cg" |
|
473 |
! |
|
474 |
||
475 |
isSyntaxHighlighter |
|
476 |
^ true |
|
477 |
||
478 |
! |
|
479 |
||
480 |
plausibilityCheck:aNode |
|
481 |
"redefined to NOT do checks" |
|
482 |
||
483 |
^ nil |
|
484 |
||
485 |
"Modified: / 19.10.1998 / 19:38:12 / cg" |
|
486 |
"Created: / 19.10.1998 / 19:57:18 / cg" |
|
487 |
! ! |
|
488 |
||
489 |
!AbstractSyntaxHighlighter methodsFor:'syntax detection'! |
|
490 |
||
491 |
markFrom:pos1 to:pos2 withAddedEmphasis:addedEmphasis |
|
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
492 |
self class |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
493 |
mark:sourceText from:pos1 to:pos2 withAddedEmphasis:addedEmphasis |
2371 | 494 |
|
495 |
"Created: / 15-01-2008 / 11:48:18 / cg" |
|
496 |
! |
|
497 |
||
498 |
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:clrIn |
|
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
499 |
self class |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
500 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn |
2371 | 501 |
|
502 |
"Created: / 31-03-1998 / 13:26:53 / cg" |
|
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
503 |
"Modified: / 01-06-2012 / 21:43:04 / cg" |
2371 | 504 |
! |
505 |
||
2813
51e4b12f18dc
added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
2688
diff
changeset
|
506 |
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr |
2872
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
507 |
self class |
f992970ef1cd
refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents:
2817
diff
changeset
|
508 |
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr |
2813
51e4b12f18dc
added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
2688
diff
changeset
|
509 |
|
51e4b12f18dc
added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
2688
diff
changeset
|
510 |
"Created: / 13-02-2012 / 11:48:09 / cg" |
51e4b12f18dc
added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
2688
diff
changeset
|
511 |
! |
51e4b12f18dc
added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents:
2688
diff
changeset
|
512 |
|
2371 | 513 |
markVariable:v |
514 |
|pos endPos| |
|
515 |
||
516 |
pos := tokenPosition. |
|
517 |
endPos := pos+tokenName size-1. |
|
3189
5a4bb1727d08
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3145
diff
changeset
|
518 |
self markVariable:v from:pos to:endPos assigned:false |
2371 | 519 |
|
2464
595ec0d9efa9
comment/format in: #markVariable:
Claus Gittinger <cg@exept.de>
parents:
2392
diff
changeset
|
520 |
"Modified: / 30-11-2010 / 14:44:28 / cg" |
2371 | 521 |
! ! |
522 |
||
523 |
!AbstractSyntaxHighlighter class methodsFor:'documentation'! |
|
524 |
||
2663
e94fe6b650ad
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2662
diff
changeset
|
525 |
version |
3201
13eb554c3f26
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
526 |
^ '$Header: /cvs/stx/stx/libcomp/AbstractSyntaxHighlighter.st,v 1.22 2013-06-20 22:52:56 cg Exp $' |
2663
e94fe6b650ad
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2662
diff
changeset
|
527 |
! |
e94fe6b650ad
changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents:
2662
diff
changeset
|
528 |
|
2371 | 529 |
version_CVS |
3201
13eb554c3f26
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
530 |
^ '$Header: /cvs/stx/stx/libcomp/AbstractSyntaxHighlighter.st,v 1.22 2013-06-20 22:52:56 cg Exp $' |
2506 | 531 |
! |
532 |
||
533 |
version_SVN |
|
3189
5a4bb1727d08
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
3145
diff
changeset
|
534 |
^ '$ Id $' |
2371 | 535 |
! ! |
3072
51ffc65ee7b5
class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
2873
diff
changeset
|
536 |