mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Fix function call statement passes Variable expression instead of function name value
This commit is contained in:
parent
3e661c81c4
commit
34298bceb8
@ -160,7 +160,7 @@ public final class Parser {
|
|||||||
return classDeclaration();
|
return classDeclaration();
|
||||||
}
|
}
|
||||||
if (lookMatch(0, TokenType.WORD) && lookMatch(1, TokenType.LPAREN)) {
|
if (lookMatch(0, TokenType.WORD) && lookMatch(1, TokenType.LPAREN)) {
|
||||||
return new ExprStatement(functionChain(qualifiedName()));
|
return functionCallStatement();
|
||||||
}
|
}
|
||||||
return assignmentStatement();
|
return assignmentStatement();
|
||||||
}
|
}
|
||||||
@ -321,6 +321,12 @@ public final class Parser {
|
|||||||
return statementOrBlock();
|
return statementOrBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ExprStatement functionCallStatement() {
|
||||||
|
return new ExprStatement(
|
||||||
|
functionChain(new ValueExpression(consume(TokenType.WORD).text()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private Expression functionChain(Expression qualifiedNameExpr) {
|
private Expression functionChain(Expression qualifiedNameExpr) {
|
||||||
// f1()()() || f1().f2().f3() || f1().key
|
// f1()()() || f1().f2().f3() || f1().key
|
||||||
final Expression expr = function(qualifiedNameExpr);
|
final Expression expr = function(qualifiedNameExpr);
|
||||||
|
@ -45,15 +45,11 @@ public final class FunctionalExpression extends InterruptableNode implements Exp
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Function consumeFunction(Expression expr) {
|
private Function consumeFunction(Expression expr) {
|
||||||
try {
|
final Value value = expr.eval();
|
||||||
final Value value = expr.eval();
|
if (value.type() == Types.FUNCTION) {
|
||||||
if (value.type() == Types.FUNCTION) {
|
return ((FunctionValue) value).getValue();
|
||||||
return ((FunctionValue) value).getValue();
|
|
||||||
}
|
|
||||||
return getFunction(value.asString());
|
|
||||||
} catch (VariableDoesNotExistsException ex) {
|
|
||||||
return getFunction(ex.getVariable());
|
|
||||||
}
|
}
|
||||||
|
return getFunction(value.asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Function getFunction(String key) {
|
private Function getFunction(String key) {
|
||||||
|
Loading…
Reference in New Issue
Block a user