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