tools/JavaSourceHighlighter.st
branchdevelopment
changeset 2708 648286432b9a
parent 2707 165badf6c997
child 2711 a00302fe5083
child 2716 1cca77810e04
--- a/tools/JavaSourceHighlighter.st	Thu Sep 05 03:29:47 2013 +0100
+++ b/tools/JavaSourceHighlighter.st	Thu Sep 05 16:37:21 2013 +0100
@@ -255,7 +255,7 @@
 
 format: source kind: kind in: class
 
-    | scanner parser builder cacheIt document tree |
+    | sourceUnit scanner parser marker cacheIt document tree |
 
     "Optimization - if full class source is to be formatted,
      consult cache - when browsing the code or debugging, very 
@@ -274,28 +274,28 @@
         ].
         document := JavaSourceDocument for: class.
     ].
+    marker := Marker new.
+    marker highlighter: self.
+
+    sourceText := source isText 
+                    ifTrue:[source copy] 
+                    ifFalse:[source asText].
 
 
-    source isText ifTrue:[
-        sourceText := source copy
-    ] ifFalse:[
-        sourceText := source asText.
-    ].
+"/    sourceUnit := (Java classForName:'stx.libjava.tools.source.JavaSource') new.
+"/    sourceUnit setContents: source string.
+"/    parser := (Java classForName:'stx.libjava.tools.source.JavaSourceHighlighter') new.
+"/    parser setMarker: marker.
+"/    tree := parser parse: sourceUnit.
 
-    scanner := Scanner for: source.
-    scanner highlighter: self.     
+    scanner := Scanner for: source string.
+    scanner highlighter: self.
     [
         [ scanner nextToken ~~ #EOF ] whileTrue.
     ] on: Error do:[
-    ]. 
 
-"/    builder := Builder new.
-"/    builder highlighter: self.
-"/    scanner highlighter: self.
-"/    parser := Parser newStartingAt: kind.
-"/    parser builder: builder.
-"/    parser stream: scanner.
-"/    tree := parser parse: scanner.
+        ].  
+
 
     ^ cacheIt ifTrue:[
         document sourceText: sourceText.
@@ -309,7 +309,7 @@
     ]
 
     "Created: / 17-03-2012 / 14:02:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 05-09-2013 / 02:56:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-09-2013 / 16:31:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaSourceHighlighter methodsFor:'syntax detection'!
@@ -638,21 +638,29 @@
     "Modified: / 05-09-2013 / 03:14:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+
+!JavaSourceHighlighter::Marker methodsFor:'accessing'!
+
+highlighter:aJavaSourceHighlighter
+    highlighter := aJavaSourceHighlighter.
+! !
+
 !JavaSourceHighlighter::Marker methodsFor:'syntax detection'!
 
 mark: kind from:pos1 to:pos2
 
-    kind == MARK_KEYWORD        ifTrue:[ ^ highlighter markKeywordFrom: pos1 to: pos2 ].
-    kind == MARK_KEYWORD_FLOW   ifTrue:[ ^ highlighter markKeywordFlowFrom: pos1 to: pos2 ].
+    kind == MARK_KEYWORD        ifTrue:[ ^ highlighter markKeywordFrom: pos1 + 1 to: pos2 + 1].
+    kind == MARK_KEYWORD_FLOW   ifTrue:[ ^ highlighter markKeywordFlowFrom: pos1 + 1 to: pos2 + 1 ].
 
-    kind == MARK_NUMBER         ifTrue:[ ^ highlighter markConstantFrom: pos1 to: pos2 ].
-    kind == MARK_STRING         ifTrue:[ ^ highlighter markConstantFrom: pos1 to: pos2 ].
-    kind == MARK_CHARACTER      ifTrue:[ ^ highlighter markConstantFrom: pos1 to: pos2 ].
+    kind == MARK_NUMBER         ifTrue:[ ^ highlighter markConstantFrom: pos1 + 1 to: pos2 + 1 ].
+    kind == MARK_STRING         ifTrue:[ ^ highlighter markConstantFrom: pos1 + 1 to: pos2 + 1 ].
+    kind == MARK_CHARACTER      ifTrue:[ ^ highlighter markConstantFrom: pos1 + 1 to: pos2 + 1 ].
 
-    kind == MARK_COMMENT       ifTrue:[ ^ highlighter markCommentFrom: pos1 to: pos2 ].
-    kind == MARK_JAVADOC       ifTrue:[ ^ highlighter markCommentFrom: pos1 to: pos2 ].
+    kind == MARK_COMMENT        ifTrue:[ ^ highlighter markCommentFrom: pos1 + 1 to: pos2 + 1 ].
+    kind == MARK_JAVADOC        ifTrue:[ ^ highlighter markCommentFrom: pos1 + 1 to: pos2 + 1 ].
 
     "Created: / 05-09-2013 / 03:03:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-09-2013 / 09:07:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaSourceHighlighter::Scanner methodsFor:'accessing'!