xo-reader2: refactor: move apply genfacet to subdirs

This commit is contained in:
Roland Conybeare 2026-03-11 10:42:42 -05:00
commit 6a0333765a
9 changed files with 11 additions and 11 deletions

View file

@ -0,0 +1,228 @@
/** @file DApplySsm.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DSyntaxStateMachine.hpp"
#include "syntaxstatetype.hpp"
#include <xo/expression2/ApplyExpr.hpp>
//#include <xo/facet/obj.hpp>
#include <string_view>
namespace xo {
namespace scm {
/**
* fn ( arg1 , arg2 , .. , argn )
* ^ ^ ^ ^ ^ ^ ^ ^ ^
* | | | | | | | | (done)
* | | | | | | | apply_3
* | | | | | | apply_2:expect_rhs_expression
* | | | | | apply_3
* | | | | apply_2:expect_rhs_expression
* | | | apply_3
* | | apply_2:expect_rhs_expression
* | apply_1
* apply_0:expect_rhs_expression
*
* apply_0 --on_expr()--> apply_1
* apply_1 --on_leftparen()--> apply_2
* apply_2 --on_expr()--> apply_3
* --on_rightparen()--> (done)
* apply_3 --on_comma()--> apply_2
* --on_rightparen()--> (done)
*
* apply_0: start
* apply_1: leftparen following expr allows parser to recognize apply
* apply_2: expect next argument, or rightparent to continue
* apply_3: got argument, expect comma or rightparen to continue
* (done): apply complete, pop exprstate from stack
*
* In practice will start in state apply_1
**/
enum class applyexprstatetype {
invalid = -1,
apply_0,
apply_1,
apply_2, // rename -> apply_2a
apply_3, // rename -> apply_2b
N
};
extern const char * applyexprstatetype_descr(applyexprstatetype x);
std::ostream &
operator<<(std::ostream & os, applyexprstatetype x);
/** @class DApplySsm
* @brief state machine for parsing a schematika function-call-expression
**/
class DApplySsm : public DSyntaxStateMachine<DApplySsm> {
public:
using Super = DSyntaxStateMachine<DApplySsm>;
using TypeDescr = xo::reflect::TypeDescr;
using AAllocator = xo::mm::AAllocator;
using DArena = xo::mm::DArena;
using ppindentinfo = xo::print::ppindentinfo;
//using Apply = xo::scm::Apply;
public:
/** @defgroup scm-applyssm-ctors constructors **/
///@{
/** construct apply ssm with @p fn_expr
* supplying function to be invoked.
*
* Expect during parsing of input like f(...)
* that we parse f before parser knows that it will be
* followed by leftparen
**/
explicit DApplySsm(applyexprstatetype applystate,
obj<AExpression> fn_expr,
DArray * args);
/** create instance using memory from @p parser_mm.
* with function to be called supplied by @p fn_expr.
**/
static DApplySsm * _make(DArena & parser_mm,
obj<AExpression> fn_expr);
/** create fop referring to new DApplySsm **/
static obj<ASyntaxStateMachine,DApplySsm> make(DArena & parser_mm,
obj<AExpression> fn_expr);
/**
* 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, ...)
*
* @p fnex expression in function position
* @p p_psm parser state machine
**/
static void start(obj<AExpression> fnex,
ParserStateMachine * p_psm);
///@}
/** @defgroup scm-applyssm-access-methods access methods **/
///@{
/** identify this nested state machine **/
static const char * ssm_classname() { return "DApplySsm"; }
/** current internal state **/
applyexprstatetype applystate() const noexcept { return applystate_; }
///@}
/** @defgroup scm-applyssm-methods general methods **/
///@{
/** handle leftparen token @p tk for this ssm,
* with overall parser state in @p p_psm
**/
void on_leftparen_token(const Token & tk,
ParserStateMachine * p_psm);
/** handle rightparen token @p tk for this ssm,
* with overall parser state in @p p_psm.
*
* Rightparen will complete apply-expression,
* terminating this syntax.
**/
void on_rightparen_token(const Token & tk,
ParserStateMachine * p_psm);
///@}
/** @defgroup ssm-applyssm-facet syntaxstatemachine facet methods **/
///@{
/** identifies the ssm implemented here **/
syntaxstatetype ssm_type() const noexcept;
/** mnemonic for expected remaining syntax for current parsing state **/
std::string_view get_expect_str() const noexcept;
/** update this apply-ssm for incoming token @p tk,
* with overall parsing state in @p p_psm
**/
void on_token(const Token & tk,
ParserStateMachine * p_psm);
/** update this apply-ssm with data from nested ssm:
* expression @p expr, followed by token @p tk.
**/
void on_parsed_expression_with_token(obj<AExpression> expr,
const Token & tk,
ParserStateMachine * p_psm);
///@}
#ifdef NOT_YET
virtual void on_expr(bp<Expression> expr,
parserstatemachine * p_psm) override;
virtual void on_comma_token(const token_type & tk,
parserstatemachine * p_psm) override;
virtual void on_rightparen_token(const token_type & tk,
parserstatemachine * p_psm) override;
private:
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:
/** @defgroup ssm-applyssm-impl-methods **/
///@{
/** create final apply-expression for this syntax,
* using @p mm for memory
**/
obj<AExpression> assemble_expr(obj<AAllocator> mm);
///@}
private:
/** @defgroup ssm-applyssm-member-variables **/
///@{
/** current state of parser for this apply expression **/
applyexprstatetype applystate_ = applyexprstatetype::apply_0;
/** evaluates to function to be invoked **/
obj<AExpression> fn_expr_;
/** args_expr_v_[i] evaluates to the i'th argument to call.
* Not using flexible array here since we don't know size at
* construction time
*
* (though could revisit + realloc this DApplySsm instance in
* place to optimize)
**/
DArray * args_expr_v_ = nullptr;
///@}
};
} /*namespace scm */
namespace print {
#ifndef ppdetail_atomic
PPDETAIL_ATOMIC(xo::scm::applyexprstatetype);
#endif
}
} /*namespace xo*/
/* end DApplySsm.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,84 @@
/** @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 AGCObject = xo::scm::ASyntaxStateMachine::AGCObject;
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);
/** update state machine for type emitted by nested ssm **/
static void on_parsed_type(DApplySsm & self, obj<AType> type, 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);
/** operate state machine for formal emitted by nested ssm **/
static void on_parsed_formal_with_token(DApplySsm & self, const DUniqueString * param_name, TypeDescr param_type, const Token & tk, 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 nested 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);
/** update state machine for nested quoted literal @p lit **/
static void on_quoted_literal(DApplySsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */