From 939885a7d2577ee1fff73e2c4e8402eb9b9735ce Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 1 Feb 2026 00:16:37 -0500 Subject: [PATCH] xo-reader2: construct LambdaExpr to complete LambdaSsm + utest --- include/xo/reader2/ParserStateMachine.hpp | 3 +++ src/reader2/DLambdaSsm.cpp | 19 +++++++++++++------ src/reader2/ParserStateMachine.cpp | 6 ++++++ utest/SchematikaParser.test.cpp | 5 +++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/include/xo/reader2/ParserStateMachine.hpp b/include/xo/reader2/ParserStateMachine.hpp index 91c84ef1..d065e24f 100644 --- a/include/xo/reader2/ParserStateMachine.hpp +++ b/include/xo/reader2/ParserStateMachine.hpp @@ -82,6 +82,9 @@ namespace xo { **/ const DUniqueString * intern_string(std::string_view str); + /** get unique (within stringtable) string, beginning with @p prefix **/ + const DUniqueString * gensym(std::string_view prefix); + /** push nested local symtab while parsing the body of a lambda expression; * restore previous symtab at the end of lambda-expression definition. * See @ref pop_local_symtab diff --git a/src/reader2/DLambdaSsm.cpp b/src/reader2/DLambdaSsm.cpp index 4b2d7df8..4ed77732 100644 --- a/src/reader2/DLambdaSsm.cpp +++ b/src/reader2/DLambdaSsm.cpp @@ -11,6 +11,7 @@ #include "DExpectExprSsm.hpp" #include "ParserStateMachine.hpp" #include "syntaxstatetype.hpp" +#include #include #include //#include @@ -336,17 +337,23 @@ namespace xo { DLambdaSsm::on_parsed_expression(obj expr, ParserStateMachine * p_psm) { - if (lm_state_ == lambdastatetype::lm_4) { + if (lmstate_ == lambdastatetype::lm_4) { this->lmstate_ = lambdastatetype::lm_5; this->body_ = expr; // assemble lambda - obj lm_expr = DLambda::make(p_psm->expr_alloc(), - xxx typeref, - xxx name, - local_symtab_, - body_); + auto prefix = TypeRef::prefix_type::from_chars("lm"); + TypeRef tref = TypeRef::dwim(prefix, nullptr); + + const DUniqueString * name = p_psm->gensym("lambda"); + + auto lm_expr = obj + (DLambdaExpr::make(p_psm->expr_alloc(), + tref, + name, + local_symtab_, + body_)); p_psm->pop_ssm(); // this lambda p_psm->on_parsed_expression(lm_expr); diff --git a/src/reader2/ParserStateMachine.cpp b/src/reader2/ParserStateMachine.cpp index 82435b50..cf9c26c1 100644 --- a/src/reader2/ParserStateMachine.cpp +++ b/src/reader2/ParserStateMachine.cpp @@ -90,6 +90,12 @@ namespace xo { return stringtable_.intern(str); } + const DUniqueString * + ParserStateMachine::gensym(std::string_view str) + { + return stringtable_.gensym(str); + } + void ParserStateMachine::push_local_symtab(DLocalSymtab * symtab) { diff --git a/utest/SchematikaParser.test.cpp b/utest/SchematikaParser.test.cpp index b30b67f3..0defdeb5 100644 --- a/utest/SchematikaParser.test.cpp +++ b/utest/SchematikaParser.test.cpp @@ -394,9 +394,10 @@ namespace xo { log && log(xtag("parser", &parser)); log && log(xtag("result", result)); - REQUIRE(parser.has_incomplete_expr() == true); + REQUIRE(parser.has_incomplete_expr() == false); REQUIRE(!result.is_error()); - REQUIRE(result.is_incomplete()); + REQUIRE(result.is_expression()); + REQUIRE(result.result_expr()); } //REQUIRE(result.is_error());