xo-reader2: refactor: generated file locn for IfElseSsm
This commit is contained in:
parent
8bb36ae3e0
commit
afe34f1d8a
11 changed files with 16 additions and 19 deletions
193
include/xo/reader2/ifelse/DIfElseSsm.hpp
Normal file
193
include/xo/reader2/ifelse/DIfElseSsm.hpp
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
/** @file DIfElseSsm.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jul 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DSyntaxStateMachine.hpp"
|
||||
#include <xo/expression2/DIfElseExpr.hpp>
|
||||
#include "syntaxstatetype.hpp"
|
||||
#include <xo/expression2/detail/IExpression_DIfElseExpr.hpp>
|
||||
#include <xo/expression2/DIfElseExpr.hpp>
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/**
|
||||
* if test-expr then then-expr else else-expr ;
|
||||
* ^ ^ ^ ^ ^ ^ ^
|
||||
* | | | | | | |
|
||||
* | if_1 if_2 if_3 if_4 if_5 if_6
|
||||
* if_0
|
||||
*
|
||||
* if_0 --on_if_token()--> if_1
|
||||
* if_1 --on_expr()--> if_2
|
||||
* if_2 --on_then_token()--> if_3
|
||||
* if_3 --on_expr()--> if_4
|
||||
* if_4 --on_else_token()--> if_5
|
||||
* --on_semicolon_token()--> (done)
|
||||
* if_5 --on_expr()-->if_6
|
||||
* if_6 --on_semicolon_token()--> (done)
|
||||
**/
|
||||
enum class ifexprstatetype {
|
||||
invalid = -1,
|
||||
|
||||
if_0,
|
||||
if_1,
|
||||
if_2,
|
||||
if_3,
|
||||
if_4,
|
||||
if_5,
|
||||
if_6,
|
||||
|
||||
N,
|
||||
};
|
||||
|
||||
extern const char * ifexprstatetype_descr(ifexprstatetype x);
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream & os, ifexprstatetype x);
|
||||
|
||||
/** @class DIfElseSsm
|
||||
* @brief syntax state machine for parsing a conditional expression
|
||||
**/
|
||||
class DIfElseSsm : public DSyntaxStateMachine<DIfElseSsm> {
|
||||
public:
|
||||
using Super = DSyntaxStateMachine<DIfElseSsm>;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using DArena = xo::mm::DArena;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
public:
|
||||
/** @defgroup scm-ifelsessm-expression-ctors constructors **/
|
||||
///@{
|
||||
explicit DIfElseSsm(DIfElseExpr * ifelse_expr);
|
||||
|
||||
/** create instance using memory from @p parser_mm
|
||||
* with initial scaffold @p ifelse_expr.
|
||||
**/
|
||||
static DIfElseSsm * _make(DArena & parser_mm,
|
||||
DIfElseExpr * ifelse_expr);
|
||||
|
||||
/** create fop referring to new DIfElseSsm **/
|
||||
static obj<ASyntaxStateMachine,DIfElseSsm> make(DArena & parser_mm,
|
||||
DIfElseExpr * ifelse_expr);
|
||||
|
||||
/** start nested parser for an if-else expression
|
||||
* on top of parser state machine @p p_psm.
|
||||
* Use @p parser_mm to allocate syntax state machines
|
||||
* (i.e. temporary memory needed only during parsing)
|
||||
* Use @p expr_mm to allocate expressions.
|
||||
**/
|
||||
static void start(DArena & parser_mm,
|
||||
obj<AAllocator> expr_mm,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
static const char * ssm_classname() { return "DIfElseSsm"; }
|
||||
|
||||
DSyntaxStateMachine<DIfElseSsm> * super() { return this; }
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-ifelsessm-expression-methods general methods **/
|
||||
///@{
|
||||
|
||||
/** operate state machine on if-token input @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_if_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** operate state machine on then-token input @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_then_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** operate state machine on else-token input @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_else_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** victory: report completed @ref if_expr_ to parent ssm,
|
||||
* after removing this ssm from parser stack
|
||||
**/
|
||||
void finish_and_continue(ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-ifelsessm-expression-facet expression facet methods **/
|
||||
///@{
|
||||
|
||||
/** identifies this state machine **/
|
||||
syntaxstatetype ssm_type() const noexcept;
|
||||
|
||||
/** text describing expected/allowed input to this ssm in current state.
|
||||
* Intended to drive error messages
|
||||
**/
|
||||
std::string_view get_expect_str() const noexcept;
|
||||
|
||||
/** operate state machine for this syntax on incoming token @p tk
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** operate state machine for this syntax on incoming semicolon token @p tk
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_semicolon_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax after parsing an expression @p expr,
|
||||
* overall parser state in @p p_psm.
|
||||
**/
|
||||
void on_parsed_expression(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax after parsing an expression @p expr,
|
||||
* followed by semicolon,
|
||||
* with overall parser state in @p p_psm.
|
||||
**/
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-ifelsessm-printable-facet printable facet methods **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef NOT_YET
|
||||
virtual void on_rightbrace_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
#ifdef NOT_YET
|
||||
static std::unique_ptr<if_else_xs> make();
|
||||
|
||||
/** exit this exprstate,
|
||||
* and deliver @ref if_expr_ to parent exprstate
|
||||
**/
|
||||
void finish_and_continue(parserstatemachine * p_psm);
|
||||
#endif
|
||||
|
||||
private:
|
||||
ifexprstatetype ifstate_ = ifexprstatetype::invalid;
|
||||
/** scaffold ifelse-expression here.
|
||||
* This will eventually be the output of this ssm
|
||||
*
|
||||
* TODO: can use DIfElseExpr* here. See xo-object2//DList
|
||||
**/
|
||||
obj<AExpression,DIfElseExpr> if_expr_;
|
||||
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DIfElseSsm.hpp */
|
||||
62
include/xo/reader2/ifelse/IPrintable_DIfElseSsm.hpp
Normal file
62
include/xo/reader2/ifelse/IPrintable_DIfElseSsm.hpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DIfElseSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DIfElseSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DIfElseSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DIfElseSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DIfElseSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DIfElseSsm>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DIfElseSsm,
|
||||
xo::scm::IPrintable_DIfElseSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DIfElseSsm
|
||||
**/
|
||||
class IPrintable_DIfElseSsm {
|
||||
public:
|
||||
/** @defgroup scm-printable-difelsessm-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-difelsessm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DIfElseSsm & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
84
include/xo/reader2/ifelse/ISyntaxStateMachine_DIfElseSsm.hpp
Normal file
84
include/xo/reader2/ifelse/ISyntaxStateMachine_DIfElseSsm.hpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/** @file ISyntaxStateMachine_DIfElseSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISyntaxStateMachine_DIfElseSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISyntaxStateMachine_DIfElseSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_Xfer.hpp"
|
||||
#include "DIfElseSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class ISyntaxStateMachine_DIfElseSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::ASyntaxStateMachine,
|
||||
xo::scm::DIfElseSsm>
|
||||
{
|
||||
using ImplType = xo::scm::ISyntaxStateMachine_Xfer
|
||||
<xo::scm::DIfElseSsm,
|
||||
xo::scm::ISyntaxStateMachine_DIfElseSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class ISyntaxStateMachine_DIfElseSsm
|
||||
**/
|
||||
class ISyntaxStateMachine_DIfElseSsm {
|
||||
public:
|
||||
/** @defgroup scm-syntaxstatemachine-difelsessm-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-difelsessm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** identify a type of syntax state machine **/
|
||||
static syntaxstatetype ssm_type(const DIfElseSsm & self) noexcept;
|
||||
/** text describing expected/allowed input to this ssm in current state **/
|
||||
static std::string_view get_expect_str(const DIfElseSsm & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** operate state machine for incoming token @p tk **/
|
||||
static void on_token(DIfElseSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DIfElseSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
static void on_parsed_typedescr(DIfElseSsm & self, TypeDescr td, ParserStateMachine * p_psm);
|
||||
/** update state machine for type emitted by nested ssm **/
|
||||
static void on_parsed_type(DIfElseSsm & self, obj<AType> type, ParserStateMachine * p_psm);
|
||||
/** operate state machine for formal emitted by nested ssm **/
|
||||
static void on_parsed_formal(DIfElseSsm & 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(DIfElseSsm & 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(DIfElseSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for nested parsed expression @p expr **/
|
||||
static void on_parsed_expression(DIfElseSsm & 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(DIfElseSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for nested quoted literal @p lit **/
|
||||
static void on_quoted_literal(DIfElseSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
Loading…
Add table
Add a link
Reference in a new issue