xo-reader2 stack: parenthesized expressions [WIP]
This commit is contained in:
parent
0170b8dacf
commit
add1b018ac
24 changed files with 1095 additions and 35 deletions
|
|
@ -6,7 +6,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "DSyntaxStateMachine.hpp"
|
||||
//#include "SyntaxStateMachine.hpp"
|
||||
#include "syntaxstatetype.hpp"
|
||||
#include <xo/expression2/detail/IExpression_DDefineExpr.hpp>
|
||||
#include <xo/expression2/DDefineExpr.hpp>
|
||||
|
|
@ -36,7 +35,7 @@ namespace xo {
|
|||
* --on_singleassign_token()--> def_5
|
||||
* def_3 --on_typedescr()--> def_4
|
||||
* def_4 --on_singleassign_token()--> def_5
|
||||
* def_5 --on_expr()--> def_6
|
||||
* def_5 --on_parsed_expression()--> def_6
|
||||
* def_6 --on_semicolon_token()--> (done)
|
||||
*
|
||||
* def_1:expect_symbol: got 'def' keyword, symbol to follow
|
||||
|
|
@ -104,9 +103,10 @@ namespace xo {
|
|||
/** @defgroup scm-definessm-access-methods **/
|
||||
///@{
|
||||
|
||||
/** identify this nested state machine **/
|
||||
static const char * ssm_classname() { return "DDefineSsm"; }
|
||||
|
||||
/** identify this nested state machine **/
|
||||
/** internal state **/
|
||||
defexprstatetype defstate() const noexcept { return defstate_; }
|
||||
|
||||
///@}
|
||||
|
|
@ -193,6 +193,9 @@ namespace xo {
|
|||
///@}
|
||||
|
||||
private:
|
||||
/** @defgroup scm-definessm-member-vars **/
|
||||
///@{
|
||||
|
||||
/** identify define-expression state **/
|
||||
defexprstatetype defstate_;
|
||||
|
||||
|
|
@ -200,6 +203,8 @@ namespace xo {
|
|||
* This will eventually be the output of this ssm
|
||||
**/
|
||||
obj<AExpression,DDefineExpr> def_expr_;
|
||||
|
||||
///@}
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -76,6 +76,12 @@ namespace xo {
|
|||
void on_string_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming lambda token @p tk,
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_lambda_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-expectexpr-ssm-facet syntaxstatemachine facet methods **/
|
||||
///@{
|
||||
|
|
|
|||
|
|
@ -113,6 +113,11 @@ namespace xo {
|
|||
**/
|
||||
void on_bool_token(const Token & tk, ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming leftparen token @p tk,
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_leftparen_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
|
||||
|
|
|
|||
|
|
@ -96,6 +96,12 @@ namespace xo {
|
|||
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 **/
|
||||
///@{
|
||||
|
|
|
|||
127
xo-reader2/include/xo/reader2/DParenSsm.hpp
Normal file
127
xo-reader2/include/xo/reader2/DParenSsm.hpp
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/** @file DParenSsm.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DSyntaxStateMachine.hpp"
|
||||
#include "syntaxstatetype.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <string_view>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/**
|
||||
* @pre
|
||||
*
|
||||
* ( x * x )
|
||||
* ^ ^ ^ ^
|
||||
* | | | (done)
|
||||
* | | |
|
||||
* | | lparen_2
|
||||
* | lparen_1:expect expr
|
||||
* lparen_0
|
||||
*
|
||||
* lparen_0 --on_leftparen_token()--> lparen_1
|
||||
* lparen_1 --on_parsed_expression()--> lparen_2
|
||||
* lparen_2 --on_rightparen_token()--> (done)
|
||||
*
|
||||
* @endpre
|
||||
**/
|
||||
|
||||
enum class parenexprstatetype {
|
||||
invalid = -1,
|
||||
|
||||
lparen_0,
|
||||
lparen_1,
|
||||
lparen_2,
|
||||
|
||||
N,
|
||||
};
|
||||
|
||||
extern const char * parenexprstatetype_descr(parenexprstatetype x);
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream & os, parenexprstatetype x);
|
||||
|
||||
class DParenSsm : public DSyntaxStateMachine<DParenSsm> {
|
||||
public:
|
||||
using Super = DSyntaxStateMachine<DParenSsm>;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using DArena = xo::mm::DArena;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
public:
|
||||
/** @defgroup scm-parenssm-ctors **/
|
||||
///@{
|
||||
|
||||
DParenSsm();
|
||||
|
||||
/** create instance using memory from @p parser_mm
|
||||
**/
|
||||
static DParenSsm * make(DArena & parser_mm);
|
||||
|
||||
/** push DParenSsm instance onto @p p_psm stack **/
|
||||
static void start(ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-parenssm-access-methods **/
|
||||
///@{
|
||||
|
||||
/** identify this nested state machine **/
|
||||
static const char * ssm_classname() { return "DParenSsm"; }
|
||||
|
||||
/** internal state **/
|
||||
parenexprstatetype parenstate() const noexcept { return parenstate_; }
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-parenssm-admin-methods admin methods **/
|
||||
///@{
|
||||
|
||||
/** update ssm state for incoming leftparen token @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_leftparen_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-parenssm-ssm-facet syntaxstatemachine facet methods **/
|
||||
///@{
|
||||
|
||||
/** identifies this ssm **/
|
||||
syntaxstatetype ssm_type() const noexcept;
|
||||
|
||||
/** text describing expected/allowed input to this ssm in current state. **/
|
||||
std::string_view get_expect_str() const noexcept;
|
||||
|
||||
/** update ssm for token @p tk, with overall state in @p p_psm **/
|
||||
void on_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-parenssm-printable-facet printable facet methods **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgroup scm-parenssm-member-vars **/
|
||||
///@{
|
||||
|
||||
/** identify paren-expression state **/
|
||||
parenexprstatetype parenstate_;
|
||||
/** scaffold expression (representing parenthesized value) here **/
|
||||
obj<AExpression> expr_;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DParenSsm.hpp */
|
||||
10
xo-reader2/include/xo/reader2/LambdaSsm.hpp
Normal file
10
xo-reader2/include/xo/reader2/LambdaSsm.hpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/** @file LambdaSsm.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "DLambdaSsm.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_DLambdaSsm.hpp"
|
||||
#include "ssm/IPrintable_DLambdaSsm.hpp"
|
||||
|
||||
/* end LambdaSsm.hpp */
|
||||
12
xo-reader2/include/xo/reader2/ParenSsm.hpp
Normal file
12
xo-reader2/include/xo/reader2/ParenSsm.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/** @file ParenSsm.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DParenSsm.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_DParenSsm.hpp"
|
||||
#include "ssm/IPrintable_DParenSsm.hpp"
|
||||
|
||||
/* end ParenSsm.hpp */
|
||||
62
xo-reader2/include/xo/reader2/ssm/IPrintable_DParenSsm.hpp
Normal file
62
xo-reader2/include/xo/reader2/ssm/IPrintable_DParenSsm.hpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DParenSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DParenSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DParenSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DParenSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DParenSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DParenSsm>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DParenSsm,
|
||||
xo::scm::IPrintable_DParenSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DParenSsm
|
||||
**/
|
||||
class IPrintable_DParenSsm {
|
||||
public:
|
||||
/** @defgroup scm-printable-dparenssm-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dparenssm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DParenSsm & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/** @file ISyntaxStateMachine_DParenSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISyntaxStateMachine_DParenSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISyntaxStateMachine_DParenSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_Xfer.hpp"
|
||||
#include "DParenSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class ISyntaxStateMachine_DParenSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::ASyntaxStateMachine,
|
||||
xo::scm::DParenSsm>
|
||||
{
|
||||
using ImplType = xo::scm::ISyntaxStateMachine_Xfer
|
||||
<xo::scm::DParenSsm,
|
||||
xo::scm::ISyntaxStateMachine_DParenSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class ISyntaxStateMachine_DParenSsm
|
||||
**/
|
||||
class ISyntaxStateMachine_DParenSsm {
|
||||
public:
|
||||
/** @defgroup scm-syntaxstatemachine-dparenssm-type-traits **/
|
||||
///@{
|
||||
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
|
||||
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
|
||||
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-syntaxstatemachine-dparenssm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** identify a type of syntax state machine **/
|
||||
static syntaxstatetype ssm_type(const DParenSsm & self) noexcept;
|
||||
/** text describing expected/allowed input to this ssm in current state **/
|
||||
static std::string_view get_expect_str(const DParenSsm & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** operate state machine for incoming token @p tk **/
|
||||
static void on_token(DParenSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DParenSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
static void on_parsed_typedescr(DParenSsm & self, TypeDescr td, ParserStateMachine * p_psm);
|
||||
/** operate state machine for formal emitted by nested ssm **/
|
||||
static void on_parsed_formal(DParenSsm & self, const DUniqueString * param_name, TypeDescr param_type, ParserStateMachine * p_psm);
|
||||
/** consume formal arglist emitted by nested ssm **/
|
||||
static void on_parsed_formal_arglist(DParenSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DParenSsm & 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(DParenSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -33,6 +33,9 @@ namespace xo {
|
|||
/** rhs expression. state exists to achieve 1-token lookahead **/
|
||||
progress,
|
||||
|
||||
/** expression enclosed in parentheses. See @ref DParenSsm **/
|
||||
paren,
|
||||
|
||||
/** toplevel of some translation unit. See @ref DExprSeqState **/
|
||||
expect_toplevel_expression_sequence,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue