Fix factory functions
This commit is contained in:
@@ -131,7 +131,6 @@ namespace Solstice {
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
Node Parser::parseActionFunction() {
|
||||
Node node{NodeType::FunctionBind};
|
||||
|
||||
@@ -140,25 +139,33 @@ namespace Solstice {
|
||||
throw std::runtime_error("expecting function arguments before '->'");
|
||||
}
|
||||
|
||||
// the previous node is either a tuple or expression (for lambda) or a function call (for named function)
|
||||
if (previous->type == NodeType::FunctionCall) {
|
||||
node.type = NodeType::FunctionBind;
|
||||
node.children.push_back(previous->children[0]); // name
|
||||
node.children.push_back(previous->children[1]); // args
|
||||
} else if (previous->type == NodeType::Tuple || previous->type == NodeType::Expression) {
|
||||
node.type = NodeType::Lambda;
|
||||
previous->type = NodeType::Tuple; // for consistency's sake
|
||||
previous->type = NodeType::Tuple;
|
||||
node.children.push_back(*previous);
|
||||
} else {
|
||||
throw std::runtime_error("expecting function arguments before '->'");
|
||||
}
|
||||
|
||||
// process the body for the function
|
||||
auto body = parseOneNode(Precedence::Root);
|
||||
if (!body.has_value()) {
|
||||
|
||||
Node bodyContext{NodeType::Root};
|
||||
Node* prevContext = context;
|
||||
context = &bodyContext;
|
||||
|
||||
while (auto n = parseOneNode(Precedence::NewLine)) {
|
||||
bodyContext.children.push_back(*n);
|
||||
}
|
||||
|
||||
context = prevContext;
|
||||
|
||||
if (bodyContext.children.empty()) {
|
||||
throw std::runtime_error("expecting function body after '->'");
|
||||
}
|
||||
node.children.push_back(*body);
|
||||
node.children.push_back(bodyContext.children.back());
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user