AbstractSyntaxHighlighter.st
changeset 4202 b74cb013e847
parent 4200 e0b3fd0f438c
child 4229 35f7bbf9efa4
--- a/AbstractSyntaxHighlighter.st	Sat Oct 21 15:25:10 2017 +0200
+++ b/AbstractSyntaxHighlighter.st	Sat Oct 21 15:25:24 2017 +0200
@@ -14,7 +14,8 @@
 "{ NameSpace: Smalltalk }"
 
 Parser subclass:#AbstractSyntaxHighlighter
-	instanceVariableNames:'method sourceText preferences fullSelectorCheck'
+	instanceVariableNames:'method sourceText preferences fullSelectorCheck commentColor
+		commentEmphasis commentFont constantColor constantEmphasis'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'System-Compiler'
@@ -435,30 +436,33 @@
 !
 
 mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontIn
+    "all positions are 1-based"
+    
     |e p2 clr|
 
     (clrIn isNil or:[clrIn = Color black]) ifTrue:[
-	e := fontEmp
+        e := fontEmp
     ] ifFalse:[
-	clr := clrIn onDevice:Screen current.
-	fontEmp isNil ifTrue:[
-	    e := (#color->clr)
-	] ifFalse:[
-	    e := Text addEmphasis:fontEmp to:(#color->clr).
-	]
+        clr := clrIn onDevice:Screen current.
+        fontEmp isNil ifTrue:[
+            e := (#color->clr)
+        ] ifFalse:[
+            e := Text addEmphasis:fontEmp to:(#color->clr).
+        ]
     ].
     fontIn notNil ifTrue:[
-	e := Text addEmphasis:e to:(#font->fontIn)
+        e := Text addEmphasis:e to:(#font->fontIn)
     ].
 
     (p2 := pos2) isNil ifTrue:[
-	p2 := sourceText size
+        p2 := sourceText size
     ] ifFalse:[
-	p2 := p2 min:sourceText size
+        p2 := p2 min:sourceText size
     ].
     sourceText emphasizeFrom:pos1 to:p2 with:e
 
     "Created: / 01-06-2012 / 21:42:41 / cg"
+    "Modified (comment): / 21-10-2017 / 14:24:20 / cg"
 !
 
 mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr
@@ -517,6 +521,23 @@
 
 !AbstractSyntaxHighlighter methodsFor:'accessing'!
 
+fetchHeavilyUsedPreferenceValues
+    preferences isNil ifTrue:[
+        commentColor :=  commentEmphasis := commentFont := nil.
+        constantColor := constantEmphasis := nil.
+        ^ self.
+    ].
+    
+    commentColor := preferences commentColor.
+    commentEmphasis := preferences commentEmphasis.
+    commentFont := preferences commentFont.
+
+    constantColor := preferences constantColor.
+    constantEmphasis := preferences constantEmphasis.
+
+    "Created: / 21-10-2017 / 14:13:33 / cg"
+!
+
 method:aMethod
     "the original method, if known (for subclasses which can make use of it)"
 
@@ -525,8 +546,13 @@
     "Created: / 28-04-2010 / 13:15:33 / cg"
 !
 
-preferences:something
-    preferences := something.
+preferences:aUserPreferencesInstance
+    preferences := aUserPreferencesInstance.
+
+    fullSelectorCheck := preferences fullSelectorCheck.
+    self fetchHeavilyUsedPreferenceValues.
+
+    "Modified: / 21-10-2017 / 14:20:06 / cg"
 !
 
 sourceText
@@ -593,11 +619,10 @@
     super initialize.
 
     foldConstants := false.
-    preferences := UserPreferences current.
-    fullSelectorCheck := preferences fullSelectorCheck.
+    self preferences:(UserPreferences current).
 
     "Created: / 31-03-1998 / 15:12:55 / cg"
-    "Modified: / 08-02-2017 / 00:31:30 / cg"
+    "Modified: / 21-10-2017 / 14:20:11 / cg"
 ! !
 
 !AbstractSyntaxHighlighter methodsFor:'misc'!
@@ -642,6 +667,39 @@
 
 !AbstractSyntaxHighlighter methodsFor:'syntax detection'!
 
+markCommentFrom:pos1 to:pos2
+    "all positions are 1-based"
+
+    self 
+        markFrom:pos1 to:pos2 
+        withEmphasis:commentEmphasis 
+        color:commentColor
+        font:commentFont
+
+    "
+     UserPreferences current commentEmphasis
+     UserPreferences current commentColor
+    "
+
+    "Modified (comment): / 21-10-2017 / 14:24:51 / cg"
+!
+
+markConstantFrom:pos1 to:pos2
+    self 
+        markFrom:pos1 to:pos2 
+        withEmphasis:constantEmphasis 
+        color:constantColor
+
+    "Created: / 31-03-1998 / 18:09:22 / cg"
+    "Modified: / 21-10-2017 / 14:15:48 / cg"
+!
+
+markFrom:pos1 length:len withEmphasis:fontEmp color:clrIn
+    self markFrom:pos1 to:pos1+len-1 withEmphasis:fontEmp color:clrIn
+
+    "Created: / 21-10-2017 / 14:47:46 / cg"
+!
+
 markFrom:pos1 to:pos2 withAddedEmphasis:addedEmphasis
     self class
 	mark:sourceText from:pos1 to:pos2 withAddedEmphasis:addedEmphasis
@@ -658,11 +716,14 @@
 !
 
 markFrom:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontInOrNil
+    "all positions are 1-based"
+
     self class
-	mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontInOrNil
+        mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontInOrNil
 
     "Created: / 31-03-1998 / 13:26:53 / cg"
     "Modified: / 01-06-2012 / 21:43:04 / cg"
+    "Modified (comment): / 21-10-2017 / 14:24:47 / cg"
 !
 
 markFrom:pos1 to:pos2 withEmphasis:fontEmp color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr