Skip to content

Commit

Permalink
Add with expression
Browse files Browse the repository at this point in the history
  • Loading branch information
wise0704 committed Aug 1, 2023
1 parent 7d29a39 commit 5757be9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions grammars/csharp.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@
<key>include</key>
<string>#switch-expression</string>
</dict>
<dict>
<key>include</key>
<string>#with-expression</string>
</dict>
<dict>
<key>include</key>
<string>#conditional-operator</string>
Expand Down Expand Up @@ -3017,6 +3021,28 @@
</dict>
</array>
</dict>
<key>with-expression</key>
<dict>
<key>begin</key>
<string>(?&lt;!\.)\b(with)\b\s*(?=\{|$)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.other.with.cs</string>
</dict>
</dict>
<key>end</key>
<string>(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#initializer-expression</string>
</dict>
</array>
</dict>
<key>switch-pattern</key>
<dict>
<key>begin</key>
Expand Down
14 changes: 14 additions & 0 deletions grammars/csharp.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ repository:
{
include: "#switch-expression"
}
{
include: "#with-expression"
}
{
include: "#conditional-operator"
}
Expand Down Expand Up @@ -1884,6 +1887,17 @@ repository:
]
}
]
"with-expression":
begin: "(?<!\\.)\\b(with)\\b\\s*(?=\\{|$)"
beginCaptures:
"1":
name: "keyword.other.with.cs"
end: "(?<=\\})"
patterns: [
{
include: "#initializer-expression"
}
]
"switch-pattern":
begin: '''
(?x) # e.g. int x OR var x
Expand Down
9 changes: 9 additions & 0 deletions src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ repository:
- include: '#type-builtin'
- include: '#this-or-base-expression'
- include: '#switch-expression'
- include: '#with-expression'
- include: '#conditional-operator'
- include: '#expression-operators'
- include: '#await-expression'
Expand Down Expand Up @@ -1120,6 +1121,14 @@ repository:
- include: '#expression-body'
- include: '#punctuation-comma'

with-expression:
begin: (?<!\.)\b(with)\b\s*(?=\{|$)
beginCaptures:
'1': { name: keyword.other.with.cs }
end: (?<=\})
patterns:
- include: '#initializer-expression'

switch-pattern:
begin: |-
(?x) # e.g. int x OR var x
Expand Down

0 comments on commit 5757be9

Please sign in to comment.