added entry to color an expression
authorClaus Gittinger <cg@exept.de>
Thu, 09 Apr 1998 17:02:15 +0200
changeset 684 dd691ac07f90
parent 683 cf417f56631d
child 685 fbbe821b0ce3
added entry to color an expression
SyntaxHighlighter.st
--- a/SyntaxHighlighter.st	Tue Apr 07 17:24:58 1998 +0200
+++ b/SyntaxHighlighter.st	Thu Apr 09 17:02:15 1998 +0200
@@ -57,6 +57,59 @@
 
 !SyntaxHighlighter class methodsFor:'highlighting'!
 
+formatExpression:aString in:aClass
+    "format (recolor) an expression in a given class.
+     Return the text containing font changes and color information."
+
+    |parser tree text endPos|
+
+    aString isNil ifTrue:[^ nil].
+
+    parser := self for:(ReadStream on:aString string) in:aClass.
+    parser ignoreErrors.
+    parser ignoreWarnings.
+    parser sourceText:(text := aString string asText).
+    "/ use an array here - this can be changed much faster using #at:put:
+    text emphasisCollection:(Array new:aString size).
+
+    parser nextToken.
+    tree := parser expression.
+    "/ now, convert the emphasis-array to a runArray
+    text emphasisCollection:(text emphasis asRunArray).
+
+    tree == #Error ifTrue:[
+        "/ mhmh - which is better ...
+        "/ alternative1: color rest after error in red
+"/        text 
+"/            emphasizeFrom:(parser sourceStream position) 
+"/            to:text size 
+"/            with:(#color->Color red).
+
+
+        "/ alternative2: take original emphasis for rest
+
+        endPos := parser sourceStream position.
+        endPos >= text size ifTrue:[
+            ^ text
+        ].
+        ^ (text copyTo:endPos) , (aString copyFrom:(endPos+1))
+
+        "/ alternative3: no emphasis for rest.
+
+"/        ^ text "/ aString
+    ].
+    ^ text
+
+    "
+     self
+        formatExpression:'(1 + 2) max:5' 
+        in:UndefinedObject
+    "
+
+    "Modified: / 7.4.1998 / 09:57:19 / cg"
+    "Created: / 9.4.1998 / 16:57:16 / cg"
+!
+
 formatMethod:aString in:aClass
     "format (recolor) a method in a given class.
      Return the text containing font changes and color information."
@@ -356,5 +409,5 @@
 !SyntaxHighlighter class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/SyntaxHighlighter.st,v 1.10 1998-04-07 09:11:39 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/SyntaxHighlighter.st,v 1.11 1998-04-09 15:02:15 cg Exp $'
 ! !