Skip to content

Commit

Permalink
Merge pull request #310 from dotnet/dev/jorobich/abstract-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich authored Dec 30, 2023
2 parents cf46bf7 + 7bd8767 commit 7a7482f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
8 changes: 8 additions & 0 deletions grammars/csharp.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>include</key>
<string>#storage-modifier</string>
</dict>
<dict>
<key>include</key>
<string>#property-declaration</string>
Expand All @@ -243,6 +247,10 @@
<key>include</key>
<string>#method-declaration</string>
</dict>
<dict>
<key>include</key>
<string>#operator-declaration</string>
</dict>
<dict>
<key>include</key>
<string>#attribute-section</string>
Expand Down
6 changes: 6 additions & 0 deletions grammars/csharp.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ repository:
{
include: "#comment"
}
{
include: "#storage-modifier"
}
{
include: "#property-declaration"
}
Expand All @@ -168,6 +171,9 @@ repository:
{
include: "#method-declaration"
}
{
include: "#operator-declaration"
}
{
include: "#attribute-section"
}
Expand Down
2 changes: 2 additions & 0 deletions src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ repository:
patterns:
- include: '#preprocessor'
- include: '#comment'
- include: '#storage-modifier'
- include: '#property-declaration'
- include: '#event-declaration'
- include: '#indexer-declaration'
- include: '#method-declaration'
- include: '#operator-declaration'
- include: '#attribute-section'
- include: '#punctuation-semicolon'

Expand Down
74 changes: 74 additions & 0 deletions test/interface.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,79 @@ interface IBar : IFoo { }
Token.Punctuation.OpenBrace,
Token.Punctuation.CloseBrace]);
});

it("generic interface with abstract methods (issue #307)", async () => {

const input = `
public interface IAdditionSubtraction<T> where T : IAdditionSubtraction<T>
{
public abstract static T operator -(T left, T right);
abstract static T operator +(T left, T right);
public abstract void M();
void N();
}`;
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.Keyword.Modifier.Public,
Token.Keyword.Definition.Interface,
Token.Identifier.InterfaceName("IAdditionSubtraction"),
Token.Punctuation.TypeParameter.Begin,
Token.Identifier.TypeParameterName("T"),
Token.Punctuation.TypeParameter.End,
Token.Keyword.Modifier.Where,
Token.Identifier.TypeParameterName("T"),
Token.Punctuation.Colon,
Token.Type("IAdditionSubtraction"),
Token.Punctuation.TypeParameter.Begin,
Token.Type("T"),
Token.Punctuation.TypeParameter.End,
Token.Punctuation.OpenBrace,

Token.Keyword.Modifier.Public,
Token.Keyword.Modifier.Abstract,
Token.Keyword.Modifier.Static,
Token.Type("T"),
Token.Keyword.Definition.Operator,
Token.Identifier.MethodName("-"),
Token.Punctuation.OpenParen,
Token.Type("T"),
Token.Identifier.ParameterName("left"),
Token.Punctuation.Comma,
Token.Type("T"),
Token.Identifier.ParameterName("right"),
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon,

Token.Keyword.Modifier.Abstract,
Token.Keyword.Modifier.Static,
Token.Type("T"),
Token.Keyword.Definition.Operator,
Token.Identifier.MethodName("+"),
Token.Punctuation.OpenParen,
Token.Type("T"),
Token.Identifier.ParameterName("left"),
Token.Punctuation.Comma,
Token.Type("T"),
Token.Identifier.ParameterName("right"),
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon,

Token.Keyword.Modifier.Public,
Token.Keyword.Modifier.Abstract,
Token.PrimitiveType.Void,
Token.Identifier.MethodName("M"),
Token.Punctuation.OpenParen,
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon,

Token.PrimitiveType.Void,
Token.Identifier.MethodName("N"),
Token.Punctuation.OpenParen,
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon,

Token.Punctuation.CloseBrace]);
});
});
});

0 comments on commit 7a7482f

Please sign in to comment.