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 65d1fd840b
14 changed files with 396 additions and 30 deletions

View file

@ -244,6 +244,32 @@ xo_add_genfacetimpl(
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-reader2-facetimpl-syntaxstatemachine-applyssm
FACET_PKG xo_reader2
FACET SyntaxStateMachine
REPR ApplySsm
INPUT idl/ISyntaxStateMachine_DApplySsm.json5
OUTPUT_HPP_DIR include/xo/reader2
OUTPUT_IMPL_SUBDIR ssm
OUTPUT_CPP_DIR src/reader2
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-reader2-facetimpl-printable-applyssm
FACET_PKG xo_printable2
FACET Printable
REPR ApplySsm
INPUT idl/IPrintable_DApplySsm.json5
OUTPUT_HPP_DIR include/xo/reader2
OUTPUT_IMPL_SUBDIR ssm
OUTPUT_CPP_DIR src/reader2
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-reader2-facetimpl-syntaxstatemachine-expectsymbolssm

View file

@ -0,0 +1,13 @@
{
mode: "implementation",
includes: [ "<xo/printable2/Printable.hpp>",
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
local_types: [],
namespace1: "xo",
namespace2: "scm",
facet_idl: "idl/Printable.json5",
brief: "provide APrintable interface for DApplySsm",
using_doxygen: true,
repr: "DApplySsm",
doc: [ "implement APrintable for DApplySsm" ],
}

View file

@ -0,0 +1,13 @@
{
mode: "implementation",
includes: [ "\"SyntaxStateMachine.hpp\"",
"\"ssm/ISyntaxStateMachine_Xfer.hpp\"" ],
local_types: [ ],
namespace1: "xo",
namespace2: "scm",
facet_idl: "idl/SyntaxStateMachine.json5",
brief: "provide ASyntaxStateMachine interface for DApplySsm",
using_doxygen: true,
repr: "DApplySsm",
doc: [ "implement ASyntaxStateMachine for DApplySsm" ],
}

View file

@ -0,0 +1,12 @@
/** @file ApplySsm.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DApplySsm.hpp"
#include "ssm/ISyntaxStateMachine_DApplySsm.hpp"
#include "ssm/IPrintable_DApplySsm.hpp"
/* end ApplySsm.hpp */

View file

@ -89,10 +89,11 @@ namespace xo {
static DApplySsm * make(DArena & parser_mm,
obj<AExpression> fn_expr);
#ifdef NOT_YET
/**
* Start apply. Will trigger this after input like
* "fn("
* or
* "makefn()()"
*
* apply_xs remains on expr stack until closing right paren
* fn(arg1-expr, arg2-expr, ...)
@ -100,9 +101,8 @@ namespace xo {
* @p fnex expression in function position
* @p p_psm parser state machine
**/
static void start(rp<Expression> fnex,
parserstatemachine * p_psm);
#endif
static void start(obj<AExpression> fnex,
ParserStateMachine * p_psm);
///@}
/** @defgroup scm-applyssm-access methods **/
@ -124,6 +124,8 @@ namespace xo {
/** mnemonic for expected remaining syntax for current parsing state **/
std::string_view get_expect_str() const noexcept;
///@}
#ifdef NOT_YET
virtual void on_expr(bp<Expression> expr,
@ -143,6 +145,14 @@ namespace xo {
static std::unique_ptr<apply_xs> make();
#endif
/** @defgroup ssm-applyssm-printable-facet printable facet **/
///@{
/** pretty-printing support **/
bool pretty(const ppindentinfo & ppii) const;
///@}
private:
/** current state of parser for this apply expression **/
applyexprstatetype applystate_ = applyexprstatetype::apply_0;

View file

@ -0,0 +1,13 @@
/** @file SequenceSsm.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DSequenceSsm.hpp"
#include "ssm/ISyntaxStateMachine_DSequenceSsm.hpp"
#include "ssm/IPrintable_DSequenceSsm.hpp"
/* end SequenceSsm.hpp */

View file

@ -0,0 +1,62 @@
/** @file IPrintable_DApplySsm.hpp
*
* 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_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DApplySsm.json5]
**/
#pragma once
#include "Printable.hpp"
#include <xo/printable2/Printable.hpp>
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
#include "DApplySsm.hpp"
namespace xo { namespace scm { class IPrintable_DApplySsm; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::print::APrintable,
xo::scm::DApplySsm>
{
using ImplType = xo::print::IPrintable_Xfer
<xo::scm::DApplySsm,
xo::scm::IPrintable_DApplySsm>;
};
}
}
namespace xo {
namespace scm {
/** @class IPrintable_DApplySsm
**/
class IPrintable_DApplySsm {
public:
/** @defgroup scm-printable-dapplyssm-type-traits **/
///@{
using ppindentinfo = xo::print::APrintable::ppindentinfo;
using Copaque = xo::print::APrintable::Copaque;
using Opaque = xo::print::APrintable::Opaque;
///@}
/** @defgroup scm-printable-dapplyssm-methods **/
///@{
// const methods
/** Pretty-printing support for this object.
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
static bool pretty(const DApplySsm & self, const ppindentinfo & ppii);
// non-const methods
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -0,0 +1,77 @@
/** @file ISyntaxStateMachine_DApplySsm.hpp
*
* 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_repr.hpp.j2]
* 3. idl for facet methods
* [idl/ISyntaxStateMachine_DApplySsm.json5]
**/
#pragma once
#include "SyntaxStateMachine.hpp"
#include "SyntaxStateMachine.hpp"
#include "ssm/ISyntaxStateMachine_Xfer.hpp"
#include "DApplySsm.hpp"
namespace xo { namespace scm { class ISyntaxStateMachine_DApplySsm; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::scm::ASyntaxStateMachine,
xo::scm::DApplySsm>
{
using ImplType = xo::scm::ISyntaxStateMachine_Xfer
<xo::scm::DApplySsm,
xo::scm::ISyntaxStateMachine_DApplySsm>;
};
}
}
namespace xo {
namespace scm {
/** @class ISyntaxStateMachine_DApplySsm
**/
class ISyntaxStateMachine_DApplySsm {
public:
/** @defgroup scm-syntaxstatemachine-dapplyssm-type-traits **/
///@{
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
///@}
/** @defgroup scm-syntaxstatemachine-dapplyssm-methods **/
///@{
// const methods
/** identify a type of syntax state machine **/
static syntaxstatetype ssm_type(const DApplySsm & self) noexcept;
/** text describing expected/allowed input to this ssm in current state **/
static std::string_view get_expect_str(const DApplySsm & self) noexcept;
// non-const methods
/** operate state machine for incoming token @p tk **/
static void on_token(DApplySsm & self, const Token & tk, ParserStateMachine * p_psm);
/** update stat machine for incoming parsed symbol @p sym **/
static void on_parsed_symbol(DApplySsm & self, std::string_view sym, ParserStateMachine * p_psm);
/** operate state machine for incoming type description @p td **/
static void on_parsed_typedescr(DApplySsm & self, TypeDescr td, ParserStateMachine * p_psm);
/** operate state machine for formal emitted by nested ssm **/
static void on_parsed_formal(DApplySsm & self, const DUniqueString * param_name, TypeDescr param_type, ParserStateMachine * p_psm);
/** consume formal arglist emitted by nested ssm **/
static void on_parsed_formal_arglist(DApplySsm & self, DArray * arglist, ParserStateMachine * p_psm);
/** update state machine for incoming parsed expression @p expr **/
static void on_parsed_expression(DApplySsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
static void on_parsed_expression_with_token(DApplySsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

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>();