From 372be46394a587500486469b453141f6547a4060 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Sat, 1 Aug 2026 20:54:41 +1000 Subject: [PATCH] Fix factory functions --- src/parser/parser.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index 59310d3..c9ed430 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -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; }