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);
|
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 == "_")
|
if (name == "_")
|
||||||
return null;
|
return null;
|
||||||
|
@ -265,6 +265,8 @@ namespace Upsilon.Binder
|
||||||
variable = new VariableSymbol(name, assignment.Type, isLocal);
|
variable = new VariableSymbol(name, assignment.Type, isLocal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable.CommentValue = commentData;
|
||||||
|
|
||||||
if (isLocal)
|
if (isLocal)
|
||||||
Scope.DefineLocalVariable(variable);
|
Scope.DefineLocalVariable(variable);
|
||||||
else
|
else
|
||||||
|
@ -309,7 +311,7 @@ namespace Upsilon.Binder
|
||||||
var boundExpression = BindExpression(e.Expression);
|
var boundExpression = BindExpression(e.Expression);
|
||||||
|
|
||||||
var isLocal = e.LocalToken != null;
|
var isLocal = e.LocalToken != null;
|
||||||
var boundVariable = TryBindVariable(name, isLocal, boundExpression);
|
var boundVariable = TryBindVariable(name, isLocal, boundExpression, e.CommentData);
|
||||||
if (boundVariable != null)
|
if (boundVariable != null)
|
||||||
{
|
{
|
||||||
var variable = new BoundVariableSymbol(boundVariable, variableExpression.Span);
|
var variable = new BoundVariableSymbol(boundVariable, variableExpression.Span);
|
||||||
|
@ -329,7 +331,7 @@ namespace Upsilon.Binder
|
||||||
|
|
||||||
foreach (var identifierToken in s.Identifiers)
|
foreach (var identifierToken in s.Identifiers)
|
||||||
{
|
{
|
||||||
var boundVariable = TryBindVariable(identifierToken.Name, isLocal, assignment);
|
var boundVariable = TryBindVariable(identifierToken.Name, isLocal, assignment, null);
|
||||||
ls.Add(boundVariable);
|
ls.Add(boundVariable);
|
||||||
}
|
}
|
||||||
return new BoundMultiAssignmentStatement(ls.ToImmutableArray(), assignment, s.Span);
|
return new BoundMultiAssignmentStatement(ls.ToImmutableArray(), assignment, s.Span);
|
||||||
|
|
|
@ -324,13 +324,21 @@ namespace Upsilon.Parser
|
||||||
|
|
||||||
private StatementSyntax ParseAssignmentExpression()
|
private StatementSyntax ParseAssignmentExpression()
|
||||||
{
|
{
|
||||||
|
string[] commentData = null;
|
||||||
SyntaxToken localKeyword = null;
|
SyntaxToken localKeyword = null;
|
||||||
if (Current.Kind == SyntaxKind.LocalKeyword)
|
if (Current.Kind == SyntaxKind.LocalKeyword)
|
||||||
{
|
{
|
||||||
localKeyword = MatchToken(SyntaxKind.LocalKeyword);
|
localKeyword = MatchToken(SyntaxKind.LocalKeyword);
|
||||||
|
commentData = localKeyword.CommentData;
|
||||||
}
|
}
|
||||||
|
|
||||||
var identifier = ParseExpression();
|
var identifier = ParseExpression();
|
||||||
|
if (commentData == null && identifier.Kind == SyntaxKind.VariableExpression)
|
||||||
|
{
|
||||||
|
var variable = (VariableExpressionSyntax)identifier;
|
||||||
|
commentData = variable.Identifier.CommentData;
|
||||||
|
}
|
||||||
|
|
||||||
if (Current.Kind == SyntaxKind.Comma)
|
if (Current.Kind == SyntaxKind.Comma)
|
||||||
{
|
{
|
||||||
if (identifier.Kind != SyntaxKind.VariableExpression)
|
if (identifier.Kind != SyntaxKind.VariableExpression)
|
||||||
|
@ -352,7 +360,10 @@ namespace Upsilon.Parser
|
||||||
|
|
||||||
var assignmentToken = MatchToken(SyntaxKind.Equals);
|
var assignmentToken = MatchToken(SyntaxKind.Equals);
|
||||||
var expression = ParseExpression();
|
var expression = ParseExpression();
|
||||||
return new AssignmentStatementSyntax(localKeyword, identifier, assignmentToken, expression);
|
return new AssignmentStatementSyntax(localKeyword, identifier, assignmentToken, expression)
|
||||||
|
{
|
||||||
|
CommentData = commentData
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private StatementSyntax ParseTableAssignmentExpression(ExpressionSyntax tableExpression)
|
private StatementSyntax ParseTableAssignmentExpression(ExpressionSyntax tableExpression)
|
||||||
|
|
|
@ -22,6 +22,7 @@ namespace Upsilon.Parser
|
||||||
public ExpressionSyntax Identifier { get; }
|
public ExpressionSyntax Identifier { get; }
|
||||||
public SyntaxToken EqualsToken { get; }
|
public SyntaxToken EqualsToken { get; }
|
||||||
public ExpressionSyntax Expression { get; }
|
public ExpressionSyntax Expression { get; }
|
||||||
|
public string[] CommentData { get; set; }
|
||||||
|
|
||||||
public override IEnumerable<SyntaxNode> ChildNodes()
|
public override IEnumerable<SyntaxNode> ChildNodes()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue