xo-reader2: progress+apply works up to lparen introducing formals

This commit is contained in:
Roland Conybeare 2026-02-11 18:07:55 -05:00
commit 18ae5739c2
14 changed files with 396 additions and 30 deletions

View file

@ -38,8 +38,8 @@ set(SELF_SRCS
IPrintable_DLambdaSsm.cpp
DApplySsm.cpp
# ISyntaxStateMachine_DApplySsm.cpp
# IPrintable_DApplySsm.cpp
ISyntaxStateMachine_DApplySsm.cpp
IPrintable_DApplySsm.cpp
DParenSsm.cpp
ISyntaxStateMachine_DParenSsm.cpp

View file

@ -3,13 +3,14 @@
* @author Roland Conybeare, Feb 2026
**/
#include "DApplySsm.hpp"
#include "ApplySsm.hpp"
#include <xo/reflectutil/typeseq.hpp>
//#include "parserstatemachine.hpp"
//#include "expect_expr_xs.hpp"
namespace xo {
using xo::print::APrintable;
using xo::reflect::typeseq;
namespace scm {
@ -60,18 +61,21 @@ namespace xo {
return new (mem) DApplySsm(fn_expr);
}
#ifdef NOT_YET
void
apply_xs::start(rp<Expression> fn_expr,
parserstatemachine * p_psm)
DApplySsm::start(obj<AExpression> fn_expr,
ParserStateMachine * p_psm)
{
scope log(XO_DEBUG(p_psm->debug_flag()));
p_psm->push_exprstate(apply_xs::make());
p_psm->top_exprstate().on_expr(fn_expr.get(), p_psm);
p_psm->top_exprstate().on_leftparen_token(token_type::leftparen(), p_psm);
DApplySsm * apply_ssm
= DApplySsm::make(p_psm->parser_alloc(), fn_expr);
obj<ASyntaxStateMachine,DApplySsm> ssm(apply_ssm);
p_psm->push_ssm(ssm);
//OBSOLETE //p_psm->top_exprstate().on_expr(fn_expr.get(), p_psm);
//OBSOLETE //p_psm->on_token(token_type::leftparen(), p_psm);
}
#endif
syntaxstatetype
DApplySsm::ssm_type() const noexcept {
@ -194,7 +198,23 @@ namespace xo {
this->illegal_input_on_token(c_self_name, tk, exp, p_psm);
}
#endif
bool
DApplySsm::pretty(const ppindentinfo & ppii) const
{
// TODO: const-correct version of obj<> template
auto fn_expr = const_cast<DApplySsm*>(this)->fn_expr_.to_facet<APrintable>();
bool fn_expr_present(fn_expr);
return ppii.pps()->pretty_struct(ppii,
"DApplySsm",
refrtag("applystate", applystate_),
refrtag("expect", this->get_expect_str()),
refrtag("fn_expr", fn_expr, fn_expr_present));
}
#ifdef NOT_YET
void
apply_xs::print(std::ostream & os) const
{

View file

@ -9,6 +9,7 @@
#include "DExpectExprSsm.hpp"
#include "ssm/ISyntaxStateMachine_DExpectExprSsm.hpp"
#include "ApplySsm.hpp"
#include "ParenSsm.hpp"
#include <xo/expression2/DApplyExpr.hpp>
@ -20,21 +21,13 @@
#include <xo/procedure2/init_primitives.hpp> // for xo::scm::Primitives
#include <xo/procedure2/detail/IGCObject_DPrimitive_gco_2_gco_gco.hpp>
#ifdef NOT_YET
#include "DApplySsm.hpp"
#include "ssm/ISyntaxStateMachine_DApplySsm.hpp"
#endif
#include <xo/printable2/Printable.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/reflectutil/typeseq.hpp>
#include <xo/indentlog/print/cond.hpp>
#ifdef NOT_YET
#include "apply_xs.hpp"
#include "exprstatestack.hpp"
#include "expect_expr_xs.hpp"
#include "parserstatemachine.hpp"
#include "pretty_exprstatestack.hpp"
#include "xo/expression/AssignExpr.hpp"
#include "xo/expression/Apply.hpp"
@ -912,12 +905,39 @@ namespace xo {
}
if (op_type_ == optype::invalid) {
// leftparen begins function call arguments.
// .lhs_ now understood to be expression that evaluates to a
// function
// input:
/// <--- F1 --->
// (..........)(.. )..
// <------ A1 ----->
// <------- X1 ------>
//
// F1: expression evaluating to a function,
// parsed as fn_expr
// A1: expression parsed as a function call (i.e. apply-expression)
// X1: operator expression starting with A1
//
// before:
// [0] ProgressSsm responsible for input beginning with F1
// .lhs = fn_expr, .op_type empty, .rhs empty
//
// after:
// [0] ApplySsm responsible for function call A1
// .fn_expr = fn_expr
// [1] ProgressSsm responsible for operator expression X1
// .lhs empty, .op_type empty, .rhs empty
//
// Remarks:
// 1. keep ProgressSsm on the stack in case input continues like:
// fn_expr(args..) + ..
// i.e. to allow for infix operator following apply
//
obj<AExpression> fn_expr(this->lhs_);
this->lhs_ = obj<AExpression>();
DApplySsm::start(fn_expr, p_psm);
return;
}
Super::on_token(tk, p_psm);

View file

@ -0,0 +1,28 @@
/** @file IPrintable_DApplySsm.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DApplySsm.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DApplySsm.json5]
**/
#include "ssm/IPrintable_DApplySsm.hpp"
namespace xo {
namespace scm {
auto
IPrintable_DApplySsm::pretty(const DApplySsm & self, const ppindentinfo & ppii) -> bool
{
return self.pretty(ppii);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IPrintable_DApplySsm.cpp */

View file

@ -0,0 +1,69 @@
/** @file ISyntaxStateMachine_DApplySsm.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/ISyntaxStateMachine_DApplySsm.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/ISyntaxStateMachine_DApplySsm.json5]
**/
#include "ssm/ISyntaxStateMachine_DApplySsm.hpp"
namespace xo {
namespace scm {
auto
ISyntaxStateMachine_DApplySsm::ssm_type(const DApplySsm & self) noexcept -> syntaxstatetype
{
return self.ssm_type();
}
auto
ISyntaxStateMachine_DApplySsm::get_expect_str(const DApplySsm & self) noexcept -> std::string_view
{
return self.get_expect_str();
}
auto
ISyntaxStateMachine_DApplySsm::on_token(DApplySsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
{
self.on_token(tk, p_psm);
}
auto
ISyntaxStateMachine_DApplySsm::on_parsed_symbol(DApplySsm & self, std::string_view sym, ParserStateMachine * p_psm) -> void
{
self.on_parsed_symbol(sym, p_psm);
}
auto
ISyntaxStateMachine_DApplySsm::on_parsed_typedescr(DApplySsm & self, TypeDescr td, ParserStateMachine * p_psm) -> void
{
self.on_parsed_typedescr(td, p_psm);
}
auto
ISyntaxStateMachine_DApplySsm::on_parsed_formal(DApplySsm & self, const DUniqueString * param_name, TypeDescr param_type, ParserStateMachine * p_psm) -> void
{
self.on_parsed_formal(param_name, param_type, p_psm);
}
auto
ISyntaxStateMachine_DApplySsm::on_parsed_formal_arglist(DApplySsm & self, DArray * arglist, ParserStateMachine * p_psm) -> void
{
self.on_parsed_formal_arglist(arglist, p_psm);
}
auto
ISyntaxStateMachine_DApplySsm::on_parsed_expression(DApplySsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
{
self.on_parsed_expression(expr, p_psm);
}
auto
ISyntaxStateMachine_DApplySsm::on_parsed_expression_with_token(DApplySsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
{
self.on_parsed_expression_with_token(expr, tk, p_psm);
}
} /*namespace scm*/
} /*namespace xo*/
/* end ISyntaxStateMachine_DApplySsm.cpp */

View file

@ -17,8 +17,8 @@
#include <xo/reader2/ssm/ISyntaxStateMachine_DIfElseSsm.hpp>
#include <xo/reader2/ssm/IPrintable_DIfElseSsm.hpp>
#include <xo/reader2/ssm/IPrintable_DSequenceSsm.hpp>
#include "ApplySsm.hpp"
#include "SequenceSsm.hpp"
#include "ParenSsm.hpp"
#include <xo/reader2/ssm/ISyntaxStateMachine_DExpectFormalArglistSsm.hpp>
@ -67,6 +67,9 @@ namespace xo {
FacetRegistry::register_impl<ASyntaxStateMachine, DIfElseSsm>();
FacetRegistry::register_impl<APrintable, DIfElseSsm>();
FacetRegistry::register_impl<APrintable, DApplySsm>();
FacetRegistry::register_impl<ASyntaxStateMachine, DSequenceSsm>();
FacetRegistry::register_impl<APrintable, DSequenceSsm>();
FacetRegistry::register_impl<ASyntaxStateMachine, DExpectFormalArglistSsm>();