Skip to content

Commit

Permalink
Fix invalid true/false operators
Browse files Browse the repository at this point in the history
  • Loading branch information
wise0704 committed Aug 1, 2023
1 parent 0da4fc7 commit 17ba4a2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion grammars/csharp.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,7 @@
)*
)
)\s*
(?<operator_keyword>\boperator)\s*
(?<operator_keyword>\boperator\b)\s*
(?<operator>[+\-*/%&|\^!=~<>]+|true|false)\s*
(?=\()</string>
<key>beginCaptures</key>
Expand Down
2 changes: 1 addition & 1 deletion grammars/csharp.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ repository:
)*
)
)\\s*
(?<operator_keyword>\\boperator)\\s*
(?<operator_keyword>\\boperator\\b)\\s*
(?<operator>[+\\-*/%&|\\^!=~<>]+|true|false)\\s*
(?=\\()
'''
Expand Down
2 changes: 1 addition & 1 deletion src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ repository:
)*
)
)\s*
(?<operator_keyword>\boperator)\s*
(?<operator_keyword>\boperator\b)\s*
(?<operator>[+\-*/%&|\^!=~<>]+|true|false)\s*
(?=\()
beginCaptures:
Expand Down
23 changes: 22 additions & 1 deletion test/operator.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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; }`);
Expand Down

0 comments on commit 17ba4a2

Please sign in to comment.