Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event fields enhancement #266

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions grammars/csharp.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1898,8 +1898,8 @@
)\s+
)
(?<interface_name>\g<type_name>\s*\.\s*)?
(?<event_names>\g<identifier>(?:\s*,\s*\g<identifier>)*)\s*
(?=\{|;|//|/\*|$)</string>
(\g&lt;identifier&gt;)\s* # first event name
(?=\{|;|,|=|//|/\*|$)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -1933,19 +1933,8 @@
</dict>
<key>9</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>entity.name.variable.event.cs</string>
<key>match</key>
<string>@?[_[:alpha:]][_[:alnum:]]*</string>
</dict>
<dict>
<key>include</key>
<string>#punctuation-comma</string>
</dict>
</array>
<key>name</key>
<string>entity.name.variable.event.cs</string>
</dict>
</dict>
<key>end</key>
Expand All @@ -1960,10 +1949,41 @@
<key>include</key>
<string>#event-accessors</string>
</dict>
<dict>
<key>name</key>
<string>entity.name.variable.event.cs</string>
<key>match</key>
<string>@?[_[:alpha:]][_[:alnum:]]*</string>
</dict>
<dict>
<key>include</key>
<string>#punctuation-comma</string>
</dict>
<dict>
<key>begin</key>
<string>=</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.cs</string>
</dict>
</dict>
<key>end</key>
<string>(?&lt;=,)|(?=;)</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#expression</string>
</dict>
<dict>
<key>include</key>
<string>#punctuation-comma</string>
</dict>
</array>
</dict>
</array>
</dict>
<key>property-accessors</key>
Expand Down
33 changes: 22 additions & 11 deletions grammars/csharp.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -1226,8 +1226,8 @@ repository:
)\\s+
)
(?<interface_name>\\g<type_name>\\s*\\.\\s*)?
(?<event_names>\\g<identifier>(?:\\s*,\\s*\\g<identifier>)*)\\s*
(?=\\{|;|//|/\\*|$)
(\\g<identifier>)\\s* # first event name
(?=\\{|;|,|=|//|/\\*|$)
'''
beginCaptures:
"1":
Expand All @@ -1248,15 +1248,7 @@ repository:
}
]
"9":
patterns: [
{
name: "entity.name.variable.event.cs"
match: "@?[_[:alpha:]][_[:alnum:]]*"
}
{
include: "#punctuation-comma"
}
]
name: "entity.name.variable.event.cs"
end: "(?<=\\})|(?=;)"
patterns: [
{
Expand All @@ -1265,9 +1257,28 @@ repository:
{
include: "#event-accessors"
}
{
name: "entity.name.variable.event.cs"
match: "@?[_[:alpha:]][_[:alnum:]]*"
}
{
include: "#punctuation-comma"
}
{
begin: "="
beginCaptures:
"0":
name: "keyword.operator.assignment.cs"
end: "(?<=,)|(?=;)"
patterns: [
{
include: "#expression"
}
{
include: "#punctuation-comma"
}
]
}
]
"property-accessors":
begin: "\\{"
Expand Down
19 changes: 12 additions & 7 deletions src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,8 @@ repository:
)\s+
)
(?<interface_name>\g<type_name>\s*\.\s*)?
(?<event_names>\g<identifier>(?:\s*,\s*\g<identifier>)*)\s*
(?=\{|;|//|/\*|$)
(\g<identifier>)\s* # first event name
(?=\{|;|,|=|//|/\*|$)
beginCaptures:
'1': { name: keyword.other.event.cs }
'2':
Expand All @@ -706,16 +706,21 @@ repository:
patterns:
- include: '#type'
- include: '#punctuation-accessor'
'9':
patterns:
- name: entity.name.variable.event.cs
match: '@?[_[:alpha:]][_[:alnum:]]*'
- include: '#punctuation-comma'
'9': { name: entity.name.variable.event.cs }
end: (?<=\})|(?=;)
patterns:
- include: '#comment'
- include: '#event-accessors'
- name: entity.name.variable.event.cs
match: '@?[_[:alpha:]][_[:alnum:]]*'
- include: '#punctuation-comma'
- begin: '='
beginCaptures:
'0': { name: keyword.operator.assignment.cs }
end: (?<=,)|(?=;)
patterns:
- include: '#expression'
- include: '#punctuation-comma'

property-accessors:
begin: \{
Expand Down
45 changes: 45 additions & 0 deletions test/event.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,50 @@ event EventHandler Event // comment
Token.Punctuation.CloseBrace,
]);
});

it("declaration with default value (issue #118)", async () => {
const input = Input.InClass(`event EventHandler Event = null;`);
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.Keywords.Event,
Token.Type("EventHandler"),
Token.Identifiers.EventName("Event"),
Token.Operators.Assignment,
Token.Literals.Null,
Token.Punctuation.Semicolon,
]);
});

it("multiple declarations with default value (issue #118)", async () => {
const input = Input.InClass(`
event EventHandler Event1 = delegate { },
Event2 = () => { }
, Event3 = null;`);
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.Keywords.Event,
Token.Type("EventHandler"),
Token.Identifiers.EventName("Event1"),
Token.Operators.Assignment,
Token.Keywords.Delegate,
Token.Punctuation.OpenBrace,
Token.Punctuation.CloseBrace,
Token.Punctuation.Comma,
Token.Identifiers.EventName("Event2"),
Token.Operators.Assignment,
Token.Punctuation.OpenParen,
Token.Punctuation.CloseParen,
Token.Operators.Arrow,
Token.Punctuation.OpenBrace,
Token.Punctuation.CloseBrace,
Token.Punctuation.Comma,
Token.Identifiers.EventName("Event3"),
Token.Operators.Assignment,
Token.Literals.Null,
Token.Punctuation.Semicolon,
]);
});
});
});
Loading