From 110dc33865f826645fbb18ab42b149ba091c3401 Mon Sep 17 00:00:00 2001 From: benkobalog Date: Thu, 10 May 2018 16:28:43 +0200 Subject: [PATCH 1/2] Fix #4500 Allow keyword start after numbers --- compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala | 2 +- .../dotty/tools/dotc/printing/SyntaxHighlightingTests.scala | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala index 6c6348e80a03..0ff19a2cb6f5 100644 --- a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala +++ b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala @@ -79,7 +79,7 @@ object SyntaxHighlighting { } else { if (n.isUpper && (keywordStart || prev == '.')) { appendWhile(n, !typeEnders.contains(_), typeDef) - } else if (keywordStart) { + } else if (keywordStart || prev.isDigit) { append(n, keywords.contains(_), { kw => if (kw == "new") typeDef(kw) else keyword(kw) }) diff --git a/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala b/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala index 2b8d66d84424..324b797de005 100644 --- a/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala +++ b/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala @@ -64,6 +64,7 @@ class SyntaxHighlightingTests { @Test def expressions = { test("val x = 1 + 2 + 3", " = + + ") + test("if(true) 3 else 1", "() ") } @Test From 1629f99ccafb00f2160ccfb9b3de41302e39fb9b Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Tue, 28 Aug 2018 16:36:40 +0200 Subject: [PATCH 2/2] Fix `keywordStart` instead --- .../src/dotty/tools/dotc/printing/SyntaxHighlighting.scala | 4 ++-- .../dotty/tools/dotc/printing/SyntaxHighlightingTests.scala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala index 0ff19a2cb6f5..243499d382e9 100644 --- a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala +++ b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala @@ -54,7 +54,7 @@ object SyntaxHighlighting { @forceInline def keywordStart = prev == 0 || prev == ' ' || prev == '{' || prev == '(' || prev == '\n' || prev == '[' || prev == ',' || prev == ':' || - prev == '|' || prev == '&' + prev == '|' || prev == '&' || prev.isDigit @forceInline def numberStart(c: Char) = c.isDigit && (!prev.isLetter || prev == '.' || prev == ' ' || prev == '(' || prev == '\u0000') @@ -79,7 +79,7 @@ object SyntaxHighlighting { } else { if (n.isUpper && (keywordStart || prev == '.')) { appendWhile(n, !typeEnders.contains(_), typeDef) - } else if (keywordStart || prev.isDigit) { + } else if (keywordStart) { append(n, keywords.contains(_), { kw => if (kw == "new") typeDef(kw) else keyword(kw) }) diff --git a/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala b/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala index 324b797de005..d02fd1d0b4cd 100644 --- a/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala +++ b/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala @@ -64,7 +64,7 @@ class SyntaxHighlightingTests { @Test def expressions = { test("val x = 1 + 2 + 3", " = + + ") - test("if(true) 3 else 1", "() ") + test("if (true) 3 else 1", " () ") } @Test