xo-reader2: + DExpectFormalArgSsm [WIP]
This commit is contained in:
parent
254d7c179d
commit
66158551c7
12 changed files with 679 additions and 16 deletions
139
include/xo/reader2/DExpectFormalArgSsm.hpp
Normal file
139
include/xo/reader2/DExpectFormalArgSsm.hpp
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/** @file DExpectFormalSsm.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Aug 2024
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
//#include <xo/arena/DArena.hpp>
|
||||
//#include "exprstate.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/**
|
||||
* name : type
|
||||
* ^ ^ ^
|
||||
* | | formal_2
|
||||
* | formal_1
|
||||
* formal_0
|
||||
*
|
||||
* formal_0 --on_symbol()--> formal_1
|
||||
* formal_1 --on_colon_token()--> formal_2
|
||||
* formal_2 --on_typedescr()--> (done)
|
||||
**/
|
||||
enum class formalstatetype {
|
||||
invalid = -1,
|
||||
|
||||
formal_0,
|
||||
formal_1,
|
||||
formal_2,
|
||||
|
||||
n_formalstatetype,
|
||||
};
|
||||
|
||||
extern const char *
|
||||
formalstatetype_descr(formalstatetype x);
|
||||
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os, formalstatetype x) {
|
||||
os << formalstatetype_descr(x);
|
||||
return os;
|
||||
}
|
||||
|
||||
/** @class expect_formal_xs
|
||||
* @brief parser state-machine for a typed formal parameter
|
||||
**/
|
||||
class DExpectFormalArgSsm {
|
||||
public:
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using DArena = xo::mm::DArena;
|
||||
|
||||
public:
|
||||
DExpectFormalArgSsm();
|
||||
|
||||
/** create empty instance using memory from @p mm **/
|
||||
DExpectFormalArgSsm * _make(DArena & mm);
|
||||
|
||||
static void start(ParserStateMachine * p_psm);
|
||||
|
||||
/** @defgroup scm-expectformalargssm-ssm-facet syntaxstatemachine facet methods **/
|
||||
///@{
|
||||
|
||||
/** identifies the ssm implemented here **/
|
||||
syntaxstatetype ssm_type() const noexcept;
|
||||
|
||||
/** mnemonic for expected input (for this ssm) in current state **/
|
||||
std::string_view get_expect_str() const noexcept;
|
||||
|
||||
/** update state on incoming token @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state on parsed symbol @p sym emitted by nested ssm,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_parsed_symbol(std::string_view sym,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state on parsed typedescr @p td emitted by nested ssm,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_parsed_typedescr(TypeDescr td,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state on parsed expression emitted by nested ssm
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_parsed_expression(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state on parsed expression, along with following semicolon,
|
||||
* emitted by nested ssm with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef NOT_YET
|
||||
|
||||
virtual void on_symbol(const std::string & symbol_name,
|
||||
parserstatemachine * p_psm) override;
|
||||
|
||||
virtual void on_colon_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
|
||||
// virtual void on_comma_token(...) override;
|
||||
|
||||
#ifdef PROBABLY_NOT
|
||||
virtual void on_rightparen_token(const token_type & tk,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr) override;
|
||||
#endif
|
||||
|
||||
virtual void on_typedescr(TypeDescr td,
|
||||
parserstatemachine * p_psm) override;
|
||||
|
||||
virtual void print(std::ostream & os) const override;
|
||||
|
||||
private:
|
||||
static std::unique_ptr<expect_formal_xs> make();
|
||||
#endif
|
||||
|
||||
private:
|
||||
/** parsing state-machine state **/
|
||||
formalstatetype fstate_ = formalstatetype::formal_0;
|
||||
|
||||
/** formal parameter name **/
|
||||
const DUniqueString * name_ = nullptr;
|
||||
|
||||
/** formal parameter type (if specified) **/
|
||||
TypeDescr td_ = nullptr;
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DExpectFormalArgSsm.hpp */
|
||||
|
|
@ -68,12 +68,21 @@ namespace xo {
|
|||
|
||||
static void start(ParserStateMachine * p_psm);
|
||||
|
||||
/** @defgroup scm-expectformalarglistssm-methods general methods **/
|
||||
///@{
|
||||
|
||||
/** update state on incoming token @p tk, with overall parser state in @p psm **/
|
||||
void on_leftparen_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-expectformalarglistssm-ssm-facet syntaxstatemachine facet methods **/
|
||||
///@{
|
||||
|
||||
/** identifies the ssm implemented here **/
|
||||
syntaxstatetype ssm_type() const noexcept;
|
||||
|
||||
/** mnemonic for expected input (for this ssm) in current state **/
|
||||
std::string_view get_expect_str() const;
|
||||
|
||||
/** update state on incoming token @p tk,
|
||||
|
|
@ -108,8 +117,6 @@ namespace xo {
|
|||
|
||||
#ifdef NOT_YET
|
||||
|
||||
virtual void on_leftparen_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
virtual void on_formal(const rp<Variable> & formal,
|
||||
parserstatemachine * p_psm) override;
|
||||
virtual void on_comma_token(const token_type & tk,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
/** @file ISyntaxStateMachine_DExpectFormalArgSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISyntaxStateMachine_DExpectFormalArgSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISyntaxStateMachine_DExpectFormalArgSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_Xfer.hpp"
|
||||
#include "DExpectFormalArgSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class ISyntaxStateMachine_DExpectFormalArgSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::ASyntaxStateMachine,
|
||||
xo::scm::DExpectFormalArgSsm>
|
||||
{
|
||||
using ImplType = xo::scm::ISyntaxStateMachine_Xfer
|
||||
<xo::scm::DExpectFormalArgSsm,
|
||||
xo::scm::ISyntaxStateMachine_DExpectFormalArgSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class ISyntaxStateMachine_DExpectFormalArgSsm
|
||||
**/
|
||||
class ISyntaxStateMachine_DExpectFormalArgSsm {
|
||||
public:
|
||||
/** @defgroup scm-syntaxstatemachine-dexpectformalargssm-type-traits **/
|
||||
///@{
|
||||
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
|
||||
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
|
||||
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-syntaxstatemachine-dexpectformalargssm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** identify a type of syntax state machine **/
|
||||
static syntaxstatetype ssm_type(const DExpectFormalArgSsm & self) noexcept;
|
||||
/** text describing expected/allowed input to this ssm in current state **/
|
||||
static std::string_view get_expect_str(const DExpectFormalArgSsm & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** operate state machine for incoming token @p tk **/
|
||||
static void on_token(DExpectFormalArgSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DExpectFormalArgSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
static void on_parsed_typedescr(DExpectFormalArgSsm & self, TypeDescr td, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DExpectFormalArgSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DExpectFormalArgSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -24,6 +24,9 @@ namespace xo {
|
|||
/** expecting a formal argument list (sub-syntax within lambda-expression) **/
|
||||
expect_formal_arglist,
|
||||
|
||||
/** expecting a formal argument (sub-syntax within formal-arglist) **/
|
||||
expect_formal_arg,
|
||||
|
||||
/** expecting a s symbol. See @ref DExpectSymbolSsm **/
|
||||
expect_symbol,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue