Skip to content

Add support for 'in' parameters #113

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

Merged
merged 1 commit into from
May 2, 2018
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
6 changes: 3 additions & 3 deletions grammars/csharp.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -5117,7 +5117,7 @@
<dict>
<key>match</key>
<string>(?x)
(?:(?:\b(ref|params|out|this)\b)\s+)?
(?:(?:\b(ref|params|out|in|this)\b)\s+)?
(?&lt;type-name&gt;
(?:
(?:ref\s+)? # ref return
Expand Down Expand Up @@ -5270,7 +5270,7 @@
<key>name</key>
<string>storage.modifier.cs</string>
<key>match</key>
<string>\b(ref|out)\b</string>
<string>\b(ref|out|in)\b</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -5886,7 +5886,7 @@
<dict>
<key>match</key>
<string>(?x)
(ref|out)?\s*
(?:\b(ref|out|in)\b)?\s*
(?&lt;type-name&gt;
(?:
(?:
Expand Down
6 changes: 3 additions & 3 deletions grammars/csharp.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,7 @@ repository:
parameter:
match: '''
(?x)
(?:(?:\\b(ref|params|out|this)\\b)\\s+)?
(?:(?:\\b(ref|params|out|in|this)\\b)\\s+)?
(?<type-name>
(?:
(?:ref\\s+)? # ref return
Expand Down Expand Up @@ -3182,7 +3182,7 @@ repository:
patterns: [
{
name: "storage.modifier.cs"
match: "\\b(ref|out)\\b"
match: "\\b(ref|out|in)\\b"
}
{
include: "#declaration-expression-local"
Expand Down Expand Up @@ -3558,7 +3558,7 @@ repository:
"lambda-parameter":
match: '''
(?x)
(ref|out)?\\s*
(?:\\b(ref|out|in)\\b)?\\s*
(?<type-name>
(?:
(?:
Expand Down
6 changes: 3 additions & 3 deletions src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,7 @@ repository:
parameter:
match: |-
(?x)
(?:(?:\b(ref|params|out|this)\b)\s+)?
(?:(?:\b(ref|params|out|in|this)\b)\s+)?
(?<type-name>
(?:
(?:ref\s+)? # ref return
Expand Down Expand Up @@ -2069,7 +2069,7 @@ repository:
argument:
patterns:
- name: storage.modifier.cs
match: \b(ref|out)\b
match: \b(ref|out|in)\b
- include: '#declaration-expression-local'
- include: '#expression'

Expand Down Expand Up @@ -2316,7 +2316,7 @@ repository:
lambda-parameter:
match: |-
(?x)
(ref|out)?\s*
(?:\b(ref|out|in)\b)?\s*
(?<type-name>
(?:
(?:
Expand Down
126 changes: 126 additions & 0 deletions test/expressions.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,25 @@ var newPoint = new Vector(point.x * z, 0);`);
]);
});

it("lambda expression with in parameter - in int", () => {
const input = Input.InMethod(`M((in int x) => x);`);
const tokens = tokenize(input);

tokens.should.deep.equal([
Token.Identifiers.MethodName("M"),
Token.Punctuation.OpenParen,
Token.Punctuation.OpenParen,
Token.Keywords.Modifiers.In,
Token.PrimitiveType.Int,
Token.Identifiers.ParameterName("x"),
Token.Punctuation.CloseParen,
Token.Operators.Arrow,
Token.Variables.ReadWrite("x"),
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon
]);
})

it("anonymous method with no parameter list (passed as argument)", () => {
const input = Input.InMethod(`M(delegate { });`);
const tokens = tokenize(input);
Expand Down Expand Up @@ -1585,6 +1604,23 @@ var result = list.Select(l => new {
]);
});

it("in argument", () => {
const input = Input.InMethod(`var o = P[in x];`);
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.Keywords.Modifiers.In,
Token.Variables.ReadWrite("x"),
Token.Punctuation.CloseBracket,
Token.Punctuation.Semicolon
]);
});

it("named ref argument", () => {
const input = Input.InMethod(`var o = P[x: ref y];`);
const tokens = tokenize(input);
Expand Down Expand Up @@ -1623,6 +1659,25 @@ var result = list.Select(l => new {
]);
});

it("named in argument", () => {
const input = Input.InMethod(`var o = P[x: in 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.In,
Token.Variables.ReadWrite("y"),
Token.Punctuation.CloseBracket,
Token.Punctuation.Semicolon
]);
});

it("out argument declaration", () => {
const input = Input.InMethod(`var o = P[out int x, out var y];`);
const tokens = tokenize(input);
Expand All @@ -1645,6 +1700,28 @@ var result = list.Select(l => new {
]);
});

it("in argument declaration", () => {
const input = Input.InMethod(`var o = P[in int x, in var 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.Keywords.Modifiers.In,
Token.PrimitiveType.Int,
Token.Identifiers.LocalName("x"),
Token.Punctuation.Comma,
Token.Keywords.Modifiers.In,
Token.Keywords.Var,
Token.Identifiers.LocalName("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 @@ -2074,6 +2151,20 @@ long total = (data["bonusGame"]["win"].AsLong) * data["bonusGame"]["betMult"].As
]);
});

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

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

it("named ref argument", () => {
const input = Input.InMethod(`M(x: ref y);`);
const tokens = tokenize(input);
Expand Down Expand Up @@ -2106,6 +2197,22 @@ long total = (data["bonusGame"]["win"].AsLong) * data["bonusGame"]["betMult"].As
]);
});

it("named in argument", () => {
const input = Input.InMethod(`M(x: in 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.In,
Token.Variables.ReadWrite("y"),
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon
]);
});

it("out argument declaration", () => {
const input = Input.InMethod(`M(out int x, out var y);`);
const tokens = tokenize(input);
Expand All @@ -2125,6 +2232,25 @@ long total = (data["bonusGame"]["win"].AsLong) * data["bonusGame"]["betMult"].As
]);
});

it("in argument declaration", () => {
const input = Input.InMethod(`M(in int x, in var y);`);
const tokens = tokenize(input);

tokens.should.deep.equal([
Token.Identifiers.MethodName("M"),
Token.Punctuation.OpenParen,
Token.Keywords.Modifiers.In,
Token.PrimitiveType.Int,
Token.Identifiers.LocalName("x"),
Token.Punctuation.Comma,
Token.Keywords.Modifiers.In,
Token.Keywords.Var,
Token.Identifiers.LocalName("y"),
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon
]);
});

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