@@ -56,13 +56,17 @@ object SyntaxHighlighting {
56
56
scanner.nextToken()
57
57
val end = scanner.lastOffset
58
58
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))
60
64
highlightRange(start, end, KeywordColor )
61
65
else if (token == IDENTIFIER && name == nme.??? )
62
66
highlightRange(start, end, Console .RED_B )
63
67
}
64
68
65
- val treeHighlighter = new untpd.UntypedTreeTraverser {
69
+ object TreeHighlighter extends untpd.UntypedTreeTraverser {
66
70
import untpd ._
67
71
68
72
def ignored (tree : NameTree ) = {
@@ -71,6 +75,9 @@ object SyntaxHighlighting {
71
75
name == nme.ERROR || name == nme.CONSTRUCTOR
72
76
}
73
77
78
+ def highlight (trees : List [Tree ])(implicit ctx : Context ): Unit =
79
+ trees.foreach(traverse)
80
+
74
81
def traverse (tree : Tree )(implicit ctx : Context ): Unit = {
75
82
tree match {
76
83
case tree : NameTree if ignored(tree) =>
@@ -84,8 +91,6 @@ object SyntaxHighlighting {
84
91
highlightPosition(tree.pos, TypeColor )
85
92
case _ : TypTree =>
86
93
highlightPosition(tree.pos, TypeColor )
87
- case _ : Literal =>
88
- highlightPosition(tree.pos, LiteralColor )
89
94
case _ =>
90
95
}
91
96
traverseChildren(tree)
@@ -94,8 +99,7 @@ object SyntaxHighlighting {
94
99
95
100
val parser = new Parser (source)
96
101
val trees = parser.blockStatSeq()
97
- for (tree <- trees)
98
- treeHighlighter.traverse(tree)
102
+ TreeHighlighter .highlight(trees)
99
103
100
104
val highlighted = new StringBuilder ()
101
105
0 commit comments