Skip to content

Commit

Permalink
Merge pull request microsoft#49 from kiootic/named-ref-out
Browse files Browse the repository at this point in the history
Add support for named ref/out arguments
  • Loading branch information
DustinCampbell authored Mar 25, 2017
2 parents 9b02ada + c888852 commit 4d0e50c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
2 changes: 1 addition & 1 deletion grammars/csharp.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -5094,7 +5094,7 @@
<array>
<dict>
<key>include</key>
<string>#expression</string>
<string>#argument</string>
</dict>
</array>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion grammars/csharp.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -3053,7 +3053,7 @@ repository:
end: "(?=(,|\\)|\\]))"
patterns: [
{
include: "#expression"
include: "#argument"
}
]
argument:
Expand Down
2 changes: 1 addition & 1 deletion src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,7 @@ repository:
'2': { name: punctuation.separator.colon.cs }
end: (?=(,|\)|\]))
patterns:
- include: '#expression'
- include: '#argument'

argument:
patterns:
Expand Down
70 changes: 70 additions & 0 deletions test/expressions.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,44 @@ class C
]);
});

it("named ref argument", () => {
const input = Input.InMethod(`var o = P[x: ref y];`);
const tokens = tokenize(input);

tokens.should.deep.equal([
Token.Keywords.Var,
Token.Identifiers.LocalName("o"),
Token.Operators.Assignment,
Token.Variables.Property("P"),
Token.Punctuation.OpenBracket,
Token.Identifiers.ParameterName("x"),
Token.Punctuation.Colon,
Token.Keywords.Modifiers.Ref,
Token.Variables.ReadWrite("y"),
Token.Punctuation.CloseBracket,
Token.Punctuation.Semicolon
]);
});

it("named out argument", () => {
const input = Input.InMethod(`var o = P[x: out y];`);
const tokens = tokenize(input);

tokens.should.deep.equal([
Token.Keywords.Var,
Token.Identifiers.LocalName("o"),
Token.Operators.Assignment,
Token.Variables.Property("P"),
Token.Punctuation.OpenBracket,
Token.Identifiers.ParameterName("x"),
Token.Punctuation.Colon,
Token.Keywords.Modifiers.Out,
Token.Variables.ReadWrite("y"),
Token.Punctuation.CloseBracket,
Token.Punctuation.Semicolon
]);
});

it("member of generic with no arguments", () => {
const input = Input.InMethod(`var o = C<int>.P[];`);
const tokens = tokenize(input);
Expand Down Expand Up @@ -1758,6 +1796,38 @@ long total = (data["bonusGame"]["win"].AsLong) * data["bonusGame"]["betMult"].As
]);
});

it("named ref argument", () => {
const input = Input.InMethod(`M(x: ref y);`);
const tokens = tokenize(input);

tokens.should.deep.equal([
Token.Identifiers.MethodName("M"),
Token.Punctuation.OpenParen,
Token.Identifiers.ParameterName("x"),
Token.Punctuation.Colon,
Token.Keywords.Modifiers.Ref,
Token.Variables.ReadWrite("y"),
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon
]);
});

it("named out argument", () => {
const input = Input.InMethod(`M(x: out y);`);
const tokens = tokenize(input);

tokens.should.deep.equal([
Token.Identifiers.MethodName("M"),
Token.Punctuation.OpenParen,
Token.Identifiers.ParameterName("x"),
Token.Punctuation.Colon,
Token.Keywords.Modifiers.Out,
Token.Variables.ReadWrite("y"),
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon
]);
});

it("generic with no arguments", () => {
const input = Input.InMethod(`M<int>();`);
const tokens = tokenize(input);
Expand Down

0 comments on commit 4d0e50c

Please sign in to comment.