From 15ce180b8c128fd9dcbccf309fccb76b9dad0ad5 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 26 Nov 2018 15:05:20 +0100 Subject: [PATCH] Allow assigning comment info to all variables --- Upsilon/Binder/Binder.cs | 8 +++++--- Upsilon/Parser/Parser.cs | 13 ++++++++++++- .../StatementSyntax/AssignmentStatementSyntax.cs | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Upsilon/Binder/Binder.cs b/Upsilon/Binder/Binder.cs index 0ef1a3f..ca60837 100644 --- a/Upsilon/Binder/Binder.cs +++ b/Upsilon/Binder/Binder.cs @@ -249,7 +249,7 @@ namespace Upsilon.Binder return new BoundExpressionStatement(exp, s.Span); } - private VariableSymbol TryBindVariable(string name, bool isLocal, BoundExpression assignment) + private VariableSymbol TryBindVariable(string name, bool isLocal, BoundExpression assignment, string[] commentData) { if (name == "_") return null; @@ -265,6 +265,8 @@ namespace Upsilon.Binder variable = new VariableSymbol(name, assignment.Type, isLocal); } + variable.CommentValue = commentData; + if (isLocal) Scope.DefineLocalVariable(variable); else @@ -309,7 +311,7 @@ namespace Upsilon.Binder var boundExpression = BindExpression(e.Expression); var isLocal = e.LocalToken != null; - var boundVariable = TryBindVariable(name, isLocal, boundExpression); + var boundVariable = TryBindVariable(name, isLocal, boundExpression, e.CommentData); if (boundVariable != null) { var variable = new BoundVariableSymbol(boundVariable, variableExpression.Span); @@ -329,7 +331,7 @@ namespace Upsilon.Binder foreach (var identifierToken in s.Identifiers) { - var boundVariable = TryBindVariable(identifierToken.Name, isLocal, assignment); + var boundVariable = TryBindVariable(identifierToken.Name, isLocal, assignment, null); ls.Add(boundVariable); } return new BoundMultiAssignmentStatement(ls.ToImmutableArray(), assignment, s.Span); diff --git a/Upsilon/Parser/Parser.cs b/Upsilon/Parser/Parser.cs index 425a8c5..bbec5c1 100644 --- a/Upsilon/Parser/Parser.cs +++ b/Upsilon/Parser/Parser.cs @@ -324,13 +324,21 @@ namespace Upsilon.Parser private StatementSyntax ParseAssignmentExpression() { + string[] commentData = null; SyntaxToken localKeyword = null; if (Current.Kind == SyntaxKind.LocalKeyword) { localKeyword = MatchToken(SyntaxKind.LocalKeyword); + commentData = localKeyword.CommentData; } var identifier = ParseExpression(); + if (commentData == null && identifier.Kind == SyntaxKind.VariableExpression) + { + var variable = (VariableExpressionSyntax)identifier; + commentData = variable.Identifier.CommentData; + } + if (Current.Kind == SyntaxKind.Comma) { if (identifier.Kind != SyntaxKind.VariableExpression) @@ -352,7 +360,10 @@ namespace Upsilon.Parser var assignmentToken = MatchToken(SyntaxKind.Equals); var expression = ParseExpression(); - return new AssignmentStatementSyntax(localKeyword, identifier, assignmentToken, expression); + return new AssignmentStatementSyntax(localKeyword, identifier, assignmentToken, expression) + { + CommentData = commentData + }; } private StatementSyntax ParseTableAssignmentExpression(ExpressionSyntax tableExpression) diff --git a/Upsilon/Parser/StatementSyntax/AssignmentStatementSyntax.cs b/Upsilon/Parser/StatementSyntax/AssignmentStatementSyntax.cs index 3446e39..ca97cb2 100644 --- a/Upsilon/Parser/StatementSyntax/AssignmentStatementSyntax.cs +++ b/Upsilon/Parser/StatementSyntax/AssignmentStatementSyntax.cs @@ -22,6 +22,7 @@ namespace Upsilon.Parser public ExpressionSyntax Identifier { get; } public SyntaxToken EqualsToken { get; } public ExpressionSyntax Expression { get; } + public string[] CommentData { get; set; } public override IEnumerable ChildNodes() {