Skip to content

Commit

Permalink
Merge pull request #272 from wise0704/comment
Browse files Browse the repository at this point in the history
Allow comment in switch statement
  • Loading branch information
JoeRobich authored Aug 8, 2023
2 parents a99ed13 + 6189489 commit 3d5703b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions grammars/csharp.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,10 @@
<string>(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>begin</key>
<string>\(</string>
Expand Down
3 changes: 3 additions & 0 deletions grammars/csharp.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,9 @@ repository:
name: "keyword.control.switch.cs"
end: "(?<=\\})"
patterns: [
{
include: "#comment"
}
{
begin: "\\("
beginCaptures:
Expand Down
1 change: 1 addition & 0 deletions src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ repository:
'1': { name: keyword.control.switch.cs }
end: (?<=\})
patterns:
- include: '#comment'
- begin: \(
beginCaptures:
'0': { name: punctuation.parenthesis.open.cs }
Expand Down
25 changes: 25 additions & 0 deletions test/statements.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,31 @@ switch (i) {
Token.Punctuation.CloseBrace
]);
});

it("switch statement with comment (issue #145)", async () => {
const input = Input.InMethod(`
switch (i) /* comment */ {
default:
break;
}`);
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.Keywords.Control.Switch,
Token.Punctuation.OpenParen,
Token.Variables.ReadWrite("i"),
Token.Punctuation.CloseParen,
Token.Comment.MultiLine.Start,
Token.Comment.MultiLine.Text(" comment "),
Token.Comment.MultiLine.End,
Token.Punctuation.OpenBrace,
Token.Keywords.Control.Default,
Token.Punctuation.Colon,
Token.Keywords.Control.Break,
Token.Punctuation.Semicolon,
Token.Punctuation.CloseBrace
]);
});
});

describe("Try", () => {
Expand Down

0 comments on commit 3d5703b

Please sign in to comment.