From ae983fedef094656c5823be860f1cd1675dc2477 Mon Sep 17 00:00:00 2001 From: Daniel Jeong Date: Fri, 25 Aug 2023 07:23:18 +0000 Subject: [PATCH] Allow operators in constant pattern --- grammars/csharp.tmLanguage | 30 ++++++++++++++++++++---------- grammars/csharp.tmLanguage.cson | 22 ++++++++++++++-------- src/csharp.tmLanguage.yml | 16 ++++++++++------ 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/grammars/csharp.tmLanguage b/grammars/csharp.tmLanguage index 6ab5d4e..66363ca 100644 --- a/grammars/csharp.tmLanguage +++ b/grammars/csharp.tmLanguage @@ -3428,6 +3428,10 @@ include #nameof-expression + + include + #expression-operators + relational-pattern @@ -6243,16 +6247,16 @@ assignment-expression begin - (\*=|/=|%=|\+=|-=|\?\?=|\&=|\^=|<<=|>>>?=|\|=|=)(?!=|>) + (?:\*|/|%|\+|-|\?\?|\&|\^|<<|>>>?|\|)?=(?!=|>) beginCaptures - 1 + 0 patterns include - #expression-operators + #assignment-operators @@ -6271,7 +6275,7 @@ - expression-operators + assignment-operators patterns @@ -6287,6 +6291,18 @@ match \&=|\^=|<<=|>>>?=|\|= + + name + keyword.operator.assignment.cs + match + \= + + + + expression-operators + + patterns + name keyword.operator.bitwise.shift.cs @@ -6317,12 +6333,6 @@ match \&|~|\^|\| - - name - keyword.operator.assignment.cs - match - \= - name keyword.operator.decrement.cs diff --git a/grammars/csharp.tmLanguage.cson b/grammars/csharp.tmLanguage.cson index 8cb546f..6a005ef 100644 --- a/grammars/csharp.tmLanguage.cson +++ b/grammars/csharp.tmLanguage.cson @@ -2122,6 +2122,9 @@ repository: { include: "#nameof-expression" } + { + include: "#expression-operators" + } ] "relational-pattern": begin: "<=?|>=?" @@ -3713,12 +3716,12 @@ repository: "0": name: "punctuation.separator.colon.cs" "assignment-expression": - begin: "(\\*=|/=|%=|\\+=|-=|\\?\\?=|\\&=|\\^=|<<=|>>>?=|\\|=|=)(?!=|>)" + begin: "(?:\\*|/|%|\\+|-|\\?\\?|\\&|\\^|<<|>>>?|\\|)?=(?!=|>)" beginCaptures: - "1": + "0": patterns: [ { - include: "#expression-operators" + include: "#assignment-operators" } ] end: "(?=[,\\)\\];}])" @@ -3730,7 +3733,7 @@ repository: include: "#expression" } ] - "expression-operators": + "assignment-operators": patterns: [ { name: "keyword.operator.assignment.compound.cs" @@ -3740,6 +3743,13 @@ repository: name: "keyword.operator.assignment.compound.bitwise.cs" match: "\\&=|\\^=|<<=|>>>?=|\\|=" } + { + name: "keyword.operator.assignment.cs" + match: "\\=" + } + ] + "expression-operators": + patterns: [ { name: "keyword.operator.bitwise.shift.cs" match: "<<|>>>?" @@ -3760,10 +3770,6 @@ repository: name: "keyword.operator.bitwise.cs" match: "\\&|~|\\^|\\|" } - { - name: "keyword.operator.assignment.cs" - match: "\\=" - } { name: "keyword.operator.decrement.cs" match: "--" diff --git a/src/csharp.tmLanguage.yml b/src/csharp.tmLanguage.yml index abf3407..fb2a866 100644 --- a/src/csharp.tmLanguage.yml +++ b/src/csharp.tmLanguage.yml @@ -1254,6 +1254,7 @@ repository: - include: '#verbatim-string-literal' - include: '#typeof-or-default-expression' - include: '#nameof-expression' + - include: '#expression-operators' relational-pattern: begin: <=?|>=? @@ -2352,22 +2353,27 @@ repository: '0': { name: punctuation.separator.colon.cs } assignment-expression: - begin: (\*=|/=|%=|\+=|-=|\?\?=|\&=|\^=|<<=|>>>?=|\|=|=)(?!=|>) + begin: (?:\*|/|%|\+|-|\?\?|\&|\^|<<|>>>?|\|)?=(?!=|>) beginCaptures: - 1: + 0: patterns: - - include: '#expression-operators' + - include: '#assignment-operators' end: (?=[,\)\];}]) patterns: - include: '#ref-modifier' - include: '#expression' - expression-operators: + assignment-operators: patterns: - name: keyword.operator.assignment.compound.cs match: \*=|/=|%=|\+=|-=|\?\?= - name: keyword.operator.assignment.compound.bitwise.cs match: \&=|\^=|<<=|>>>?=|\|= + - name: keyword.operator.assignment.cs + match: \= + + expression-operators: + patterns: - name: keyword.operator.bitwise.shift.cs match: <<|>>>? - name: keyword.operator.comparison.cs @@ -2378,8 +2384,6 @@ repository: match: \!|&&|\|\| - name: keyword.operator.bitwise.cs match: \&|~|\^|\| - - name: keyword.operator.assignment.cs - match: \= - name: keyword.operator.decrement.cs match: -- - name: keyword.operator.increment.cs