@@ -56,13 +56,17 @@ object SyntaxHighlighting {
5656 scanner.nextToken()
5757 val end = scanner.lastOffset
5858
59- if (alphaKeywords.contains(token))
59+ // Branch order is important. For example,
60+ // `true` is at the same time a keyword and a literal
61+ if (literalTokens.contains(token))
62+ highlightRange(start, end, LiteralColor )
63+ else if (alphaKeywords.contains(token))
6064 highlightRange(start, end, KeywordColor )
6165 else if (token == IDENTIFIER && name == nme.??? )
6266 highlightRange(start, end, Console .RED_B )
6367 }
6468
65- val treeHighlighter = new untpd.UntypedTreeTraverser {
69+ object TreeHighlighter extends untpd.UntypedTreeTraverser {
6670 import untpd ._
6771
6872 def ignored (tree : NameTree ) = {
@@ -71,6 +75,9 @@ object SyntaxHighlighting {
7175 name == nme.ERROR || name == nme.CONSTRUCTOR
7276 }
7377
78+ def highlight (trees : List [Tree ])(implicit ctx : Context ): Unit =
79+ trees.foreach(traverse)
80+
7481 def traverse (tree : Tree )(implicit ctx : Context ): Unit = {
7582 tree match {
7683 case tree : NameTree if ignored(tree) =>
@@ -84,8 +91,6 @@ object SyntaxHighlighting {
8491 highlightPosition(tree.pos, TypeColor )
8592 case _ : TypTree =>
8693 highlightPosition(tree.pos, TypeColor )
87- case _ : Literal =>
88- highlightPosition(tree.pos, LiteralColor )
8994 case _ =>
9095 }
9196 traverseChildren(tree)
@@ -94,8 +99,7 @@ object SyntaxHighlighting {
9499
95100 val parser = new Parser (source)
96101 val trees = parser.blockStatSeq()
97- for (tree <- trees)
98- treeHighlighter.traverse(tree)
102+ TreeHighlighter .highlight(trees)
99103
100104 val highlighted = new StringBuilder ()
101105
0 commit comments