xo-reader2: + on_f64_token() + handle in DDefineSsm+DProgressSsm
This commit is contained in:
parent
55149f0890
commit
d30412779c
44 changed files with 1638 additions and 8 deletions
|
|
@ -164,6 +164,32 @@ xo_add_genfacetimpl(
|
|||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-reader2-facetimpl-syntaxstatemachine-progressssm
|
||||
FACET_PKG xo_reader2
|
||||
FACET SyntaxStateMachine
|
||||
REPR ProgressSsm
|
||||
INPUT idl/ISyntaxStateMachine_DProgressSsm.json5
|
||||
OUTPUT_HPP_DIR include/xo/reader2
|
||||
OUTPUT_IMPL_SUBDIR ssm
|
||||
OUTPUT_CPP_DIR src/reader2
|
||||
)
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-reader2-facetimpl-printable-progressssm
|
||||
FACET_PKG xo_printable2
|
||||
FACET Printable
|
||||
REPR ProgressSsm
|
||||
INPUT idl/IPrintable_DProgressSsm.json5
|
||||
OUTPUT_HPP_DIR include/xo/reader2
|
||||
OUTPUT_IMPL_SUBDIR ssm
|
||||
OUTPUT_CPP_DIR src/reader2
|
||||
)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
xo_add_genfacet_all(xo-reader2-genfacet-all)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
|
|
|||
13
idl/IPrintable_DProgressSsm.json5
Normal file
13
idl/IPrintable_DProgressSsm.json5
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [ "<xo/printable2/Printable.hpp>",
|
||||
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
|
||||
local_types: [],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/Printable.json5",
|
||||
brief: "provide APrintable interface for DProgressSsm",
|
||||
using_doxygen: true,
|
||||
repr: "DProgressSsm",
|
||||
doc: [ "implement APrintable for DProgressSsm" ],
|
||||
}
|
||||
13
idl/ISyntaxStateMachine_DProgressSsm.json5
Normal file
13
idl/ISyntaxStateMachine_DProgressSsm.json5
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [ "\"SyntaxStateMachine.hpp\"",
|
||||
"\"ssm/ISyntaxStateMachine_Xfer.hpp\"" ],
|
||||
local_types: [ ],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/SyntaxStateMachine.json5",
|
||||
brief: "provide ASyntaxStateMachine interface for DProgressSsm",
|
||||
using_doxygen: true,
|
||||
repr: "DProgressSsm",
|
||||
doc: [ "implement ASyntaxStateMachine for DProgressSsm" ],
|
||||
}
|
||||
|
|
@ -90,6 +90,15 @@
|
|||
{type: "ParserStateMachine *", name: "p_psm"},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "on_f64_token",
|
||||
doc: ["update state machine for incoming f64-token @p tk"],
|
||||
return_type: "void",
|
||||
args: [
|
||||
{type: "const Token &", name: "tk"},
|
||||
{type: "ParserStateMachine *", name: "p_psm"},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "on_parsed_symbol",
|
||||
doc: ["update stat machine for incoming parsed symbol @p sym"],
|
||||
|
|
|
|||
|
|
@ -147,6 +147,12 @@ namespace xo {
|
|||
void on_singleassign_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming f64 token @p tk,
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax after parsing a symbol @p sym;
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -83,6 +83,12 @@ namespace xo {
|
|||
void on_singleassign_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming f64 token @p tk,
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax after parsing a symbol @p sym;
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -103,6 +103,12 @@ namespace xo {
|
|||
void on_singleassign_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming f64 token @p tk,
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-expectsymbol-printable-facet printable facet methods **/
|
||||
///@{
|
||||
|
|
|
|||
|
|
@ -77,6 +77,12 @@ namespace xo {
|
|||
void on_singleassign_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming f64 token @p tk,
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** (Never called).
|
||||
* Operate state machine for this syntax after symbol
|
||||
* emitted from nested ssm.
|
||||
|
|
|
|||
|
|
@ -90,6 +90,11 @@ namespace xo {
|
|||
**/
|
||||
void on_singleassign_token(const Token & tk, ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming f64 token @p tk,
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_f64_token(const Token & tk, ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on parsed symbol @p sym
|
||||
* from immediately-downstream ssm.
|
||||
* overall parser state in @p p_psm
|
||||
|
|
|
|||
220
include/xo/reader2/DProgressSsm.hpp
Normal file
220
include/xo/reader2/DProgressSsm.hpp
Normal file
|
|
@ -0,0 +1,220 @@
|
|||
/** @file DProgressSsm.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ParserStateMachine.hpp"
|
||||
#include "syntaxstatetype.hpp"
|
||||
//#include <xo/expression2/Expression.hpp>
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
#ifdef NOT_YET
|
||||
#include "exprstate.hpp"
|
||||
#include "xo/reflect/TypeDescr.hpp"
|
||||
#include <iostream>
|
||||
//#include <cstdint>
|
||||
#endif
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** represent an infix operator.
|
||||
*
|
||||
* See @ref progress_xs::assemble_expr() for translation
|
||||
* to Expression
|
||||
**/
|
||||
enum class optype {
|
||||
invalid = -1,
|
||||
|
||||
/** op:= **/
|
||||
op_assign,
|
||||
|
||||
/** op< **/
|
||||
op_less,
|
||||
/** op<= **/
|
||||
op_less_equal,
|
||||
/** op== **/
|
||||
op_equal,
|
||||
/** op!= **/
|
||||
op_not_equal,
|
||||
/** op> **/
|
||||
op_great,
|
||||
/** op>= **/
|
||||
op_great_equal,
|
||||
|
||||
/** op+ **/
|
||||
op_add,
|
||||
/** op- **/
|
||||
op_subtract,
|
||||
|
||||
/** op* **/
|
||||
op_multiply,
|
||||
/** op/ **/
|
||||
op_divide,
|
||||
|
||||
n_optype
|
||||
};
|
||||
|
||||
extern const char *
|
||||
optype_descr(optype x);
|
||||
|
||||
/** report operator precedence.
|
||||
* lowest operator precedence is 1
|
||||
**/
|
||||
extern int
|
||||
precedence(optype x);
|
||||
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os, optype x) {
|
||||
os << optype_descr(x);
|
||||
return os;
|
||||
}
|
||||
|
||||
/** @class DProgressSsm
|
||||
* @brief syntax state machine for parsing a schematica rhs-value-expression
|
||||
*
|
||||
* Handles an expression that produces a value, for example appearing on the
|
||||
* right-hand side of a definition.
|
||||
*
|
||||
* Deals with:
|
||||
* 1. infix operators including operator precedence.
|
||||
* 2. generates argument-type-specific arithmetic expressions,
|
||||
* for example using ``Apply::make_add2_f64()`` when adding floating-point numbers
|
||||
*
|
||||
* One reason for this to exist is to simulate one-token lookahead.
|
||||
* To look at but not consume a token T, can push a progress_xs instance P,
|
||||
* then send T to P.
|
||||
**/
|
||||
class DProgressSsm {
|
||||
public:
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using DArena = xo::mm::DArena;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
public:
|
||||
DProgressSsm(obj<AExpression> lhs, optype op);
|
||||
|
||||
static DProgressSsm * make(DArena & parser_mm,
|
||||
obj<AExpression> lhs,
|
||||
optype op);
|
||||
|
||||
static void start(DArena & parser_mm,
|
||||
obj<AExpression> valex,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
#ifdef NOT_YET
|
||||
static void start(rp<Expression> valex,
|
||||
optype optype,
|
||||
parserstatemachine * p_psm);
|
||||
#endif
|
||||
|
||||
syntaxstatetype ssm_type() const noexcept;
|
||||
|
||||
#ifdef NOT_YET
|
||||
bool admits_f64() const;
|
||||
|
||||
void apply_type_error(const char * self_name,
|
||||
optype op,
|
||||
bp<Expression> expr1,
|
||||
bp<Expression> expr2,
|
||||
parserstatemachine * p_psm) const;
|
||||
#endif
|
||||
|
||||
std::string_view get_expect_str() const noexcept;
|
||||
|
||||
#ifdef NOT_YET
|
||||
void on_expr(bp<Expression> expr,
|
||||
parserstatemachine * p_psm) override;
|
||||
void on_expr_with_semicolon(bp<Expression> expr,
|
||||
parserstatemachine * p_psm) override;
|
||||
#endif
|
||||
void on_symbol_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_def_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_if_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_colon_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_singleassign_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_parsed_symbol(std::string_view sym,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_parsed_typedescr(TypeDescr td,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@{
|
||||
|
||||
/** @defgroup scm-progressssm-printable-facet printable facet methods **/
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
#ifdef NOT_YET
|
||||
void on_comma_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) final override;
|
||||
void on_typedescr(TypeDescr td,
|
||||
parserstatemachine * p_psm) override;
|
||||
|
||||
void on_semicolon_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
void on_assign_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) final override;
|
||||
void on_leftparen_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
void on_rightparen_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
void on_rightbrace_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
void on_then_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
void on_else_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
|
||||
/* entry point for an infix operator token */
|
||||
void on_operator_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) final override;
|
||||
|
||||
void on_bool_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
|
||||
void on_i64_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
|
||||
|
||||
void print(std::ostream & os) const override;
|
||||
|
||||
private:
|
||||
/** assemble expression representing
|
||||
* value of
|
||||
* @code
|
||||
* f(lhs_, rhs_)
|
||||
* @endcode
|
||||
*
|
||||
* where f determined by @ref op_type_
|
||||
**/
|
||||
obj<AExpression> assemble_expr(ParserStateMachine * p_psm);
|
||||
#endif
|
||||
|
||||
private:
|
||||
/** populate an expression here, may be followed by an operator **/
|
||||
obj<AExpression> lhs_;
|
||||
|
||||
/** infix operator, if supplied **/
|
||||
optype op_type_ = optype::invalid;
|
||||
|
||||
/** populate an expression here, following infix operator */
|
||||
obj<AExpression> rhs_;
|
||||
};
|
||||
} /*namespace scm*/
|
||||
|
||||
#ifndef ppdetail_atomic
|
||||
namespace print {
|
||||
PPDETAIL_ATOMIC(xo::scm::optype);
|
||||
}
|
||||
#endif
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end DProgressSsm.hpp */
|
||||
|
|
@ -122,6 +122,9 @@ namespace xo {
|
|||
/** operate state machine for incoming singleassign-token @p tk **/
|
||||
void on_singleassign_token(const Token & tk);
|
||||
|
||||
/** operate state machine for incoming f64-token @p tk **/
|
||||
void on_f64_token(const Token & tk);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-parserstatemachine-error-entrypoints error entry points **/
|
||||
///@{
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ public:
|
|||
virtual void on_colon_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) = 0;
|
||||
/** update state machine for incoming singleassign-token @p tk **/
|
||||
virtual void on_singleassign_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) = 0;
|
||||
/** update state machine for incoming f64-token @p tk **/
|
||||
virtual void on_f64_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) = 0;
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
virtual void on_parsed_symbol(Opaque data, std::string_view sym, ParserStateMachine * p_psm) = 0;
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DExpectExprSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
62
include/xo/reader2/ssm/IPrintable_DProgressSsm.hpp
Normal file
62
include/xo/reader2/ssm/IPrintable_DProgressSsm.hpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DProgressSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DProgressSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DProgressSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DProgressSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DProgressSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DProgressSsm>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DProgressSsm,
|
||||
xo::scm::IPrintable_DProgressSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DProgressSsm
|
||||
**/
|
||||
class IPrintable_DProgressSsm {
|
||||
public:
|
||||
/** @defgroup scm-printable-dprogressssm-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dprogressssm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DProgressSsm & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -65,6 +65,7 @@ namespace scm {
|
|||
[[noreturn]] void on_if_token(Opaque, const Token &, ParserStateMachine *) override;
|
||||
[[noreturn]] void on_colon_token(Opaque, const Token &, ParserStateMachine *) override;
|
||||
[[noreturn]] void on_singleassign_token(Opaque, const Token &, ParserStateMachine *) override;
|
||||
[[noreturn]] void on_f64_token(Opaque, const Token &, ParserStateMachine *) override;
|
||||
[[noreturn]] void on_parsed_symbol(Opaque, std::string_view, ParserStateMachine *) override;
|
||||
[[noreturn]] void on_parsed_typedescr(Opaque, TypeDescr, ParserStateMachine *) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ namespace xo {
|
|||
static void on_colon_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming singleassign-token @p tk **/
|
||||
static void on_singleassign_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming f64-token @p tk **/
|
||||
static void on_f64_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DDefineSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISyntaxStateMachine_DExpectExprSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
@ -64,6 +64,8 @@ namespace xo {
|
|||
static void on_colon_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming singleassign-token @p tk **/
|
||||
static void on_singleassign_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming f64-token @p tk **/
|
||||
static void on_f64_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DExpectExprSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ namespace xo {
|
|||
static void on_colon_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming singleassign-token @p tk **/
|
||||
static void on_singleassign_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming f64-token @p tk **/
|
||||
static void on_f64_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DExpectSymbolSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ namespace xo {
|
|||
static void on_colon_token(DExpectTypeSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming singleassign-token @p tk **/
|
||||
static void on_singleassign_token(DExpectTypeSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming f64-token @p tk **/
|
||||
static void on_f64_token(DExpectTypeSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DExpectTypeSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ namespace xo {
|
|||
static void on_colon_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming singleassign-token @p tk **/
|
||||
static void on_singleassign_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming f64-token @p tk **/
|
||||
static void on_f64_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DExprSeqState & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
|
|
|
|||
79
include/xo/reader2/ssm/ISyntaxStateMachine_DProgressSsm.hpp
Normal file
79
include/xo/reader2/ssm/ISyntaxStateMachine_DProgressSsm.hpp
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/** @file ISyntaxStateMachine_DProgressSsm.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISyntaxStateMachine_DProgressSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISyntaxStateMachine_DProgressSsm.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_Xfer.hpp"
|
||||
#include "DProgressSsm.hpp"
|
||||
|
||||
namespace xo { namespace scm { class ISyntaxStateMachine_DProgressSsm; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::ASyntaxStateMachine,
|
||||
xo::scm::DProgressSsm>
|
||||
{
|
||||
using ImplType = xo::scm::ISyntaxStateMachine_Xfer
|
||||
<xo::scm::DProgressSsm,
|
||||
xo::scm::ISyntaxStateMachine_DProgressSsm>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class ISyntaxStateMachine_DProgressSsm
|
||||
**/
|
||||
class ISyntaxStateMachine_DProgressSsm {
|
||||
public:
|
||||
/** @defgroup scm-syntaxstatemachine-dprogressssm-type-traits **/
|
||||
///@{
|
||||
using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr;
|
||||
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
|
||||
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-syntaxstatemachine-dprogressssm-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** identify a type of syntax state machine **/
|
||||
static syntaxstatetype ssm_type(const DProgressSsm & self) noexcept;
|
||||
/** text describing expected/allowed input to this ssm in current state **/
|
||||
static std::string_view get_expect_str(const DProgressSsm & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** operate state machine for incoming symbol-token @p tk **/
|
||||
static void on_symbol_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming define-keyword-token @p tk **/
|
||||
static void on_def_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming if-keyword-token @p tk **/
|
||||
static void on_if_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming colon-token @p tk **/
|
||||
static void on_colon_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming singleassign-token @p tk **/
|
||||
static void on_singleassign_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming f64-token @p tk **/
|
||||
static void on_f64_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||
/** update stat machine for incoming parsed symbol @p sym **/
|
||||
static void on_parsed_symbol(DProgressSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||
/** operate state machine for incoming type description @p td **/
|
||||
static void on_parsed_typedescr(DProgressSsm & self, TypeDescr td, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -67,6 +67,9 @@ namespace scm {
|
|||
void on_singleassign_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) override {
|
||||
return I::on_singleassign_token(_dcast(data), tk, p_psm);
|
||||
}
|
||||
void on_f64_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) override {
|
||||
return I::on_f64_token(_dcast(data), tk, p_psm);
|
||||
}
|
||||
void on_parsed_symbol(Opaque data, std::string_view sym, ParserStateMachine * p_psm) override {
|
||||
return I::on_parsed_symbol(_dcast(data), sym, p_psm);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,9 @@ public:
|
|||
void on_singleassign_token(const Token & tk, ParserStateMachine * p_psm) {
|
||||
return O::iface()->on_singleassign_token(O::data(), tk, p_psm);
|
||||
}
|
||||
void on_f64_token(const Token & tk, ParserStateMachine * p_psm) {
|
||||
return O::iface()->on_f64_token(O::data(), tk, p_psm);
|
||||
}
|
||||
void on_parsed_symbol(std::string_view sym, ParserStateMachine * p_psm) {
|
||||
return O::iface()->on_parsed_symbol(O::data(), sym, p_psm);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ namespace xo {
|
|||
/** handle define-expression. See @ref DDefineSsm **/
|
||||
defexpr,
|
||||
|
||||
/** rhs expression. state exists to achieve 1-token lookahead **/
|
||||
progress,
|
||||
|
||||
/** comes lasts, counts number of valid enums **/
|
||||
N
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ set(SELF_SRCS
|
|||
ISyntaxStateMachine_DExpectExprSsm.cpp
|
||||
IPrintable_DExpectExprSsm.cpp
|
||||
|
||||
DProgressSsm.cpp
|
||||
ISyntaxStateMachine_DProgressSsm.cpp
|
||||
IPrintable_DProgressSsm.cpp
|
||||
|
||||
reader2_register_facets.cpp
|
||||
reader2_register_types.cpp
|
||||
)
|
||||
|
|
|
|||
|
|
@ -565,6 +565,15 @@ namespace xo {
|
|||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DDefineSsm::on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_token("DDefineSsm::on_f64_token",
|
||||
tk,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
bool
|
||||
DDefineSsm::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,13 @@
|
|||
#include "ParserStateMachine.hpp"
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_DExpectExprSsm.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_DProgressSsm.hpp"
|
||||
#include "syntaxstatetype.hpp"
|
||||
#include <xo/expression2/DConstant.hpp>
|
||||
#include <xo/expression2/detail/IExpression_DConstant.hpp>
|
||||
#include <xo/object2/DFloat.hpp>
|
||||
#include <xo/object2/number/IGCObject_DFloat.hpp>
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
#include <xo/facet/facet_implementation.hpp>
|
||||
|
||||
#ifdef NOT_YET
|
||||
|
|
@ -27,6 +33,8 @@ namespace xo {
|
|||
#ifdef NOT_YET
|
||||
using xo::scm::Constant;
|
||||
#endif
|
||||
using xo::scm::DFloat;
|
||||
using xo::mm::AGCObject;
|
||||
|
||||
using xo::reflect::typeseq;
|
||||
using xo::facet::with_facet;
|
||||
|
|
@ -139,6 +147,29 @@ namespace xo {
|
|||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DExpectExprSsm::on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
auto f64o = DFloat::box<AGCObject>(p_psm->expr_alloc(),
|
||||
tk.f64_value());
|
||||
|
||||
auto expr = with_facet<AExpression>::mkobj(DConstant::make(p_psm->expr_alloc(), f64o));
|
||||
|
||||
// DProgressSsm responsible for resolving cases like
|
||||
// 1.9,
|
||||
// 1.9;
|
||||
// 1.9 + 2;
|
||||
// 1.9 + 2 .. // could be followed by infix
|
||||
// 1.9 + 2 * 3;
|
||||
// 1.9 + 2 * 3 .. // could be followed by infix
|
||||
// 1.9 * (2 + 3)
|
||||
|
||||
DProgressSsm::start(p_psm->parser_alloc(),
|
||||
expr,
|
||||
p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
DExpectExprSsm::on_parsed_symbol(std::string_view sym,
|
||||
ParserStateMachine * p_psm)
|
||||
|
|
|
|||
|
|
@ -131,6 +131,15 @@ namespace xo {
|
|||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DExpectSymbolSsm::on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_token("DExpectSymbolSsm::on_f64_token",
|
||||
tk,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
bool
|
||||
DExpectSymbolSsm::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -92,6 +92,15 @@ namespace xo {
|
|||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DExpectTypeSsm::on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_token("DExpectTypeSsm",
|
||||
tk,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DExpectTypeSsm::on_symbol_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
|
|
|
|||
|
|
@ -178,6 +178,15 @@ namespace xo {
|
|||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DExprSeqState::on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_token("DExprSeqState::on_f64_token",
|
||||
tk,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DExprSeqState::on_parsed_symbol(std::string_view sym,
|
||||
ParserStateMachine * p_psm)
|
||||
|
|
|
|||
932
src/reader2/DProgressSsm.cpp
Normal file
932
src/reader2/DProgressSsm.cpp
Normal file
|
|
@ -0,0 +1,932 @@
|
|||
/** @file DProgressSsm.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include "DProgressSsm.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_DProgressSsm.hpp"
|
||||
#include <xo/reflectutil/typeseq.hpp>
|
||||
|
||||
#ifdef NOT_YET
|
||||
#include "apply_xs.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "expect_expr_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "pretty_exprstatestack.hpp"
|
||||
#include "xo/expression/AssignExpr.hpp"
|
||||
#include "xo/expression/Apply.hpp"
|
||||
#include "xo/expression/pretty_expression.hpp"
|
||||
#endif
|
||||
|
||||
namespace xo {
|
||||
#ifdef NOT_YET
|
||||
using xo::scm::Expression;
|
||||
using xo::scm::AssignExpr;
|
||||
using xo::scm::Variable;
|
||||
using xo::scm::Apply;
|
||||
#endif
|
||||
using xo::facet::with_facet;
|
||||
using xo::reflect::typeseq;
|
||||
|
||||
namespace scm {
|
||||
const char *
|
||||
optype_descr(optype x) {
|
||||
switch (x) {
|
||||
case optype::invalid:
|
||||
return "?optype";
|
||||
case optype::op_assign:
|
||||
return "op:=";
|
||||
case optype::op_less:
|
||||
return "op<";
|
||||
case optype::op_less_equal:
|
||||
return "op<=";
|
||||
case optype::op_equal:
|
||||
return "op==";
|
||||
case optype::op_not_equal:
|
||||
return "op!=";
|
||||
case optype::op_great:
|
||||
return "op>";
|
||||
case optype::op_great_equal:
|
||||
return "op>=";
|
||||
case optype::op_add:
|
||||
return "op+";
|
||||
case optype::op_subtract:
|
||||
return "op-";
|
||||
case optype::op_multiply:
|
||||
return "op*";
|
||||
case optype::op_divide:
|
||||
return "op/";
|
||||
case optype::n_optype:
|
||||
break;
|
||||
}
|
||||
return "???";
|
||||
}
|
||||
|
||||
int
|
||||
precedence(optype x) {
|
||||
switch (x) {
|
||||
case optype::invalid:
|
||||
case optype::n_optype:
|
||||
return 0;
|
||||
|
||||
case optype::op_assign:
|
||||
return 1;
|
||||
|
||||
case optype::op_less:
|
||||
case optype::op_less_equal:
|
||||
case optype::op_equal:
|
||||
case optype::op_not_equal:
|
||||
case optype::op_great:
|
||||
case optype::op_great_equal:
|
||||
return 2;
|
||||
|
||||
case optype::op_add:
|
||||
case optype::op_subtract:
|
||||
return 3;
|
||||
|
||||
case optype::op_multiply:
|
||||
case optype::op_divide:
|
||||
return 4;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DProgressSsm *
|
||||
DProgressSsm::make(DArena & mm,
|
||||
obj<AExpression> lhs,
|
||||
optype op)
|
||||
{
|
||||
void * mem = mm.alloc(typeseq::id<DProgressSsm>(),
|
||||
sizeof(DProgressSsm));
|
||||
|
||||
return new (mem) DProgressSsm(lhs, op);
|
||||
|
||||
//return std::make_unique<progress_xs>(progress_xs(std::move(valex), op));
|
||||
}
|
||||
|
||||
void
|
||||
DProgressSsm::start(DArena & parser_mm,
|
||||
obj<AExpression> valex,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
DProgressSsm * progress_ssm
|
||||
= DProgressSsm::make(parser_mm, valex, optype::invalid);
|
||||
|
||||
obj<ASyntaxStateMachine> ssm
|
||||
= with_facet<ASyntaxStateMachine>::mkobj(progress_ssm);
|
||||
|
||||
p_psm->push_ssm(ssm);
|
||||
}
|
||||
|
||||
#ifdef NOT_YET
|
||||
void
|
||||
progress_xs::start(rp<Expression> valex, optype op, parserstatemachine * p_psm) {
|
||||
p_psm->push_exprstate(progress_xs::make(valex, op));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
DProgressSsm::DProgressSsm(obj<AExpression> valex,
|
||||
optype op)
|
||||
: lhs_{valex},
|
||||
op_type_{op}
|
||||
{}
|
||||
|
||||
syntaxstatetype
|
||||
DProgressSsm::ssm_type() const noexcept
|
||||
{
|
||||
return syntaxstatetype::progress;
|
||||
}
|
||||
|
||||
#ifdef NOT_YET
|
||||
bool
|
||||
progress_xs::admits_f64() const { return false; }
|
||||
#endif
|
||||
|
||||
std::string_view
|
||||
DProgressSsm::get_expect_str() const noexcept {
|
||||
if (op_type_ == optype::invalid) {
|
||||
return "oper|semicolon|rightparen";
|
||||
} else {
|
||||
return "expr|leftparen";
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DProgressSsm::on_symbol_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_token("DProgressSsm::on_symbol_token",
|
||||
tk,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DProgressSsm::on_def_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_token("DProgressSsm::on_def_token",
|
||||
tk,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DProgressSsm::on_if_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_token("DProgressSsm::on_if_token",
|
||||
tk,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DProgressSsm::on_colon_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_token("DProgressSsm::on_colon_token",
|
||||
tk,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DProgressSsm::on_singleassign_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_token("DProgressSsm::on_singleassign_token",
|
||||
tk,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DProgressSsm::on_f64_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_token("DProgressSsm::on_f64_token",
|
||||
tk,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DProgressSsm::on_parsed_symbol(std::string_view sym,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_symbol("DProgressSsm::on_parsed_symbol",
|
||||
sym,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
void
|
||||
DProgressSsm::on_parsed_typedescr(TypeDescr td,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_typedescr("DProgressSsm::on_parsed_typedescr",
|
||||
td,
|
||||
this->get_expect_str());
|
||||
}
|
||||
|
||||
#ifdef NOT_YET
|
||||
void
|
||||
progress_xs::apply_type_error(const char * self_name,
|
||||
optype op,
|
||||
bp<Expression> expr1,
|
||||
bp<Expression> expr2,
|
||||
parserstatemachine * p_psm) const
|
||||
{
|
||||
std::string errmsg = tostr("incompatible argument types T1,T2 to op",
|
||||
xtag("op", op),
|
||||
xtag("T1", expr1->valuetype()),
|
||||
xtag("T2", expr2->valuetype()));
|
||||
|
||||
p_psm->on_error(self_name, std::move(errmsg));
|
||||
}
|
||||
|
||||
rp<Expression>
|
||||
progress_xs::assemble_expr(parserstatemachine * p_psm) {
|
||||
/* need to defer building Apply incase expr followed by higher-precedence operator:
|
||||
* consider input like
|
||||
* 3.14 + 2.0 * ...
|
||||
*/
|
||||
|
||||
constexpr const char * c_self_name = "progress_xs::assemble_expr";
|
||||
|
||||
if ((op_type_ != optype::invalid) && (rhs_.get() == nullptr)) {
|
||||
std::string errmsg = tostr("expected expression on rhs of operator op",
|
||||
xtag("lhs", lhs_),
|
||||
xtag("op", op_type_));
|
||||
|
||||
p_psm->on_error(c_self_name, errmsg);
|
||||
}
|
||||
|
||||
/* consecutive expressions not legal, e.g:
|
||||
* 3.14 6.28
|
||||
* but expressions surrounding an infix operators is:
|
||||
* 3.14 / 6.28
|
||||
*/
|
||||
switch (op_type_) {
|
||||
case optype::invalid:
|
||||
return this->lhs_;
|
||||
|
||||
case optype::op_assign:
|
||||
{
|
||||
bp<Variable> lhs = Variable::from(this->lhs_);
|
||||
|
||||
if (!lhs) {
|
||||
throw std::runtime_error
|
||||
(tostr("progress_xs::assemble_expr",
|
||||
" expect variable on lhs of assignment operator :=",
|
||||
xtag("lhs", lhs_),
|
||||
xtag("rhs", rhs_)));
|
||||
}
|
||||
|
||||
return AssignExpr::make(lhs.promote(),
|
||||
this->rhs_);
|
||||
}
|
||||
|
||||
case optype::op_equal:
|
||||
if (lhs_->valuetype()->is_i64() && rhs_->valuetype()->is_i64()) {
|
||||
return Apply::make_cmp_eq_i64(lhs_, rhs_);
|
||||
} else {
|
||||
this->apply_type_error(c_self_name,
|
||||
op_type_, lhs_, rhs_, p_psm);
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case optype::op_not_equal:
|
||||
if (lhs_->valuetype()->is_i64() && rhs_->valuetype()->is_i64()) {
|
||||
return Apply::make_cmp_ne_i64(lhs_, rhs_);
|
||||
} else {
|
||||
this->apply_type_error(c_self_name,
|
||||
op_type_, lhs_, rhs_, p_psm);
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case optype::op_less:
|
||||
// TODO: floating-point less-than
|
||||
|
||||
if (lhs_->valuetype()->is_i64() && rhs_->valuetype()->is_i64()) {
|
||||
return Apply::make_cmp_lt_i64(lhs_, rhs_);
|
||||
} else {
|
||||
this->apply_type_error(c_self_name,
|
||||
op_type_, lhs_, rhs_, p_psm);
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case optype::op_less_equal:
|
||||
if (lhs_->valuetype()->is_i64() && rhs_->valuetype()->is_i64()) {
|
||||
return Apply::make_cmp_le_i64(lhs_, rhs_);
|
||||
} else {
|
||||
this->apply_type_error(c_self_name,
|
||||
op_type_, lhs_, rhs_, p_psm);
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case optype::op_great:
|
||||
if (lhs_->valuetype()->is_i64() && rhs_->valuetype()->is_i64()) {
|
||||
return Apply::make_cmp_gt_i64(lhs_, rhs_);
|
||||
} else {
|
||||
this->apply_type_error(c_self_name,
|
||||
op_type_, lhs_, rhs_, p_psm);
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case optype::op_great_equal:
|
||||
// TODO: upconvert integer->double
|
||||
if (lhs_->valuetype()->is_i64() && rhs_->valuetype()->is_i64()) {
|
||||
return Apply::make_cmp_ge_i64(lhs_, rhs_);
|
||||
} else {
|
||||
this->apply_type_error(c_self_name,
|
||||
op_type_, lhs_, rhs_, p_psm);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
|
||||
case optype::op_add:
|
||||
// TODO: upconvert integer->double
|
||||
if (lhs_->valuetype()->is_i64() && rhs_->valuetype()->is_i64()) {
|
||||
return Apply::make_add2_i64(lhs_, rhs_);
|
||||
} else if (lhs_->valuetype()->is_f64() && rhs_->valuetype()->is_f64()) {
|
||||
return Apply::make_add2_f64(lhs_, rhs_);
|
||||
} else {
|
||||
this->apply_type_error(c_self_name,
|
||||
op_type_, lhs_, rhs_, p_psm);
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
case optype::op_subtract:
|
||||
// TODO: upconvert integer->double
|
||||
if (lhs_->valuetype()->is_i64() && rhs_->valuetype()->is_i64()) {
|
||||
return Apply::make_sub2_i64(lhs_, rhs_);
|
||||
} else if (lhs_->valuetype()->is_f64() && rhs_->valuetype()->is_f64()) {
|
||||
return Apply::make_sub2_f64(lhs_, rhs_);
|
||||
} else {
|
||||
this->apply_type_error(c_self_name,
|
||||
op_type_, lhs_, rhs_, p_psm);
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case optype::op_multiply:
|
||||
// TODO: upconvert integer->double
|
||||
if (lhs_->valuetype()->is_i64() && rhs_->valuetype()->is_i64()) {
|
||||
return Apply::make_mul2_i64(lhs_, rhs_);
|
||||
} else if (lhs_->valuetype()->is_f64() && rhs_->valuetype()->is_f64()) {
|
||||
return Apply::make_mul2_f64(lhs_, rhs_);
|
||||
} else {
|
||||
this->apply_type_error(c_self_name,
|
||||
op_type_, lhs_, rhs_, p_psm);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case optype::op_divide:
|
||||
// TODO: upconvert integer->double
|
||||
if (lhs_->valuetype()->is_i64() && rhs_->valuetype()->is_i64()) {
|
||||
return Apply::make_div2_i64(lhs_, rhs_);
|
||||
} else if (lhs_->valuetype()->is_f64() && rhs_->valuetype()->is_f64()) {
|
||||
return Apply::make_div2_f64(lhs_, rhs_);
|
||||
} else {
|
||||
this->apply_type_error(c_self_name,
|
||||
op_type_, lhs_, rhs_, p_psm);
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case optype::n_optype:
|
||||
/* unreachable */
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_expr(bp<Expression> expr,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()), xtag("expr", expr));
|
||||
|
||||
/* note: previous token probably an operator,
|
||||
* handled from progress_xs::on_operator_token(),
|
||||
* which pushes expect_expr_xs::expect_rhs_expression()
|
||||
*/
|
||||
|
||||
constexpr const char * c_self_name = "progress_xs::on_expr";
|
||||
const char * exp = get_expect_str();
|
||||
|
||||
if (lhs_) {
|
||||
if (op_type_ == optype::invalid) {
|
||||
/* two consecutive expression without an operator */
|
||||
this->illegal_input_on_expr(c_self_name, expr, exp, p_psm);
|
||||
}
|
||||
|
||||
#ifdef NOT_QUITE
|
||||
assert(result.get());
|
||||
|
||||
/* this expression complete.. */
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
/* ..but more operators could follow, so don't commit yet */
|
||||
p_stack->push_exprstate(progress_xs::make(result));
|
||||
#endif
|
||||
|
||||
this->rhs_ = expr.promote();
|
||||
} else {
|
||||
/* control here on input like
|
||||
* add(1,2)...
|
||||
*
|
||||
* add(1,2) needs to be handled inside a progress_xs
|
||||
* instance because may be followed by an operator:
|
||||
* add(1,2) + ...
|
||||
*/
|
||||
this->lhs_ = expr.promote();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_expr_with_semicolon(bp<Expression> expr,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
log && log(xtag("lhs", lhs_), xtag("op", op_type_), xtag("expr", expr));
|
||||
|
||||
constexpr const char * c_self_name = "progress_xs::on_expr_with_semicolon";
|
||||
const char * exp = get_expect_str();
|
||||
|
||||
if (op_type_ == optype::invalid) {
|
||||
this->illegal_input_on_expr(c_self_name, expr, exp, p_psm);
|
||||
}
|
||||
|
||||
this->rhs_ = expr.promote();
|
||||
|
||||
// FORBIDDEN, because .on_semicolon_token() destroys *this before returning
|
||||
// this->on_semicolon_token(token_type::semicolon(), p_psm);
|
||||
// INSTEAD, spell out the body
|
||||
|
||||
rp<Expression> expr2 = this->assemble_expr(p_psm);
|
||||
|
||||
if (expr2) {
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
p_psm->on_expr_with_semicolon(expr2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NOT_YET
|
||||
void
|
||||
progress_xs::on_comma_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
/* note: implementation parllels .on_semicolon_token(), .on_rightparen_token() */
|
||||
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
constexpr const char * self_name = "progress::xs::on_comma_token";
|
||||
|
||||
auto & xs_stack = p_psm->xs_stack_;
|
||||
|
||||
/* stack may be something like
|
||||
*
|
||||
* applyexpr
|
||||
* expect_expr_xs
|
||||
* progress_xs
|
||||
* <-- comma
|
||||
*
|
||||
* 1. comma completes expression-in-progress
|
||||
*/
|
||||
|
||||
/* comma confirms stack expression */
|
||||
rp<Expression> expr = this->assemble_expr(p_psm);
|
||||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
if (xs_stack.empty()) {
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": expected non-empty parsing state"));
|
||||
}
|
||||
|
||||
log && log(xtag("stack", &xs_stack));
|
||||
|
||||
p_psm->top_exprstate().on_expr(expr, p_psm);
|
||||
|
||||
/* now deliver comma */
|
||||
p_psm->top_exprstate().on_comma_token(tk, p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_typedescr(TypeDescr /*td*/,
|
||||
parserstatemachine * /*p_psm*/)
|
||||
{
|
||||
/* unreachable */
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_semicolon_token(const token_type & /*tk*/,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
/* note: implementation parallels .on_rightparen_token() */
|
||||
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
rp<Expression> expr = this->assemble_expr(p_psm);
|
||||
|
||||
log && log(xtag("assembled-expr", expr));
|
||||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
p_psm->on_expr_with_semicolon(expr);
|
||||
|
||||
/* control here on input like:
|
||||
* (1.234;
|
||||
*
|
||||
* a. '(' sets up stack [lparen_0:expect_rhs_expression]
|
||||
* (see exprstate::on_leftparen())
|
||||
* b. 1.234 pushes (in case operators) [lparen_0:expect_rhs_expression:expr_progress]
|
||||
* (see exprstate::on_f64())
|
||||
* c. semicolon completes expr_progress [lparen_0:expect_rhs_expression]
|
||||
* deliver expresssion to expect_rhs_expression.on_expr_with_semicolon()
|
||||
* (see exprstate::on_expr_with_semicolon())
|
||||
* d. expr_rhs_expression forwards expression to [lparen_0]
|
||||
* e. lparen_0 would advance to [lparen_1], but rejects semicolon
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_assign_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
this->on_operator_token(tk, p_psm);
|
||||
}
|
||||
|
||||
/* editor bait: on_lparen */
|
||||
void
|
||||
progress_xs::on_leftparen_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
/* input like:
|
||||
* 'foo(' -> expect function call. might continue 'foo(a,b,c)'
|
||||
* 'foo+(' -> expect parenthesized expression. might continue 'foo+(bar/2)'
|
||||
*/
|
||||
|
||||
if (op_type_ == optype::invalid) {
|
||||
/* start function call */
|
||||
assert(rhs_.get() == nullptr);
|
||||
|
||||
rp<Expression> fn_expr = lhs_;
|
||||
|
||||
/* reset this progress_xs back to empty state;
|
||||
* apply_xs will be responsible for lhs_.
|
||||
*/
|
||||
lhs_ = nullptr;
|
||||
|
||||
#ifdef OBSOLETE
|
||||
/* don't unwind! want to handle input like
|
||||
* f(x,y)+g(z)
|
||||
*/
|
||||
/* unwind this progress_xs + replace with function call */
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
#endif
|
||||
|
||||
apply_xs::start(fn_expr, p_psm);
|
||||
|
||||
/* control will reenter progress_xs via .on_expr() */
|
||||
return;
|
||||
}
|
||||
|
||||
constexpr const char * c_self_name = "exprstate::on_leftparen";
|
||||
const char * exp = get_expect_str();
|
||||
|
||||
this->illegal_input_on_token(c_self_name, tk, exp, p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_rightparen_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
/* note: implementation parallels .on_semicolon_token() */
|
||||
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
constexpr const char * self_name = "progress_xs::on_rightparen";
|
||||
|
||||
auto & xs_stack = p_psm->xs_stack_;
|
||||
|
||||
/* stack may be something like:
|
||||
*
|
||||
* lparen_0
|
||||
* expect_expr_xs
|
||||
* expr_progress
|
||||
* <-- rightparen
|
||||
*
|
||||
* 1. rightparen completes expression-in-progress
|
||||
* 2. rightparen must then match innermost waiting lparen_0
|
||||
*/
|
||||
|
||||
/* right paren confirms stack expression */
|
||||
rp<Expression> expr = this->assemble_expr(p_psm);
|
||||
|
||||
log && log(xtag("expr", expr),
|
||||
xtag("do", "pop self + send {expr, rparen} -> parent"));
|
||||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
if (xs_stack.empty()) {
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": expected non-empty parsing stack"));
|
||||
}
|
||||
|
||||
log && log(xtag("stack", &xs_stack));
|
||||
|
||||
p_psm->top_exprstate().on_expr(expr, p_psm);
|
||||
|
||||
/* now deliver rightparen */
|
||||
p_psm->top_exprstate().on_rightparen_token(tk, p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_then_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
rp<Expression> expr = this->assemble_expr(p_psm);
|
||||
|
||||
log && log(xtag("assembled-expr", expr));
|
||||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
p_psm->on_expr(expr);
|
||||
p_psm->on_then_token(tk);
|
||||
|
||||
/* control here on input like:
|
||||
*
|
||||
* if a > b then..
|
||||
*
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_else_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
rp<Expression> expr = this->assemble_expr(p_psm);
|
||||
|
||||
log && log(xtag("assembled-expr", expr));
|
||||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
p_psm->on_expr(expr);
|
||||
p_psm->on_else_token(tk);
|
||||
|
||||
/* control here on input like:
|
||||
*
|
||||
* if a > b then c else..
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_rightbrace_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
rp<Expression> expr = this->assemble_expr(p_psm);
|
||||
|
||||
log && log(xtag("assembled-expr", expr));
|
||||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
p_psm->on_expr(expr);
|
||||
p_psm->on_rightbrace_token(tk);
|
||||
|
||||
/* control here on input like:
|
||||
*
|
||||
* { n * n }
|
||||
*/
|
||||
}
|
||||
|
||||
namespace {
|
||||
optype
|
||||
tk2op(const tokentype & tktype) {
|
||||
switch (tktype) {
|
||||
case tokentype::tk_assign:
|
||||
return optype::op_assign;
|
||||
case tokentype::tk_plus:
|
||||
return optype::op_add;
|
||||
case tokentype::tk_minus:
|
||||
return optype::op_subtract;
|
||||
case tokentype::tk_star:
|
||||
return optype::op_multiply;
|
||||
case tokentype::tk_slash:
|
||||
return optype::op_divide;
|
||||
case tokentype::tk_cmpeq:
|
||||
return optype::op_equal;
|
||||
case tokentype::tk_cmpne:
|
||||
return optype::op_not_equal;
|
||||
case tokentype::tk_leftangle:
|
||||
return optype::op_less;
|
||||
case tokentype::tk_lessequal:
|
||||
return optype::op_less_equal;
|
||||
case tokentype::tk_rightangle:
|
||||
return optype::op_great;
|
||||
case tokentype::tk_greatequal:
|
||||
return optype::op_great_equal;
|
||||
default:
|
||||
assert(false);
|
||||
return optype::invalid;
|
||||
}
|
||||
return optype::invalid;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_operator_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
constexpr const char * c_self_name = "progress_xs::on_operator_token";
|
||||
|
||||
if (op_type_ == optype::invalid) {
|
||||
this->op_type_ = tk2op(tk.tk_type());
|
||||
|
||||
/* infix operator must be followed by non-empty expression */
|
||||
expect_expr_xs::start(p_psm);
|
||||
} else if (rhs_) {
|
||||
/* already have complete expression stashed.
|
||||
* behavior depends on operator precedence for tk with stored operator
|
||||
* this->op_type_
|
||||
*/
|
||||
optype op2 = tk2op(tk.tk_type());
|
||||
|
||||
if (precedence(op2) <= precedence(this->op_type_)) {
|
||||
/* e.g.
|
||||
* 6.2 * 4.9 + ...
|
||||
*
|
||||
* in stack:
|
||||
* 1. progress_xs lhs=6.2, op=*, rhs=4.9
|
||||
*
|
||||
* out stack
|
||||
* 1. progress_xs lhs=apply(*,6.2,4.9), op=+
|
||||
*/
|
||||
|
||||
/* 1. instantiate expression for *this */
|
||||
auto expr = this->assemble_expr(p_psm);
|
||||
|
||||
/* 2. remove from stack */
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
/* 3. replace with new progress_xs: */
|
||||
progress_xs::start(expr, op2, p_psm);
|
||||
|
||||
/* infix operator must be followed by non-empty expression */
|
||||
expect_expr_xs::start(p_psm);
|
||||
} else {
|
||||
/* e.g.
|
||||
* 6.2 + 4.9 * ...
|
||||
*
|
||||
* in stack:
|
||||
* 1. progress_xs lhs=6.2, op=+, rhs=4.9
|
||||
*
|
||||
* out stack:
|
||||
* 1. progress_xs lhs=6.2, op=+
|
||||
* 2. expect_rhs_expression
|
||||
* 3. progress_xs lhs=4.9, op=*
|
||||
* 4. expect_rhs_expression
|
||||
*/
|
||||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
/* 1. replace with nested incomplete infix exprs */
|
||||
progress_xs::start(lhs_, op_type_, p_psm);
|
||||
expect_expr_xs::start(p_psm);
|
||||
progress_xs::start(rhs_, op2, p_psm);
|
||||
expect_expr_xs::start(p_psm);
|
||||
}
|
||||
|
||||
} else {
|
||||
throw std::runtime_error(tostr(c_self_name,
|
||||
": expected expression following operator",
|
||||
xtag("tk", tk)));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_bool_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
constexpr const char * c_self_name = "progress_xs::on_bool_token";
|
||||
const char * exp = get_expect_str();
|
||||
|
||||
if (this->op_type_ == optype::invalid) {
|
||||
this->illegal_input_on_token(c_self_name, tk, exp, p_psm);
|
||||
} else {
|
||||
exprstate::on_bool_token(tk, p_psm);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_i64_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
constexpr const char * c_self_name = "progress_xs::on_i64_token";
|
||||
const char * exp = get_expect_str();
|
||||
|
||||
if (this->op_type_ == optype::invalid) {
|
||||
this->illegal_input_on_token(c_self_name, tk, exp, p_psm);
|
||||
} else {
|
||||
exprstate::on_i64_token(tk, p_psm);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::print(std::ostream & os) const {
|
||||
os << "<progress_xs"
|
||||
<< xtag("this", (void*)this)
|
||||
<< xtag("type", exs_type_);
|
||||
if (lhs_)
|
||||
os << xtag("lhs", lhs_);
|
||||
if (op_type_ != optype::invalid)
|
||||
os << xtag("op", op_type_);
|
||||
if (rhs_)
|
||||
os << xtag("rhs", rhs_);
|
||||
os << ">";
|
||||
}
|
||||
|
||||
bool
|
||||
progress_xs::pretty_print(const xo::print::ppindentinfo & ppii) const
|
||||
{
|
||||
if (ppii.upto()) {
|
||||
return (ppii.pps()->print_upto("<progress_xs")
|
||||
&& (lhs_ ? ppii.pps()->print_upto(refrtag("lhs", lhs_)) : true)
|
||||
&& (op_type_ != optype::invalid ? ppii.pps()->print_upto(refrtag("op", op_type_)) : true)
|
||||
&& (rhs_ ? ppii.pps()->print_upto(refrtag("rhs", rhs_)) : true)
|
||||
&& ppii.pps()->print_upto(">"));
|
||||
} else {
|
||||
ppii.pps()->write("<progress_xs ");
|
||||
if (lhs_)
|
||||
ppii.pps()->pretty(refrtag("lhs", lhs_));
|
||||
if (op_type_ != optype::invalid)
|
||||
ppii.pps()->pretty(refrtag("op", op_type_));
|
||||
if (rhs_)
|
||||
ppii.pps()->pretty(refrtag("rhs", rhs_));
|
||||
ppii.pps()->write(">");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
bool
|
||||
DProgressSsm::pretty(const xo::print::ppindentinfo & ppii) const
|
||||
{
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"DProgressSsm",
|
||||
refrtag("lhs", lhs_),
|
||||
refrtag("op", op_type_),
|
||||
refrtag("rhs", rhs_));
|
||||
|
||||
#ifdef NOPE
|
||||
if (ppii.upto()) {
|
||||
return (ppii.pps()->print_upto("<progress_xs")
|
||||
&& (lhs_ ? ppii.pps()->print_upto(refrtag("lhs", lhs_)) : true)
|
||||
&& (op_type_ != optype::invalid ? ppii.pps()->print_upto(refrtag("op", op_type_)) : true)
|
||||
&& (rhs_ ? ppii.pps()->print_upto(refrtag("rhs", rhs_)) : true)
|
||||
&& ppii.pps()->print_upto(">"));
|
||||
} else {
|
||||
ppii.pps()->write("<progress_xs ");
|
||||
if (lhs_)
|
||||
ppii.pps()->pretty(refrtag("lhs", lhs_));
|
||||
if (op_type_ != optype::invalid)
|
||||
ppii.pps()->pretty(refrtag("op", op_type_));
|
||||
if (rhs_)
|
||||
ppii.pps()->pretty(refrtag("rhs", rhs_));
|
||||
ppii.pps()->write(">");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DProgressSsm.cpp */
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DExpectExprSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
28
src/reader2/IPrintable_DProgressSsm.cpp
Normal file
28
src/reader2/IPrintable_DProgressSsm.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DProgressSsm.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DProgressSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DProgressSsm.json5]
|
||||
**/
|
||||
|
||||
#include "ssm/IPrintable_DProgressSsm.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DProgressSsm::pretty(const DProgressSsm & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DProgressSsm.cpp */
|
||||
|
|
@ -64,6 +64,12 @@ ISyntaxStateMachine_Any::on_singleassign_token(Opaque, const Token &, ParserStat
|
|||
_fatal();
|
||||
}
|
||||
|
||||
auto
|
||||
ISyntaxStateMachine_Any::on_f64_token(Opaque, const Token &, ParserStateMachine *) -> void
|
||||
{
|
||||
_fatal();
|
||||
}
|
||||
|
||||
auto
|
||||
ISyntaxStateMachine_Any::on_parsed_symbol(Opaque, std::string_view, ParserStateMachine *) -> void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -53,6 +53,11 @@ namespace xo {
|
|||
self.on_singleassign_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDefineSsm::on_f64_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_f64_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDefineSsm::on_parsed_symbol(DDefineSsm & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_symbol(sym, p_psm);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISyntaxStateMachine_DExpectExprSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
@ -53,6 +53,11 @@ namespace xo {
|
|||
self.on_singleassign_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExpectExprSsm::on_f64_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_f64_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExpectExprSsm::on_parsed_symbol(DExpectExprSsm & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_symbol(sym, p_psm);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,11 @@ namespace xo {
|
|||
self.on_singleassign_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExpectSymbolSsm::on_f64_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_f64_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExpectSymbolSsm::on_parsed_symbol(DExpectSymbolSsm & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_symbol(sym, p_psm);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,11 @@ namespace xo {
|
|||
self.on_singleassign_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExpectTypeSsm::on_f64_token(DExpectTypeSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_f64_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExpectTypeSsm::on_parsed_symbol(DExpectTypeSsm & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_symbol(sym, p_psm);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,11 @@ namespace xo {
|
|||
self.on_singleassign_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExprSeqState::on_f64_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_f64_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExprSeqState::on_parsed_symbol(DExprSeqState & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_symbol(sym, p_psm);
|
||||
|
|
|
|||
74
src/reader2/ISyntaxStateMachine_DProgressSsm.cpp
Normal file
74
src/reader2/ISyntaxStateMachine_DProgressSsm.cpp
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/** @file ISyntaxStateMachine_DProgressSsm.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISyntaxStateMachine_DProgressSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISyntaxStateMachine_DProgressSsm.json5]
|
||||
**/
|
||||
|
||||
#include "ssm/ISyntaxStateMachine_DProgressSsm.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
ISyntaxStateMachine_DProgressSsm::ssm_type(const DProgressSsm & self) noexcept -> syntaxstatetype
|
||||
{
|
||||
return self.ssm_type();
|
||||
}
|
||||
|
||||
auto
|
||||
ISyntaxStateMachine_DProgressSsm::get_expect_str(const DProgressSsm & self) noexcept -> std::string_view
|
||||
{
|
||||
return self.get_expect_str();
|
||||
}
|
||||
|
||||
auto
|
||||
ISyntaxStateMachine_DProgressSsm::on_symbol_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_symbol_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DProgressSsm::on_def_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_def_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DProgressSsm::on_if_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_if_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DProgressSsm::on_colon_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_colon_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DProgressSsm::on_singleassign_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_singleassign_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DProgressSsm::on_f64_token(DProgressSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_f64_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DProgressSsm::on_parsed_symbol(DProgressSsm & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_symbol(sym, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DProgressSsm::on_parsed_typedescr(DProgressSsm & self, TypeDescr td, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_typedescr(td, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ISyntaxStateMachine_DProgressSsm.cpp */
|
||||
|
|
@ -163,11 +163,14 @@ namespace xo {
|
|||
this->on_singleassign_token(tk);
|
||||
break;
|
||||
|
||||
case tokentype::tk_f64:
|
||||
this->on_f64_token(tk);
|
||||
break;
|
||||
|
||||
// all the not-yet handled cases
|
||||
case tokentype::tk_invalid:
|
||||
case tokentype::tk_bool:
|
||||
case tokentype::tk_i64:
|
||||
case tokentype::tk_f64:
|
||||
case tokentype::tk_string:
|
||||
case tokentype::tk_leftparen:
|
||||
case tokentype::tk_rightparen:
|
||||
|
|
@ -246,6 +249,14 @@ namespace xo {
|
|||
stack_->top().on_singleassign_token(tk, this);
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::on_f64_token(const Token & tk)
|
||||
{
|
||||
scope log(XO_DEBUG(debug_flag_), xtag("tk", tk));
|
||||
|
||||
stack_->top().on_f64_token(tk, this);
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::capture_error(std::string_view ssm_name,
|
||||
const DString * errmsg)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@
|
|||
#include <xo/reader2/ssm/ISyntaxStateMachine_DExpectExprSsm.hpp>
|
||||
#include <xo/reader2/ssm/IPrintable_DExpectExprSsm.hpp>
|
||||
|
||||
#include <xo/reader2/ssm/ISyntaxStateMachine_DProgressSsm.hpp>
|
||||
#include <xo/reader2/ssm/IPrintable_DProgressSsm.hpp>
|
||||
|
||||
#include <xo/reader2/ssm/ASyntaxStateMachine.hpp>
|
||||
#include <xo/printable2/detail/APrintable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
|
|
@ -51,11 +54,15 @@ namespace xo {
|
|||
FacetRegistry::register_impl<ASyntaxStateMachine, DExpectExprSsm>();
|
||||
FacetRegistry::register_impl<APrintable, DExpectExprSsm>();
|
||||
|
||||
FacetRegistry::register_impl<ASyntaxStateMachine, DProgressSsm>();
|
||||
FacetRegistry::register_impl<APrintable, DProgressSsm>();
|
||||
|
||||
log && log(xtag("DExprSeqState.tseq", typeseq::id<DExprSeqState>()));
|
||||
log && log(xtag("DDefineSsm.tseq", typeseq::id<DDefineSsm>()));
|
||||
log && log(xtag("DExpectSymbolSsm.tseq", typeseq::id<DExpectSymbolSsm>()));
|
||||
log && log(xtag("DExpectTypeSsm.tseq", typeseq::id<DExpectTypeSsm>()));
|
||||
log && log(xtag("DExpectExprSsm.tseq", typeseq::id<DExpectExprSsm>()));
|
||||
log && log(xtag("DProgressSsm.tseq", typeseq::id<DProgressSsm>()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ namespace xo {
|
|||
return "expect-rhs-expression";
|
||||
case syntaxstatetype::defexpr:
|
||||
return "defexpr";
|
||||
case syntaxstatetype::progress:
|
||||
return "progress";
|
||||
case syntaxstatetype::N:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,7 +163,6 @@ namespace xo {
|
|||
REQUIRE(exp_ssm.data()->cxl_on_rightbrace() == false);
|
||||
}
|
||||
|
||||
#ifdef NOT_YET
|
||||
{
|
||||
// future-proofing for Token only holding a string_view
|
||||
const DString * str = DString::from_cstr(expr_alloc, "3.141593");
|
||||
|
|
@ -172,11 +171,10 @@ namespace xo {
|
|||
|
||||
REQUIRE(parser.has_incomplete_expr() == true);
|
||||
|
||||
log && log("after typename symbol token:");
|
||||
log && log("after f64 token:");
|
||||
log && log(xtag("parser", &parser));
|
||||
log && log(xtag("result", result));
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
#ifdef NOT_YET
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue