@@ -57,13 +57,17 @@ object SyntaxHighlighting {
5757 scanner.nextToken()
5858 val end = scanner.lastOffset
5959
60- if (alphaKeywords.contains(token))
60+ // Branch order is important. For example,
61+ // `true` is at the same time a keyword and a literal
62+ if (literalTokens.contains(token))
63+ highlightRange(start, end, LiteralColor )
64+ else if (alphaKeywords.contains(token))
6165 highlightRange(start, end, KeywordColor )
6266 else if (token == IDENTIFIER && name == nme.??? )
6367 highlightRange(start, end, Console .RED_B )
6468 }
6569
66- val treeHighlighter = new untpd.UntypedTreeTraverser {
70+ object TreeHighlighter extends untpd.UntypedTreeTraverser {
6771 import untpd ._
6872
6973 def ignored (tree : NameTree ) = {
@@ -72,6 +76,9 @@ object SyntaxHighlighting {
7276 name == nme.ERROR || name == nme.CONSTRUCTOR
7377 }
7478
79+ def highlight (trees : List [Tree ])(implicit ctx : Context ): Unit =
80+ trees.foreach(traverse)
81+
7582 def traverse (tree : Tree )(implicit ctx : Context ): Unit = {
7683 tree match {
7784 case tree : NameTree if ignored(tree) =>
@@ -85,8 +92,6 @@ object SyntaxHighlighting {
8592 highlightPosition(tree.pos, TypeColor )
8693 case _ : TypTree =>
8794 highlightPosition(tree.pos, TypeColor )
88- case _ : Literal =>
89- highlightPosition(tree.pos, LiteralColor )
9095 case _ =>
9196 }
9297 traverseChildren(tree)
@@ -95,8 +100,7 @@ object SyntaxHighlighting {
95100
96101 val parser = new Parser (source)
97102 val trees = parser.blockStatSeq()
98- for (tree <- trees)
99- treeHighlighter.traverse(tree)
103+ TreeHighlighter .highlight(trees)
100104
101105 val highlighted = new StringBuilder ()
102106
0 commit comments