xo-reader2: + DExpectTypeSsm + extend DDefineSsm [WIP]

This commit is contained in:
Roland Conybeare 2026-01-21 01:24:17 -05:00
commit 7b62bd7f5c
13 changed files with 442 additions and 10 deletions

View file

@ -110,6 +110,34 @@ xo_add_genfacetimpl(
OUTPUT_CPP_DIR src/reader2
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-reader2-facetimpl-syntaxstatemachine-expecttypessm
FACET_PKG xo_reader2
FACET SyntaxStateMachine
REPR ExpectTypeSsm
INPUT idl/ISyntaxStateMachine_DExpectTypeSsm.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-expecttypessm
FACET_PKG xo_printable2
FACET Printable
REPR ExpectTypeSsm
INPUT idl/IPrintable_DExpectTypeSsm.json5
OUTPUT_HPP_DIR include/xo/reader2
OUTPUT_IMPL_SUBDIR ssm
OUTPUT_CPP_DIR src/reader2
)
# ----------------------------------------------------------------
xo_add_genfacet_all(xo-reader2-genfacet-all)
# ----------------------------------------------------------------

View 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 DExpectTypeSsm",
using_doxygen: true,
repr: "DExpectTypeSsm",
doc: [ "implement APrintable for DExpectTypeSsm" ],
}

View 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 DExpectTypeSsm",
using_doxygen: true,
repr: "DExpectTypeSsm",
doc: [ "implement ASyntaxStateMachine for DExpectTypeSsm" ],
}

View file

@ -6,6 +6,7 @@
#pragma once
#include "SyntaxStateMachine.hpp"
#include <xo/indentlog/print/ppindentinfo.hpp>
namespace xo {
namespace scm {
@ -21,6 +22,10 @@ namespace xo {
* @endpre
**/
class DExpectTypeSsm {
public:
using DArena = xo::mm::DArena;
using ppindentinfo = xo::print::ppindentinfo;
public:
DExpectTypeSsm();
@ -30,11 +35,6 @@ namespace xo {
//obj<AAllocator> expr_mm,
ParserStateMachine * p_psm);
virtual const char * get_expect_str() const override;
virtual void on_symbol_token(const token_type & tk,
parserstatemachine * p_psm) override;
/** @defgroup scm-expecttype-ssm-facet syntaxstatemachine facet methods **/
///@{
@ -52,13 +52,45 @@ namespace xo {
void on_symbol_token(const Token & tk,
ParserStateMachine * p_psm);
/** operate state machine for this syntax on incoming define-token @p tk
* with overall parser state in @p p_psm
**/
void on_def_token(const Token & tk,
ParserStateMachine * p_psm);
/** operate state machine for this syntax on incoming if-token @p tk
* with overall parser state in @p p_psm
**/
void on_if_token(const Token & tk,
ParserStateMachine * p_psm);
/** operate state machine for this syntax on incoming colon-token @p tk
* with overall parser state in @p p_psm
**/
void on_colon_token(const Token & tk,
ParserStateMachine * p_psm);
/** Never called.
* Operate state machine for this syntax after symbol
* emitted from nested ssm.
* Impossible path for DExpectTypeSsm until such time as it relies
* on nested ssms. Currently using on_symbol_token
* entry point instead.
**/
void on_parsed_symbol(std::string_view sym,
ParserStateMachine * p_psm);
///@}
/** @defgroup scm-expecttype-printable-facet printable facet methods **/
///@{
bool pretty(const ppindentinfo & ppii) const;
///@}
private:
static std::unique_ptr<expect_type_xs> make();
};
} /*namespace scm*/
} /*namespace xo*/
/* end expect_type_xs.hpp */
/* end DExpectTypeSsm.hpp */

View file

@ -0,0 +1,62 @@
/** @file IPrintable_DExpectTypeSsm.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DExpectTypeSsm.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DExpectTypeSsm.json5]
**/
#pragma once
#include "Printable.hpp"
#include <xo/printable2/Printable.hpp>
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
#include "DExpectTypeSsm.hpp"
namespace xo { namespace scm { class IPrintable_DExpectTypeSsm; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::print::APrintable,
xo::scm::DExpectTypeSsm>
{
using ImplType = xo::print::IPrintable_Xfer
<xo::scm::DExpectTypeSsm,
xo::scm::IPrintable_DExpectTypeSsm>;
};
}
}
namespace xo {
namespace scm {
/** @class IPrintable_DExpectTypeSsm
**/
class IPrintable_DExpectTypeSsm {
public:
/** @defgroup scm-printable-dexpecttypessm-type-traits **/
///@{
using ppindentinfo = xo::print::APrintable::ppindentinfo;
using Copaque = xo::print::APrintable::Copaque;
using Opaque = xo::print::APrintable::Opaque;
///@}
/** @defgroup scm-printable-dexpecttypessm-methods **/
///@{
// const methods
/** Pretty-printing support for this object.
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
static bool pretty(const DExpectTypeSsm & self, const ppindentinfo & ppii);
// non-const methods
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -0,0 +1,72 @@
/** @file ISyntaxStateMachine_DExpectTypeSsm.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/ISyntaxStateMachine_DExpectTypeSsm.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/ISyntaxStateMachine_DExpectTypeSsm.json5]
**/
#pragma once
#include "SyntaxStateMachine.hpp"
#include "SyntaxStateMachine.hpp"
#include "ssm/ISyntaxStateMachine_Xfer.hpp"
#include "DExpectTypeSsm.hpp"
namespace xo { namespace scm { class ISyntaxStateMachine_DExpectTypeSsm; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::scm::ASyntaxStateMachine,
xo::scm::DExpectTypeSsm>
{
using ImplType = xo::scm::ISyntaxStateMachine_Xfer
<xo::scm::DExpectTypeSsm,
xo::scm::ISyntaxStateMachine_DExpectTypeSsm>;
};
}
}
namespace xo {
namespace scm {
/** @class ISyntaxStateMachine_DExpectTypeSsm
**/
class ISyntaxStateMachine_DExpectTypeSsm {
public:
/** @defgroup scm-syntaxstatemachine-dexpecttypessm-type-traits **/
///@{
using Copaque = xo::scm::ASyntaxStateMachine::Copaque;
using Opaque = xo::scm::ASyntaxStateMachine::Opaque;
///@}
/** @defgroup scm-syntaxstatemachine-dexpecttypessm-methods **/
///@{
// const methods
/** identify a type of syntax state machine **/
static syntaxstatetype ssm_type(const DExpectTypeSsm & self) noexcept;
/** text describing expected/allowed input to this ssm in current state **/
static std::string_view get_expect_str(const DExpectTypeSsm & self) noexcept;
// non-const methods
/** operate state machine for incoming symbol-token @p tk **/
static void on_symbol_token(DExpectTypeSsm & self, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for incoming define-keyword-token @p tk **/
static void on_def_token(DExpectTypeSsm & self, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for incoming if-keyword-token @p tk **/
static void on_if_token(DExpectTypeSsm & self, const Token & tk, ParserStateMachine * p_psm);
/** update state machine for incoming colon-token @p tk **/
static void on_colon_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);
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -23,6 +23,10 @@ set(SELF_SRCS
ISyntaxStateMachine_DExpectSymbolSsm.cpp
IPrintable_DExpectSymbolSsm.cpp
DExpectTypeSsm.cpp
ISyntaxStateMachine_DExpectTypeSsm.cpp
IPrintable_DExpectTypeSsm.cpp
reader2_register_facets.cpp
reader2_register_types.cpp
)

View file

@ -5,6 +5,7 @@
#include "DDefineSsm.hpp"
#include "DExpectSymbolSsm.hpp"
#include "DExpectTypeSsm.hpp"
#include "ssm/ISyntaxStateMachine_DDefineSsm.hpp"
#include "ssm/IPrintable_DDefineSsm.hpp"
#include <xo/expression2/detail/IPrintable_DDefineExpr.hpp>
@ -505,7 +506,9 @@ namespace xo {
if (defstate_ == defexprstatetype::def_2) {
this->defstate_ = defexprstatetype::def_3;
// expect_type_xs::start(p_psm);
DExpectTypeSsm::start(p_psm->parser_alloc(),
p_psm);
return;
}

View file

@ -4,8 +4,20 @@
**/
#include "DExpectTypeSsm.hpp"
#include "ssm/ISyntaxStateMachine_DExpectTypeSsm.hpp"
#include "SyntaxStateMachine.hpp"
#include <string_view>
#include <xo/reflect/Reflect.hpp>
#include <xo/facet/facet_implementation.hpp>
#include <xo/reflectutil/typeseq.hpp>
#include <xo/indentlog/print/pretty.hpp>
namespace xo {
using xo::facet::with_facet;
using xo::reflect::Reflect;
using xo::reflect::TypeDescr;
using xo::reflect::typeseq;
namespace scm {
DExpectTypeSsm::DExpectTypeSsm()
{}
@ -22,7 +34,7 @@ namespace xo {
void
DExpectTypeSsm::start(DArena & mm,
//obj<AAllocator> expr_mm,
PArserStateMachine * p_psm)
ParserStateMachine * p_psm)
{
DExpectTypeSsm * expect_type_ssm = DExpectTypeSsm::make(mm);
@ -38,6 +50,94 @@ namespace xo {
return syntaxstatetype::expect_type;
}
std::string_view
DExpectTypeSsm::get_expect_str() const noexcept
{
return "typename";
}
void
DExpectTypeSsm::on_def_token(const Token & tk,
ParserStateMachine * p_psm)
{
p_psm->illegal_input_on_token("DExpectTypeSsm",
tk,
this->get_expect_str());
}
void
DExpectTypeSsm::on_if_token(const Token & tk,
ParserStateMachine * p_psm)
{
p_psm->illegal_input_on_token("DxpectTypeSsm",
tk,
this->get_expect_str());
}
void
DExpectTypeSsm::on_colon_token(const Token & tk,
ParserStateMachine * p_psm)
{
p_psm->illegal_input_on_token("DxpectTypeSsm",
tk,
this->get_expect_str());
}
void
DExpectTypeSsm::on_symbol_token(const Token & tk,
ParserStateMachine * p_psm)
{
scope log(XO_DEBUG(true));
TypeDescr td = nullptr;
/* TODO: replace with typetable lookup */
if (tk.text() == "bool")
td = Reflect::require<bool>();
else if (tk.text() == "str")
td = Reflect::require<std::string>();
else if (tk.text() == "f64")
td = Reflect::require<double>();
else if(tk.text() == "f32")
td = Reflect::require<float>();
else if(tk.text() == "i16")
td = Reflect::require<std::int16_t>();
else if(tk.text() == "i32")
td = Reflect::require<std::int32_t>();
else if(tk.text() == "i64")
td = Reflect::require<std::int64_t>();
if (!td) {
p_psm->illegal_input_on_token("DExpectTypeSsm",
tk,
this->get_expect_str());
}
p_psm->pop_ssm();
log && log("STUB: missing on_typedescr() call");
//p_psm->on_typedescr(td);
}
void
DExpectTypeSsm::on_parsed_symbol(std::string_view sym,
ParserStateMachine * p_psm)
{
p_psm->illegal_input_on_symbol("ExpectTypeSsm",
sym,
this->get_expect_str());
}
bool
DExpectTypeSsm::pretty(const ppindentinfo & ppii) const
{
return ppii.pps()->pretty_struct
(ppii,
"DExpectTypeSsm");
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -0,0 +1,28 @@
/** @file IPrintable_DExpectTypeSsm.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DExpectTypeSsm.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DExpectTypeSsm.json5]
**/
#include "ssm/IPrintable_DExpectTypeSsm.hpp"
namespace xo {
namespace scm {
auto
IPrintable_DExpectTypeSsm::pretty(const DExpectTypeSsm & self, const ppindentinfo & ppii) -> bool
{
return self.pretty(ppii);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IPrintable_DExpectTypeSsm.cpp */

View file

@ -0,0 +1,59 @@
/** @file ISyntaxStateMachine_DExpectTypeSsm.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/ISyntaxStateMachine_DExpectTypeSsm.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/ISyntaxStateMachine_DExpectTypeSsm.json5]
**/
#include "ssm/ISyntaxStateMachine_DExpectTypeSsm.hpp"
namespace xo {
namespace scm {
auto
ISyntaxStateMachine_DExpectTypeSsm::ssm_type(const DExpectTypeSsm & self) noexcept -> syntaxstatetype
{
return self.ssm_type();
}
auto
ISyntaxStateMachine_DExpectTypeSsm::get_expect_str(const DExpectTypeSsm & self) noexcept -> std::string_view
{
return self.get_expect_str();
}
auto
ISyntaxStateMachine_DExpectTypeSsm::on_symbol_token(DExpectTypeSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
{
self.on_symbol_token(tk, p_psm);
}
auto
ISyntaxStateMachine_DExpectTypeSsm::on_def_token(DExpectTypeSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
{
self.on_def_token(tk, p_psm);
}
auto
ISyntaxStateMachine_DExpectTypeSsm::on_if_token(DExpectTypeSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
{
self.on_if_token(tk, p_psm);
}
auto
ISyntaxStateMachine_DExpectTypeSsm::on_colon_token(DExpectTypeSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
{
self.on_colon_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);
}
} /*namespace scm*/
} /*namespace xo*/
/* end ISyntaxStateMachine_DExpectTypeSsm.cpp */

View file

@ -14,6 +14,9 @@
#include <xo/reader2/ssm/ISyntaxStateMachine_DExpectSymbolSsm.hpp>
#include <xo/reader2/ssm/IPrintable_DExpectSymbolSsm.hpp>
#include <xo/reader2/ssm/ISyntaxStateMachine_DExpectTypeSsm.hpp>
#include <xo/reader2/ssm/IPrintable_DExpectTypeSsm.hpp>
#include <xo/reader2/ssm/ASyntaxStateMachine.hpp>
#include <xo/printable2/detail/APrintable.hpp>
#include <xo/facet/FacetRegistry.hpp>
@ -39,9 +42,13 @@ namespace xo {
FacetRegistry::register_impl<ASyntaxStateMachine, DExpectSymbolSsm>();
FacetRegistry::register_impl<APrintable, DExpectSymbolSsm>();
FacetRegistry::register_impl<ASyntaxStateMachine, DExpectTypeSsm>();
FacetRegistry::register_impl<APrintable, DExpectTypeSsm>();
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>()));
return true;
}

View file

@ -123,6 +123,17 @@ namespace xo {
log && log(xtag("result", result));
}
{
auto & result = parser.on_token(Token::symbol_token("f64"));
REQUIRE(parser.has_incomplete_expr() == true);
REQUIRE(result.is_incomplete());
log && log("after typename symbol token:");
log && log(xtag("parser", &parser));
log && log(xtag("result", result));
}
// define-expressions not properly implemented
//REQUIRE(result.error_description());