From 17ba4a224810ff1e95564f966643adf3e70691a1 Mon Sep 17 00:00:00 2001 From: Daniel Jeong Date: Tue, 1 Aug 2023 12:34:19 +0000 Subject: [PATCH] Fix invalid true/false operators --- grammars/csharp.tmLanguage | 2 +- grammars/csharp.tmLanguage.cson | 2 +- src/csharp.tmLanguage.yml | 2 +- test/operator.tests.ts | 23 ++++++++++++++++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/grammars/csharp.tmLanguage b/grammars/csharp.tmLanguage index 7a96507..6ccb907 100644 --- a/grammars/csharp.tmLanguage +++ b/grammars/csharp.tmLanguage @@ -2347,7 +2347,7 @@ )* ) )\s* -(?<operator_keyword>\boperator)\s* +(?<operator_keyword>\boperator\b)\s* (?<operator>[+\-*/%&|\^!=~<>]+|true|false)\s* (?=\() beginCaptures diff --git a/grammars/csharp.tmLanguage.cson b/grammars/csharp.tmLanguage.cson index b6c7ed3..0495a41 100644 --- a/grammars/csharp.tmLanguage.cson +++ b/grammars/csharp.tmLanguage.cson @@ -1516,7 +1516,7 @@ repository: )* ) )\\s* - (?\\boperator)\\s* + (?\\boperator\\b)\\s* (?[+\\-*/%&|\\^!=~<>]+|true|false)\\s* (?=\\() ''' diff --git a/src/csharp.tmLanguage.yml b/src/csharp.tmLanguage.yml index 994a2b8..fd77de0 100644 --- a/src/csharp.tmLanguage.yml +++ b/src/csharp.tmLanguage.yml @@ -879,7 +879,7 @@ repository: )* ) )\s* - (?\boperator)\s* + (?\boperator\b)\s* (?[+\-*/%&|\^!=~<>]+|true|false)\s* (?=\() beginCaptures: diff --git a/test/operator.tests.ts b/test/operator.tests.ts index 14df9bf..a962e8b 100644 --- a/test/operator.tests.ts +++ b/test/operator.tests.ts @@ -150,7 +150,6 @@ describe("Operators", () => { }); it("unary true", async () => { - const input = Input.InClass(`public static int operator true(int value) { return value != 0; }`); const tokens = await tokenize(input); @@ -173,6 +172,28 @@ describe("Operators", () => { Token.Punctuation.CloseBrace]); }); + it("unary true invalid", async () => { + const input = Input.InClass(`public static bool operatortrue(int value) { return value != 0; }`); + const tokens = await tokenize(input); + + tokens.should.deep.equal([ + Token.Keywords.Modifiers.Public, + Token.Keywords.Modifiers.Static, + Token.PrimitiveType.Bool, + Token.Identifiers.MethodName("operatortrue"), + Token.Punctuation.OpenParen, + Token.PrimitiveType.Int, + Token.Identifiers.ParameterName("value"), + Token.Punctuation.CloseParen, + Token.Punctuation.OpenBrace, + Token.Keywords.Control.Return, + Token.Variables.ReadWrite("value"), + Token.Operators.Relational.NotEqual, + Token.Literals.Numeric.Decimal("0"), + Token.Punctuation.Semicolon, + Token.Punctuation.CloseBrace]); + }); + it("unary false", async () => { const input = Input.InClass(`public static int operator false(int value) { return value == 0; }`);