xo-reader2: + DExpectFormalArglistSsm [WIP]
This commit is contained in:
parent
fdf2cc8439
commit
254d7c179d
18 changed files with 899 additions and 8 deletions
146
include/xo/reader2/DExpectFormalArglistSsm.hpp
Normal file
146
include/xo/reader2/DExpectFormalArglistSsm.hpp
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/** @file DExpectFormalArglistSsm.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Aug 2024
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include <xo/object2/DArray.hpp>
|
||||
#include <xo/arena/DArena.hpp>
|
||||
|
||||
#ifdef NOT_YET
|
||||
#include "exprstate.hpp"
|
||||
#include "formal_arg.hpp"
|
||||
#include <vector>
|
||||
#endif
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/**
|
||||
* ( name(1) : type(1) , ..., )
|
||||
* ^ ^ ^ ^ ^
|
||||
* | | | | |
|
||||
* | | | | argl_1b
|
||||
* | argl_1a | argl_1a
|
||||
* argl_0 argl_1b
|
||||
*
|
||||
* argl_0 --on_leftparen_token()--> argl_1a
|
||||
* argl_1a --on_formal()--> argl_1b
|
||||
* argl_1b -+-on_comma_token()--> argl_1a
|
||||
* \-on_rightparen_token()--> (done)
|
||||
**/
|
||||
enum class formalarglstatetype {
|
||||
invalid = -1,
|
||||
|
||||
argl_0,
|
||||
argl_1a,
|
||||
argl_1b,
|
||||
|
||||
n_formalarglstatetype,
|
||||
};
|
||||
|
||||
extern const char *
|
||||
formalarglstatetype_descr(formalarglstatetype x);
|
||||
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os, formalarglstatetype x) {
|
||||
os << formalarglstatetype_descr(x);
|
||||
return os;
|
||||
}
|
||||
|
||||
/** @class expect_formal_arglist
|
||||
* @brief parser state-machine for a formal parameter list
|
||||
**/
|
||||
class DExpectFormalArglistSsm {
|
||||
public:
|
||||
using DArena = xo::mm::DArena;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
using size_type = std::uint32_t;
|
||||
|
||||
public:
|
||||
DExpectFormalArglistSsm(DArray * argl);
|
||||
|
||||
/** create instance, using memory from @parser_mm **/
|
||||
static obj<ASyntaxStateMachine,DExpectFormalArglistSsm> make(DArena & parser_mm);
|
||||
static DExpectFormalArglistSsm * _make(DArena & parser_mm);
|
||||
|
||||
static void start(ParserStateMachine * p_psm);
|
||||
|
||||
/** @defgroup scm-expectformalarglistssm-ssm-facet syntaxstatemachine facet methods **/
|
||||
///@{
|
||||
|
||||
/** identifies the ssm implemented here **/
|
||||
syntaxstatetype ssm_type() const noexcept;
|
||||
|
||||
std::string_view get_expect_str() const;
|
||||
|
||||
/** 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_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,
|
||||
parserstatemachine * p_psm) override;
|
||||
virtual void on_rightparen_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
#endif
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-expectformalarglistssm-printable-facet printable facet methods **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** parsing state-machine state **/
|
||||
formalarglstatetype fastate_ = formalarglstatetype::argl_0;
|
||||
/** number of formal parameters encountered.
|
||||
* Invariant: n_args_ <= argl_->size()
|
||||
**/
|
||||
size_type n_args_ = 0;
|
||||
/** populate with (parmaeter-name, parameter-type) list
|
||||
* as they're encountered.
|
||||
*
|
||||
* Not using flexible array here since we don't know size
|
||||
**/
|
||||
DArray * argl_ = nullptr;
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DExpectFormalArglistSsm.hpp */
|
||||
|
|
@ -81,6 +81,11 @@ namespace xo {
|
|||
**/
|
||||
void on_def_token(const Token & tk, ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming lamdba token @p tk,
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_lambda_token(const Token & tk, ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming token @p tk,
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ namespace xo {
|
|||
public:
|
||||
//using DSymbolTable = xo::scm::DSymbolTable;
|
||||
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;
|
||||
|
|
@ -81,6 +82,12 @@ namespace xo {
|
|||
|
||||
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);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-lambdassm-syntaxstatemachine-facet **/
|
||||
///@{
|
||||
|
|
@ -124,8 +131,6 @@ namespace xo {
|
|||
#ifdef NOT_YET
|
||||
virtual const char * get_expect_str() const override;
|
||||
|
||||
virtual void on_lambda_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
virtual void on_typedescr(TypeDescr td,
|
||||
parserstatemachine * p_psm) override;
|
||||
virtual void on_formal_arglist(const std::vector<rp<Variable>> & argl,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DExpectFormalArglistSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DExpectFormalArglistSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DExpectFormalArglistSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DExpectFormalArglistSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DExpectFormalArglistSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DExpectFormalArglistSsm>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DExpectFormalArglistSsm,
|
||||
xo::scm::IPrintable_DExpectFormalArglistSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DExpectFormalArglistSsm
|
||||
**/
|
||||
class IPrintable_DExpectFormalArglistSsm {
|
||||
public:
|
||||
/** @defgroup scm-printable-dexpectformalarglistssm-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dexpectformalarglistssm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DExpectFormalArglistSsm & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/** @file ISyntaxStateMachine_DExpectFormalArglistSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISyntaxStateMachine_DExpectFormalArglistSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISyntaxStateMachine_DExpectFormalArglistSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_Xfer.hpp"
|
||||
#include "DExpectFormalArglistSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class ISyntaxStateMachine_DExpectFormalArglistSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::ASyntaxStateMachine,
|
||||
xo::scm::DExpectFormalArglistSsm>
|
||||
{
|
||||
using ImplType = xo::scm::ISyntaxStateMachine_Xfer
|
||||
<xo::scm::DExpectFormalArglistSsm,
|
||||
xo::scm::ISyntaxStateMachine_DExpectFormalArglistSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class ISyntaxStateMachine_DExpectFormalArglistSsm
|
||||
**/
|
||||
class ISyntaxStateMachine_DExpectFormalArglistSsm {
|
||||
public:
|
||||
/** @defgroup scm-syntaxstatemachine-dexpectformalarglistssm-type-traits **/
|
||||
///@{
|
||||
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
|
||||
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
|
||||
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-syntaxstatemachine-dexpectformalarglistssm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** identify a type of syntax state machine **/
|
||||
static syntaxstatetype ssm_type(const DExpectFormalArglistSsm & self) noexcept;
|
||||
/** text describing expected/allowed input to this ssm in current state **/
|
||||
static std::string_view get_expect_str(const DExpectFormalArglistSsm & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** operate state machine for incoming token @p tk **/
|
||||
static void on_token(DExpectFormalArglistSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DExpectFormalArglistSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
static void on_parsed_typedescr(DExpectFormalArglistSsm & self, TypeDescr td, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DExpectFormalArglistSsm & 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(DExpectFormalArglistSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -21,6 +21,9 @@ namespace xo {
|
|||
/** toplevel of some translation unit. See @ref DExprSeqState **/
|
||||
expect_toplevel_expression_sequence,
|
||||
|
||||
/** expecting a formal argument list (sub-syntax within lambda-expression) **/
|
||||
expect_formal_arglist,
|
||||
|
||||
/** expecting a s symbol. See @ref DExpectSymbolSsm **/
|
||||
expect_symbol,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue