Allow assigning comment info to all variables
This commit is contained in:
parent
963245c9e7
commit
15ce180b8c
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<SyntaxNode> ChildNodes()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue