Skip to content

Commit 5c8c42d

Browse files
committed
Highlight inline as a "soft" keyword
1 parent 093cc24 commit 5c8c42d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ object Parsers {
12231223
val t = postfixExpr()
12241224
if (in.token == MATCH) matchExpr(t, start, InlineMatch)
12251225
else {
1226-
syntaxErrorOrIncomplete("`match` or `if` expected but ${in.token} found")
1226+
syntaxErrorOrIncomplete(s"`match` or `if` expected but ${showToken(in.token)} found")
12271227
t
12281228
}
12291229
}

compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,22 @@ object SyntaxHighlighting {
6262
token match {
6363
case _ if literalTokens.contains(token) =>
6464
highlightRange(start, end, LiteralColor)
65+
6566
case STRINGPART =>
6667
// String interpolation parts include `$` but
6768
// we don't highlight it, hence the `-1`
6869
highlightRange(start, end - 1, LiteralColor)
70+
6971
case _ if alphaKeywords.contains(token) =>
7072
highlightRange(start, end, KeywordColor)
73+
74+
case IDENTIFIER if name == nme.INLINEkw =>
75+
// `inline` is a "soft" keyword
76+
highlightRange(start, end, KeywordColor)
77+
7178
case IDENTIFIER if name == nme.??? =>
7279
highlightRange(start, end, Console.RED_B)
80+
7381
case _ =>
7482
}
7583
}

compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,11 @@ class SyntaxHighlightingTests extends DottyTest {
120120
test("val foo @ Foo(x) = bar", ???)
121121
test("x match { case Foo | Bar => 1 }", ???)
122122
}
123+
124+
@Test
125+
def softKeywords = {
126+
test("inline def foo = 1", "<K|inline> <K|def> <V|foo> = <L|1>")
127+
test("@inline def foo = 1", "<T|@inline> <K|def> <V|foo> = <L|1>")
128+
test("class inline", "<K|class> <T|inline>")
129+
}
123130
}

0 commit comments

Comments
 (0)