Fixes issue where functions inside binary operators wouldnt work
This commit is contained in:
parent
62a18e22d4
commit
9be1cfa1fc
|
@ -268,17 +268,24 @@ namespace Upsilon.Parser
|
|||
{
|
||||
expression = ParseBinaryExpression();
|
||||
}
|
||||
|
||||
HandleComplexExpression(expression);
|
||||
return expression;
|
||||
}
|
||||
|
||||
private ExpressionSyntax HandleComplexExpression(ExpressionSyntax baseExpression)
|
||||
{
|
||||
while (Current.Kind == SyntaxKind.OpenBracket || Current.Kind == SyntaxKind.OpenParenthesis ||
|
||||
Current.Kind == SyntaxKind.FullStop)
|
||||
{
|
||||
if (Current.Kind == SyntaxKind.OpenBracket)
|
||||
expression = ParseIndexExpression(expression);
|
||||
baseExpression = ParseIndexExpression(baseExpression);
|
||||
else if (Current.Kind == SyntaxKind.OpenParenthesis)
|
||||
expression = ParseFunctionCallExpression(expression);
|
||||
baseExpression = ParseFunctionCallExpression(baseExpression);
|
||||
else if (Current.Kind == SyntaxKind.FullStop)
|
||||
expression = ParseFullStopIndexExpression(expression);
|
||||
baseExpression = ParseFullStopIndexExpression(baseExpression);
|
||||
}
|
||||
return expression;
|
||||
return baseExpression;
|
||||
}
|
||||
|
||||
private StatementSyntax ParseAssignmentExpression()
|
||||
|
@ -346,6 +353,7 @@ namespace Upsilon.Parser
|
|||
|
||||
var op = NextToken();
|
||||
var right = ParseBinaryExpression(precedence);
|
||||
right = HandleComplexExpression(right);
|
||||
left = new BinaryExpressionSyntax(left, op, right);
|
||||
}
|
||||
return left;
|
||||
|
|
|
@ -115,6 +115,5 @@ return value
|
|||
Assert.Empty(script.Diagnostics.Messages);
|
||||
Assert.Equal(6, result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -198,7 +198,24 @@ end
|
|||
var result = script.EvaluateFunction<long>("add", new object[] {400, 128});
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
Assert.Equal(528, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleFunctionsInsideBinaryExpressions()
|
||||
{
|
||||
const string input = @"
|
||||
arr = {100, 56, 28}
|
||||
value = 0
|
||||
for key, val in arr do
|
||||
value = value + tonumber(key)
|
||||
end
|
||||
return value
|
||||
";
|
||||
var script = new Script(input, BoundScope, StaticScope);
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
var result = script.Evaluate<long>();
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
Assert.Equal(6, result);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue