xo-interpreter2 stack: handle operator expressions w/ qliterals
This commit is contained in:
parent
3f8be97290
commit
906bb2a913
24 changed files with 942 additions and 51 deletions
|
|
@ -76,6 +76,14 @@ namespace xo {
|
|||
void on_leftbrace_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on quote token @p tk,
|
||||
* with overall parser state in @p p_psm.
|
||||
*
|
||||
* Starts nested {progress-ssm, quote-ssm} combination.
|
||||
**/
|
||||
void on_quote_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** step state machine for this syntax on incoming boolean literal token @p tkk
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
|
|
@ -160,6 +168,15 @@ namespace xo {
|
|||
const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
#ifdef NOT_YET
|
||||
/** update state for literal @p lit with overall state in @p p_psm.
|
||||
* wraps literal as constant-expr + starts progress-ssm for possible
|
||||
* operator expression.
|
||||
**/
|
||||
void on_quoted_literal(obj<AGCObject> lit,
|
||||
ParserStateMachine * p_psm);
|
||||
#endif
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-define-printable-facet printable facet methods **/
|
||||
///@{
|
||||
|
|
|
|||
143
include/xo/reader2/DExpectQLiteralSsm.hpp
Normal file
143
include/xo/reader2/DExpectQLiteralSsm.hpp
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/** @file DExpectQLiteralSsm.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Mar 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DSyntaxStateMachine.hpp"
|
||||
//#include <xo/object2/DArray.hpp>
|
||||
//#include <xo/arena/DArena.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
#ifdef NOT_USING
|
||||
/**
|
||||
* Already in quoted-literal context
|
||||
*
|
||||
* #q{ }
|
||||
* ^
|
||||
* qliteral_0
|
||||
*
|
||||
* qliteral_0 --on_leftparen_token()--> push QuotedListSsm
|
||||
**/
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @class expect_formal_arglist
|
||||
* @brief parser state-machine for a formal parameter list
|
||||
**/
|
||||
class DExpectQLiteralSsm : public DSyntaxStateMachine<DExpectQLiteralSsm> {
|
||||
public:
|
||||
using Super = DSyntaxStateMachine<DExpectQLiteralSsm>;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using DArena = xo::mm::DArena;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
using size_type = std::uint32_t;
|
||||
|
||||
public:
|
||||
DExpectQLiteralSsm();
|
||||
|
||||
/** create instance, using memory from @parser_mm **/
|
||||
static obj<ASyntaxStateMachine,DExpectQLiteralSsm> make(DArena & parser_mm);
|
||||
static DExpectQLiteralSsm * _make(DArena & parser_mm);
|
||||
|
||||
/** start nested syntax for a quoted literal **/
|
||||
static void start(ParserStateMachine * p_psm);
|
||||
|
||||
/** @defgroup scm-expectformalarglistssm-methods general methods **/
|
||||
///@{
|
||||
|
||||
static const char * ssm_classname() { return "DExpectQLiteralSsm"; }
|
||||
|
||||
/** update state for f64 token @p tk, with overall parser state in @p p_psm.
|
||||
* delegates to parent ssm via @ref on_quoted_literal
|
||||
**/
|
||||
void on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state on incoming token @p tk, with overall parser state in @p p_psm **/
|
||||
void on_leftparen_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state on incoming token @p tk, with overall parser state in @p p_psm **/
|
||||
void on_comma_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state on incoming rightparen token @p tk, with overall parser state in @p p_psm **/
|
||||
void on_rightparen_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,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-expectformalarglistssm-printable-facet printable facet methods **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgroup scm-expectformalarglistssm-impl-methods **/
|
||||
///@{
|
||||
|
||||
/** update local state to include parsed formal (param_name, param_type).
|
||||
* If stack memory needed, get from @p parser_alloc.
|
||||
* Lifetime until formal arglist completely parsed
|
||||
**/
|
||||
void _accept_formal(obj<AAllocator> expr_alloc,
|
||||
DArena & parser_alloc,
|
||||
const DUniqueString * param_name,
|
||||
TypeDescr param_type);
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
#ifdef NOT_USING
|
||||
/** parsing state-machine state **/
|
||||
formalarglstatetype fastate_ = formalarglstatetype::argl_0;
|
||||
/** populate with (parameter-name, parameter-type) list
|
||||
* as they're encountered.
|
||||
*
|
||||
* Not using flexible array here since we don't know size at construction time
|
||||
**/
|
||||
DArray * argl_ = nullptr;
|
||||
#endif
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DExpectQLiteralSsm.hpp */
|
||||
|
|
@ -100,6 +100,13 @@ namespace xo {
|
|||
/** @defgroup scm-parenssm-admin-methods admin methods **/
|
||||
///@{
|
||||
|
||||
/** update ssm for incoming quote token @p tk.
|
||||
* with overall parser state in @p p_psm.
|
||||
* advances from quote_0 -> quote_1. Otherwise error
|
||||
**/
|
||||
void on_quote_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update ssm state for incoming leftparen token @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
|
|
@ -129,17 +136,9 @@ namespace xo {
|
|||
/** update ssm for expression @p expr (emitted by nested ssm),
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_parsed_expression(obj<AExpression> expr,
|
||||
void on_quoted_literal(obj<AGCObject> literal,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update ssm for expression @p expr (emitted by nested ssm)
|
||||
* that's immediately followed by token @p tk
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psmn);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-parenssm-printable-facet printable facet methods **/
|
||||
///@{
|
||||
|
|
|
|||
|
|
@ -119,6 +119,11 @@ namespace xo {
|
|||
**/
|
||||
void on_leftparen_token(const Token & tk, ParserStateMachine * p_psm);
|
||||
|
||||
/** update ssm for incoming quote token @p tk, overall parser state in @p p_psm
|
||||
* starts nested syntax for quoted literal
|
||||
**/
|
||||
void on_quote_token(const Token & tk, ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on parsed expression @p expr
|
||||
* from nested ssm.
|
||||
* overall parser state in @p p_psm
|
||||
|
|
|
|||
12
include/xo/reader2/ExpectQLiteralSsm.hpp
Normal file
12
include/xo/reader2/ExpectQLiteralSsm.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/** @file ExpectQLiteralSsm.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Mar 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DExpectQLiteralSsm.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_DExpectQLiteralSsm.hpp"
|
||||
#include "ssm/IPrintable_DExpectQLiteralSsm.hpp"
|
||||
|
||||
/* end ExpectQLiteralSsm.hpp */
|
||||
|
|
@ -186,6 +186,9 @@ namespace xo {
|
|||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk);
|
||||
|
||||
/** update state to consume quoted literal @p lit **/
|
||||
void on_quoted_literal(obj<AGCObject> lit);
|
||||
|
||||
/** update state to respond to input token @p tk.
|
||||
* record output (if any) in @ref result_
|
||||
**/
|
||||
|
|
|
|||
62
include/xo/reader2/ssm/IPrintable_DExpectQLiteralSsm.hpp
Normal file
62
include/xo/reader2/ssm/IPrintable_DExpectQLiteralSsm.hpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DExpectQLiteralSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DExpectQLiteralSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DExpectQLiteralSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DExpectQLiteralSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DExpectQLiteralSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DExpectQLiteralSsm>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DExpectQLiteralSsm,
|
||||
xo::scm::IPrintable_DExpectQLiteralSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DExpectQLiteralSsm
|
||||
**/
|
||||
class IPrintable_DExpectQLiteralSsm {
|
||||
public:
|
||||
/** @defgroup scm-printable-dexpectqliteralssm-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dexpectqliteralssm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DExpectQLiteralSsm & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
/** @file ISyntaxStateMachine_DExpectQLiteralSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISyntaxStateMachine_DExpectQLiteralSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISyntaxStateMachine_DExpectQLiteralSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_Xfer.hpp"
|
||||
#include "DExpectQLiteralSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class ISyntaxStateMachine_DExpectQLiteralSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::ASyntaxStateMachine,
|
||||
xo::scm::DExpectQLiteralSsm>
|
||||
{
|
||||
using ImplType = xo::scm::ISyntaxStateMachine_Xfer
|
||||
<xo::scm::DExpectQLiteralSsm,
|
||||
xo::scm::ISyntaxStateMachine_DExpectQLiteralSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class ISyntaxStateMachine_DExpectQLiteralSsm
|
||||
**/
|
||||
class ISyntaxStateMachine_DExpectQLiteralSsm {
|
||||
public:
|
||||
/** @defgroup scm-syntaxstatemachine-dexpectqliteralssm-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-dexpectqliteralssm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** identify a type of syntax state machine **/
|
||||
static syntaxstatetype ssm_type(const DExpectQLiteralSsm & self) noexcept;
|
||||
/** text describing expected/allowed input to this ssm in current state **/
|
||||
static std::string_view get_expect_str(const DExpectQLiteralSsm & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** operate state machine for incoming token @p tk **/
|
||||
static void on_token(DExpectQLiteralSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DExpectQLiteralSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
static void on_parsed_typedescr(DExpectQLiteralSsm & self, TypeDescr td, ParserStateMachine * p_psm);
|
||||
/** operate state machine for formal emitted by nested ssm **/
|
||||
static void on_parsed_formal(DExpectQLiteralSsm & 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(DExpectQLiteralSsm & 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(DExpectQLiteralSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for nested parsed expression @p expr **/
|
||||
static void on_parsed_expression(DExpectQLiteralSsm & 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(DExpectQLiteralSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for nested quoted literal @p lit **/
|
||||
static void on_quoted_literal(DExpectQLiteralSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -60,6 +60,9 @@ namespace xo {
|
|||
/** expecting a rhs expression. See @ref DExpectExprSsm **/
|
||||
expect_rhs_expression,
|
||||
|
||||
/** expecting a quoted literal. See @ref DExpectQLiteralSsm **/
|
||||
expect_qliteral,
|
||||
|
||||
/** comes lasts, counts number of valid enums **/
|
||||
N
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue