Skip to content

Commit

Permalink
Fix #1078 and add regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinCampbell committed Jan 7, 2017
1 parent d161564 commit 1ab9c08
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
21 changes: 20 additions & 1 deletion syntaxes/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ repository:
expression:
patterns:
- include: '#checked-unchecked-expression'
- include: '#typeof-expression'
- include: '#interpolated-string'
- include: '#verbatim-interpolated-string'
- include: '#literal'
- include: '#this-or-base-expression'
- include: '#expression-operators'
- include: '#cast-expression'
- include: '#object-creation-expression'
Expand Down Expand Up @@ -1174,6 +1176,17 @@ repository:
patterns:
- include: '#expression'

typeof-expression:
begin: (?<!\.)\b(typeof)\b\s*(\()
beginCaptures:
'1': { name: keyword.other.typeof.cs }
'2': { name: punctuation.parenthesis.open.cs }
end: \)
endCaptures:
'0': { name: punctuation.parenthesis.close.cs }
patterns:
- include: '#type'

interpolated-string:
name: string.quoted.double.cs
begin: '\$"'
Expand Down Expand Up @@ -1327,6 +1340,12 @@ repository:
patterns:
- include: '#type'

this-or-base-expression:
match: \b(?:(base)|(this))\b
captures:
'1': { name: keyword.other.base.cs }
'2': { name: keyword.other.this.cs }

invocation-expression:
begin: |-
(?x)
Expand Down Expand Up @@ -1371,7 +1390,7 @@ repository:

member-access-expression:
patterns:
- match: (\.)\s*([_$[:alpha:]][_$[:alnum:]]*)(?=(\s*\.\s*[_$[:alpha:]][_$[:alnum:]]*)|\))
- match: (\.)\s*([_$[:alpha:]][_$[:alnum:]]*)(?=(\s*((\.\s*[_$[:alpha:]][_$[:alnum:]]*)|([^_$[:alnum:]\(\[\<]))))
captures:
'1': { name: punctuation.accessor.cs }
'2': { name: variable.other.object.property.cs }
Expand Down
81 changes: 81 additions & 0 deletions test/syntaxes/string-literals.test.syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,86 @@ world!";`);
Token.Punctuation.String.End,
Token.Punctuation.Semicolon]);
});

it("highlight escaped double-quote properly (issue #1078 - repro 1)", () => {

const input = Input.InMethod(
`configContent = rgx.Replace(configContent, $"name{suffix}\\"");
File.WriteAllText(_testConfigFile, configContent);`);
const tokens = tokenize(input);

tokens.should.deep.equal([
Token.Variables.ReadWrite("configContent"),
Token.Operators.Assignment,
Token.Variables.Object('rgx'),
Token.Punctuation.Accessor,
Token.Identifiers.MethodName("Replace"),
Token.Punctuation.OpenParen,
Token.Variables.ReadWrite("configContent"),
Token.Punctuation.Comma,
Token.Punctuation.InterpolatedString.Begin,
Token.Literals.String("name"),
Token.Punctuation.Interpolation.Begin,
Token.Variables.ReadWrite("suffix"),
Token.Punctuation.Interpolation.End,
Token.Literals.CharacterEscape("\\\""),
Token.Punctuation.String.End,
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon,
Token.Variables.Object("File"),
Token.Punctuation.Accessor,
Token.Identifiers.MethodName("WriteAllText"),
Token.Punctuation.OpenParen,
Token.Variables.ReadWrite("_testConfigFile"),
Token.Punctuation.Comma,
Token.Variables.ReadWrite("configContent"),
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon
]);
});

it("highlight escaped double-quote properly (issue #1078 - repro 2)", () => {

const input = Input.InMethod(
`throw new InvalidCastException(
$"The value \\"{this.Value} is of the type \\"{this.Type}\\". You asked for \\"{typeof(T)}\\".");`);
const tokens = tokenize(input);

tokens.should.deep.equal([
Token.Keywords.Throw,
Token.Keywords.New,
Token.Type("InvalidCastException"),
Token.Punctuation.OpenParen,
Token.Punctuation.InterpolatedString.Begin,
Token.Literals.String("The value "),
Token.Literals.CharacterEscape("\\\""),
Token.Punctuation.Interpolation.Begin,
Token.Keywords.This,
Token.Punctuation.Accessor,
Token.Variables.Property("Value"),
Token.Punctuation.Interpolation.End,
Token.Literals.String(" is of the type "),
Token.Literals.CharacterEscape("\\\""),
Token.Punctuation.Interpolation.Begin,
Token.Keywords.This,
Token.Punctuation.Accessor,
Token.Variables.Property("Type"),
Token.Punctuation.Interpolation.End,
Token.Literals.CharacterEscape("\\\""),
Token.Literals.String(". You asked for "),
Token.Literals.CharacterEscape("\\\""),
Token.Punctuation.Interpolation.Begin,
Token.Keywords.TypeOf,
Token.Punctuation.OpenParen,
Token.Type("T"),
Token.Punctuation.CloseParen,
Token.Punctuation.Interpolation.End,
Token.Literals.CharacterEscape("\\\""),
Token.Literals.String("."),
Token.Punctuation.InterpolatedString.End,
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon
]);
});
});
});
1 change: 1 addition & 0 deletions test/syntaxes/utils/tokenize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export namespace Token {
export const This = createToken('this', 'keyword.other.this.cs');
export const Throw = createToken('throw', 'keyword.control.flow.throw.cs');
export const Try = createToken('try', 'keyword.control.try.cs');
export const TypeOf = createToken('typeof', 'keyword.other.typeof.cs');
export const Unchecked = createToken('unchecked', 'keyword.other.unchecked.cs');
export const Using = createToken('using', 'keyword.other.using.cs');
export const When = createToken('when', 'keyword.control.try.when.cs');
Expand Down

0 comments on commit 1ab9c08

Please sign in to comment.