PyFunction.fromLambda constructor
PyFunction.fromLambda(
- LambdaExpr lambdaExpr,
- Environment closure
Implementation
PyFunction.fromLambda(LambdaExpr lambdaExpr, this.closure)
: declaration = null, // declaration is null for LAMBDA
expressionBody = lambdaExpr.body,
params = lambdaExpr.params,
isInitializer = false {
// Make sure that the body is an Expr but not assignment.
// In case of an assignment, a SyntaxError should be thrown by the Parser,
// but it is easier to detect it here.
if (expressionBody is AssignExpr ||
expressionBody is AugAssignExpr ||
expressionBody is IndexSetExpr ||
expressionBody is AttributeSetExpr) {
Token errorToken = lambdaExpr.keyword;
throw RuntimeError(
errorToken,
"SyntaxError: invalid syntax (assignment in lambda)",
);
}
}