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