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();
|
expression = ParseBinaryExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HandleComplexExpression(expression);
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExpressionSyntax HandleComplexExpression(ExpressionSyntax baseExpression)
|
||||||
|
{
|
||||||
while (Current.Kind == SyntaxKind.OpenBracket || Current.Kind == SyntaxKind.OpenParenthesis ||
|
while (Current.Kind == SyntaxKind.OpenBracket || Current.Kind == SyntaxKind.OpenParenthesis ||
|
||||||
Current.Kind == SyntaxKind.FullStop)
|
Current.Kind == SyntaxKind.FullStop)
|
||||||
{
|
{
|
||||||
if (Current.Kind == SyntaxKind.OpenBracket)
|
if (Current.Kind == SyntaxKind.OpenBracket)
|
||||||
expression = ParseIndexExpression(expression);
|
baseExpression = ParseIndexExpression(baseExpression);
|
||||||
else if (Current.Kind == SyntaxKind.OpenParenthesis)
|
else if (Current.Kind == SyntaxKind.OpenParenthesis)
|
||||||
expression = ParseFunctionCallExpression(expression);
|
baseExpression = ParseFunctionCallExpression(baseExpression);
|
||||||
else if (Current.Kind == SyntaxKind.FullStop)
|
else if (Current.Kind == SyntaxKind.FullStop)
|
||||||
expression = ParseFullStopIndexExpression(expression);
|
baseExpression = ParseFullStopIndexExpression(baseExpression);
|
||||||
}
|
}
|
||||||
return expression;
|
return baseExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
private StatementSyntax ParseAssignmentExpression()
|
private StatementSyntax ParseAssignmentExpression()
|
||||||
|
@ -346,6 +353,7 @@ namespace Upsilon.Parser
|
||||||
|
|
||||||
var op = NextToken();
|
var op = NextToken();
|
||||||
var right = ParseBinaryExpression(precedence);
|
var right = ParseBinaryExpression(precedence);
|
||||||
|
right = HandleComplexExpression(right);
|
||||||
left = new BinaryExpressionSyntax(left, op, right);
|
left = new BinaryExpressionSyntax(left, op, right);
|
||||||
}
|
}
|
||||||
return left;
|
return left;
|
||||||
|
|
|
@ -115,6 +115,5 @@ return value
|
||||||
Assert.Empty(script.Diagnostics.Messages);
|
Assert.Empty(script.Diagnostics.Messages);
|
||||||
Assert.Equal(6, result);
|
Assert.Equal(6, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -198,7 +198,24 @@ end
|
||||||
var result = script.EvaluateFunction<long>("add", new object[] {400, 128});
|
var result = script.EvaluateFunction<long>("add", new object[] {400, 128});
|
||||||
Assert.Empty(script.Diagnostics.Messages);
|
Assert.Empty(script.Diagnostics.Messages);
|
||||||
Assert.Equal(528, result);
|
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