Skip to content

Commit 0febdc7

Browse files
authored
Merge pull request #297 from dotnet/dev/jorobich/support-e-escape-sequence
Add support for \e escape sequences in c# strings and characters
2 parents 57e66c7 + 7bf5709 commit 0febdc7

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

grammars/csharp.tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6156,7 +6156,7 @@
61566156
<key>name</key>
61576157
<string>constant.character.escape.cs</string>
61586158
<key>match</key>
6159-
<string>\\(['"\\0abfnrtv]|x[0-9a-fA-F]{1,4}|u[0-9a-fA-F]{4})</string>
6159+
<string>\\(x[0-9a-fA-F]{1,4}|u[0-9a-fA-F]{4}|.)</string>
61606160
</dict>
61616161
<key>string-literal</key>
61626162
<dict>
@@ -6200,7 +6200,7 @@
62006200
<key>name</key>
62016201
<string>constant.character.escape.cs</string>
62026202
<key>match</key>
6203-
<string>\\(['"\\0abfnrtv]|x[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4})</string>
6203+
<string>\\(x[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|.)</string>
62046204
</dict>
62056205
<key>verbatim-string-literal</key>
62066206
<dict>

grammars/csharp.tmLanguage.cson

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3705,7 +3705,7 @@ repository:
37053705
]
37063706
"char-character-escape":
37073707
name: "constant.character.escape.cs"
3708-
match: "\\\\(['\"\\\\0abfnrtv]|x[0-9a-fA-F]{1,4}|u[0-9a-fA-F]{4})"
3708+
match: "\\\\(x[0-9a-fA-F]{1,4}|u[0-9a-fA-F]{4}|.)"
37093709
"string-literal":
37103710
name: "string.quoted.double.cs"
37113711
begin: "(?<!@)\""
@@ -3725,7 +3725,7 @@ repository:
37253725
]
37263726
"string-character-escape":
37273727
name: "constant.character.escape.cs"
3728-
match: "\\\\(['\"\\\\0abfnrtv]|x[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4})"
3728+
match: "\\\\(x[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|.)"
37293729
"verbatim-string-literal":
37303730
name: "string.quoted.double.cs"
37313731
begin: "@\""

src/csharp.tmLanguage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,7 @@ repository:
23142314

23152315
char-character-escape:
23162316
name: constant.character.escape.cs
2317-
match: \\(['"\\0abfnrtv]|x[0-9a-fA-F]{1,4}|u[0-9a-fA-F]{4})
2317+
match: \\(x[0-9a-fA-F]{1,4}|u[0-9a-fA-F]{4}|.)
23182318

23192319
string-literal:
23202320
name: string.quoted.double.cs
@@ -2330,7 +2330,7 @@ repository:
23302330

23312331
string-character-escape:
23322332
name: constant.character.escape.cs
2333-
match: \\(['"\\0abfnrtv]|x[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4})
2333+
match: \\(x[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|.)
23342334

23352335
verbatim-string-literal:
23362336
name: string.quoted.double.cs

test/literals.tests.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ describe("Literals", () => {
7878
Token.Punctuation.Semicolon]);
7979
});
8080

81+
it("escaped character escape \\e", async () => {
82+
const input = Input.InClass(`char x = '\\e';`);
83+
const tokens = await tokenize(input);
84+
85+
tokens.should.deep.equal([
86+
Token.PrimitiveType.Char,
87+
Token.Identifier.FieldName("x"),
88+
Token.Operator.Assignment,
89+
Token.Punctuation.Char.Begin,
90+
Token.Literal.CharacterEscape("\\e"),
91+
Token.Punctuation.Char.End,
92+
Token.Punctuation.Semicolon]);
93+
});
94+
8195
it("escaped character escape \\t", async () => {
8296
const input = Input.InClass(`char x = '\\t';`);
8397
const tokens = await tokenize(input);
@@ -712,6 +726,22 @@ describe("Literals", () => {
712726
Token.Punctuation.Semicolon]);
713727
});
714728

729+
it("escaped character escape \\e", async () => {
730+
const input = Input.InClass(`string test = "hello\\eworld!";`);
731+
const tokens = await tokenize(input);
732+
733+
tokens.should.deep.equal([
734+
Token.PrimitiveType.String,
735+
Token.Identifier.FieldName("test"),
736+
Token.Operator.Assignment,
737+
Token.Punctuation.String.Begin,
738+
Token.Literal.String("hello"),
739+
Token.Literal.CharacterEscape("\\e"),
740+
Token.Literal.String("world!"),
741+
Token.Punctuation.String.End,
742+
Token.Punctuation.Semicolon]);
743+
});
744+
715745
it("escaped character escape \\n", async () => {
716746
const input = Input.InClass(`string test = "hello\\nworld!";`);
717747
const tokens = await tokenize(input);

0 commit comments

Comments
 (0)