xo-reader2: refactor: move Lambda genfacet files to subdirs
This commit is contained in:
parent
afe34f1d8a
commit
309af002d2
10 changed files with 17 additions and 16 deletions
213
include/xo/reader2/lambda/DLambdaSsm.hpp
Normal file
213
include/xo/reader2/lambda/DLambdaSsm.hpp
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
/** @file DLambdaSsm.hpp
|
||||
*
|
||||
* Author: Roland Conybeare
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DSyntaxStateMachine.hpp"
|
||||
#include <xo/expression2/DLambdaExpr.hpp>
|
||||
#include <xo/expression2/SymbolTable.hpp>
|
||||
//#include <xo/expression2/DLocalSymtab.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
class ParserStateMachine;
|
||||
|
||||
/**
|
||||
* @text
|
||||
*
|
||||
* lambda ( name(1) : type(1), ..., ) : type body-expr ;
|
||||
* ^ ^ ^ ^ ^ ^
|
||||
* | | | | lm_4 lm_5
|
||||
* | | | lm_3
|
||||
* lm_0 lm_1 lm_2
|
||||
*
|
||||
* lm_0 --on_lambda_token()--> lm_1
|
||||
* lm_1 --on_formal_arglist()--> lm_2
|
||||
* lm_2 --on_expr()--> lm_3
|
||||
* lm_5 --on_semicolon_token()--> (done)
|
||||
*
|
||||
* @endtext
|
||||
**/
|
||||
enum class lambdastatetype {
|
||||
invalid = -1,
|
||||
|
||||
lm_0,
|
||||
lm_1,
|
||||
lm_2,
|
||||
lm_3,
|
||||
lm_4,
|
||||
lm_5,
|
||||
|
||||
n_lambdastatetype
|
||||
};
|
||||
|
||||
extern const char *
|
||||
lambdastatetype_descr(lambdastatetype x);
|
||||
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os, lambdastatetype x) {
|
||||
os << lambdastatetype_descr(x);
|
||||
return os;
|
||||
}
|
||||
|
||||
/** @class DLambdaSsm
|
||||
* @brief parsing state-machine for a lambda-expression
|
||||
**/
|
||||
class DLambdaSsm : public DSyntaxStateMachine<DLambdaSsm> {
|
||||
public:
|
||||
using Super = DSyntaxStateMachine<DLambdaSsm>;
|
||||
using DLocalSymtab = xo::scm::DLocalSymtab;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using DArena = xo::mm::DArena;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
public:
|
||||
/** @defgroup scm-lambdassm-ctors **/
|
||||
///@{
|
||||
|
||||
DLambdaSsm();
|
||||
|
||||
/** create instance using memory from @p parser_mm **/
|
||||
static obj<ASyntaxStateMachine,DLambdaSsm> make(DArena & parser_mm);
|
||||
|
||||
/** create instance using memory from @p parser_mm **/
|
||||
static DLambdaSsm * _make(DArena & parser_mm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-lambdassm-methods **/
|
||||
///@{
|
||||
|
||||
static const char * ssm_classname() { return "DLambdaSsm"; }
|
||||
|
||||
static void start(ParserStateMachine * p_psm);
|
||||
|
||||
/** update ssm on lambda keyword token @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_lambda_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update ssm on yield token @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_yields_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update ssm on leftbrace token @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_leftbrace_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-lambdassm-syntaxstatemachine-facet **/
|
||||
///@{
|
||||
|
||||
/** identify this nested 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;
|
||||
|
||||
/** update this ssm for incoming token @p tk **/
|
||||
void on_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
#ifdef OBSOLETE
|
||||
/** update this ssm when nested parser
|
||||
* emits @p td.
|
||||
**/
|
||||
void on_parsed_symbol(std::string_view sym,
|
||||
ParserStateMachine * p_psm);
|
||||
#endif
|
||||
|
||||
/** update this ssm when nested parser
|
||||
* emits @p td.
|
||||
**/
|
||||
void on_parsed_typedescr(TypeDescr td,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
#ifdef OBSOLETE
|
||||
/** update this ssm to consume parsed formal (name,value)
|
||||
* from nested (and now expired) ssm
|
||||
**/
|
||||
void on_parsed_formal(const DUniqueString * sym,
|
||||
TypeDescr td,
|
||||
ParserStateMachine * p_psm);
|
||||
#endif
|
||||
|
||||
/** consume formal params @p arglist from completed nested ssm,
|
||||
* with overall parser state in @p p_psm.
|
||||
**/
|
||||
void on_parsed_formal_arglist(DArray * arglist,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update this ssm when nested parser
|
||||
* emits expression @p expr
|
||||
**/
|
||||
void on_parsed_expression(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update this ssm when nested parser
|
||||
* emits expression @p expr
|
||||
**/
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
#ifdef NOT_YET
|
||||
virtual const char * get_expect_str() const override;
|
||||
|
||||
virtual void on_leftbrace_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
virtual void on_colon_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
virtual void on_semicolon_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
virtual void on_f64_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) final override;
|
||||
|
||||
virtual void print(std::ostream & os) const override;
|
||||
virtual bool pretty_print(const print::ppindentinfo & ppii) const override;
|
||||
#endif
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-lambdassm-printable-facet **/
|
||||
///@{
|
||||
|
||||
/** pretty-printing support **/
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
|
||||
|
||||
private:
|
||||
/** parsing state-machine state **/
|
||||
lambdastatetype lmstate_ = lambdastatetype::lm_0;
|
||||
|
||||
/** lambda environment (for formal parameters) **/
|
||||
DLocalSymtab * local_symtab_ = nullptr;
|
||||
|
||||
/** explicit return type (if supplied) **/
|
||||
TypeDescr explicit_return_td_ = nullptr;
|
||||
|
||||
/** lambda signature (when known) **/
|
||||
TypeDescr lambda_td_ = nullptr;
|
||||
|
||||
/** body expression **/
|
||||
obj<AExpression> body_;
|
||||
|
||||
/** parent environment **/
|
||||
obj<ASymbolTable> parent_symtab_;
|
||||
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DLambdaSsm.hpp */
|
||||
62
include/xo/reader2/lambda/IPrintable_DLambdaSsm.hpp
Normal file
62
include/xo/reader2/lambda/IPrintable_DLambdaSsm.hpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DLambdaSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DLambdaSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DLambdaSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DLambdaSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DLambdaSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DLambdaSsm>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DLambdaSsm,
|
||||
xo::scm::IPrintable_DLambdaSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DLambdaSsm
|
||||
**/
|
||||
class IPrintable_DLambdaSsm {
|
||||
public:
|
||||
/** @defgroup scm-printable-dlambdassm-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dlambdassm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DLambdaSsm & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
84
include/xo/reader2/lambda/ISyntaxStateMachine_DLambdaSsm.hpp
Normal file
84
include/xo/reader2/lambda/ISyntaxStateMachine_DLambdaSsm.hpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/** @file ISyntaxStateMachine_DLambdaSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISyntaxStateMachine_DLambdaSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISyntaxStateMachine_DLambdaSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_Xfer.hpp"
|
||||
#include "DLambdaSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class ISyntaxStateMachine_DLambdaSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::ASyntaxStateMachine,
|
||||
xo::scm::DLambdaSsm>
|
||||
{
|
||||
using ImplType = xo::scm::ISyntaxStateMachine_Xfer
|
||||
<xo::scm::DLambdaSsm,
|
||||
xo::scm::ISyntaxStateMachine_DLambdaSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class ISyntaxStateMachine_DLambdaSsm
|
||||
**/
|
||||
class ISyntaxStateMachine_DLambdaSsm {
|
||||
public:
|
||||
/** @defgroup scm-syntaxstatemachine-dlambdassm-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-dlambdassm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** identify a type of syntax state machine **/
|
||||
static syntaxstatetype ssm_type(const DLambdaSsm & self) noexcept;
|
||||
/** text describing expected/allowed input to this ssm in current state **/
|
||||
static std::string_view get_expect_str(const DLambdaSsm & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** operate state machine for incoming token @p tk **/
|
||||
static void on_token(DLambdaSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DLambdaSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
static void on_parsed_typedescr(DLambdaSsm & self, TypeDescr td, ParserStateMachine * p_psm);
|
||||
/** update state machine for type emitted by nested ssm **/
|
||||
static void on_parsed_type(DLambdaSsm & self, obj<AType> type, ParserStateMachine * p_psm);
|
||||
/** operate state machine for formal emitted by nested ssm **/
|
||||
static void on_parsed_formal(DLambdaSsm & 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(DLambdaSsm & 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(DLambdaSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for nested parsed expression @p expr **/
|
||||
static void on_parsed_expression(DLambdaSsm & 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(DLambdaSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for nested quoted literal @p lit **/
|
||||
static void on_quoted_literal(DLambdaSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
Loading…
Add table
Add a link
Reference in a new issue