Skip to content

Commit

Permalink
Working on parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed May 16, 2016
1 parent 65dad7b commit 33e78bd
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6844,10 +6844,10 @@ private bool IsPossibleLocalDeclarationStatement(bool allowAnyExpression)
}

// deconstruction-assignment
if (tk == SyntaxKind.OpenParenToken)
{
return false;
}
//if (tk == SyntaxKind.OpenParenToken)
//{
// return false;
//}

bool? typedIdentifier = IsPossibleTypedIdentifierStart(this.CurrentToken, this.PeekToken(1), allowThisKeyword: false);
if (typedIdentifier != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="Parsing\AwaitParsingTests.cs" />
<Compile Include="Parsing\CrefParsingTests.cs" />
<Compile Include="Parsing\DeclarationParsingTests.cs" />
<Compile Include="Parsing\Deconstruction.cs" />
<Compile Include="Parsing\ExpressionParsingTests.cs" />
<Compile Include="Parsing\LocalFunctionParsingTests.cs" />
<Compile Include="Parsing\ParserRegressionTests.cs" />
Expand Down
109 changes: 109 additions & 0 deletions src/Compilers/CSharp/Test/Syntax/Parsing/Deconstruction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Parsing
{
// (T id, ...) = is a deconstruction-declaration

// (T, ...) id
// and (T, ...) [] are types
// (E, ...) = is a deconstruction-assignment
// (E, ...) folowed by ., +, -, etc is an expression

public class DeconstructionTests : ParsingTests
{
protected override SyntaxTree ParseTree(string text, CSharpParseOptions options)
{
return SyntaxFactory.ParseSyntaxTree(text, options: options);
}

[Fact]
public void TupleType()
{
// (T id, ...) id is a tuple type

var tree = UsingTree(@"
class C
{
void Foo()
{
(Int32 a, Int64 b) x;
}
}", options: TestOptions.Regular.WithTuplesFeature());
N(SyntaxKind.CompilationUnit);
{
N(SyntaxKind.ClassDeclaration);
{
N(SyntaxKind.ClassKeyword);
N(SyntaxKind.IdentifierToken);
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.MethodDeclaration);
{
N(SyntaxKind.TupleType);
{
N(SyntaxKind.OpenParenToken);
N(SyntaxKind.TupleElement);
{
N(SyntaxKind.PredefinedType);
{
N(SyntaxKind.IntKeyword);
}
}
N(SyntaxKind.CommaToken);
N(SyntaxKind.TupleElement);
{
N(SyntaxKind.PredefinedType);
{
N(SyntaxKind.StringKeyword);
}
}
N(SyntaxKind.CloseParenToken);
}
N(SyntaxKind.IdentifierToken);
N(SyntaxKind.ParameterList);
{
N(SyntaxKind.OpenParenToken);
N(SyntaxKind.CloseParenToken);
}
N(SyntaxKind.Block);
{
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.ReturnStatement);
{
N(SyntaxKind.ReturnKeyword);
N(SyntaxKind.TupleExpression);
{
N(SyntaxKind.OpenParenToken);
N(SyntaxKind.Argument);
{
N(SyntaxKind.NumericLiteralExpression);
{
N(SyntaxKind.NumericLiteralToken);
}
}
N(SyntaxKind.CommaToken);
N(SyntaxKind.Argument);
{
N(SyntaxKind.StringLiteralExpression);
{
N(SyntaxKind.StringLiteralToken);
}
}
N(SyntaxKind.CloseParenToken);
}
N(SyntaxKind.SemicolonToken);
}
N(SyntaxKind.CloseBraceToken);
}
}
N(SyntaxKind.CloseBraceToken);
}
N(SyntaxKind.EndOfFileToken);
}
EOF();
}
}
}
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Test/Syntax/Parsing/ParsingTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#define PARSING_TESTS_DUMP

using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class C
EOF();
}


[Fact]
public void LongTuple()
{
Expand Down

0 comments on commit 33e78bd

Please sign in to comment.