From 319c7537f3f125cd186ec253663da19f2aed4342 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 21 Jan 2026 01:24:17 -0500 Subject: [PATCH] xo-reader2: + DExpectTypeSsm + extend DDefineSsm [WIP] --- xo-reader2/CMakeLists.txt | 28 +++++ .../idl/IPrintable_DExpectTypeSsm.json5 | 13 +++ .../ISyntaxStateMachine_DExpectTypeSsm.json5 | 13 +++ .../include/xo/reader2/DExpectTypeSsm.hpp | 48 +++++++-- .../reader2/ssm/IPrintable_DExpectTypeSsm.hpp | 62 +++++++++++ .../ISyntaxStateMachine_DExpectTypeSsm.hpp | 72 +++++++++++++ xo-reader2/src/reader2/CMakeLists.txt | 4 + xo-reader2/src/reader2/DDefineSsm.cpp | 5 +- xo-reader2/src/reader2/DExpectTypeSsm.cpp | 102 +++++++++++++++++- .../src/reader2/IPrintable_DExpectTypeSsm.cpp | 28 +++++ .../ISyntaxStateMachine_DExpectTypeSsm.cpp | 59 ++++++++++ .../src/reader2/reader2_register_facets.cpp | 7 ++ xo-reader2/utest/SchematikaParser.test.cpp | 11 ++ 13 files changed, 442 insertions(+), 10 deletions(-) create mode 100644 xo-reader2/idl/IPrintable_DExpectTypeSsm.json5 create mode 100644 xo-reader2/idl/ISyntaxStateMachine_DExpectTypeSsm.json5 create mode 100644 xo-reader2/include/xo/reader2/ssm/IPrintable_DExpectTypeSsm.hpp create mode 100644 xo-reader2/include/xo/reader2/ssm/ISyntaxStateMachine_DExpectTypeSsm.hpp create mode 100644 xo-reader2/src/reader2/IPrintable_DExpectTypeSsm.cpp create mode 100644 xo-reader2/src/reader2/ISyntaxStateMachine_DExpectTypeSsm.cpp diff --git a/xo-reader2/CMakeLists.txt b/xo-reader2/CMakeLists.txt index ac780154..d8c82e1d 100644 --- a/xo-reader2/CMakeLists.txt +++ b/xo-reader2/CMakeLists.txt @@ -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) # ---------------------------------------------------------------- diff --git a/xo-reader2/idl/IPrintable_DExpectTypeSsm.json5 b/xo-reader2/idl/IPrintable_DExpectTypeSsm.json5 new file mode 100644 index 00000000..1a4ddca2 --- /dev/null +++ b/xo-reader2/idl/IPrintable_DExpectTypeSsm.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + 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" ], +} diff --git a/xo-reader2/idl/ISyntaxStateMachine_DExpectTypeSsm.json5 b/xo-reader2/idl/ISyntaxStateMachine_DExpectTypeSsm.json5 new file mode 100644 index 00000000..d46aaff4 --- /dev/null +++ b/xo-reader2/idl/ISyntaxStateMachine_DExpectTypeSsm.json5 @@ -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" ], +} \ No newline at end of file diff --git a/xo-reader2/include/xo/reader2/DExpectTypeSsm.hpp b/xo-reader2/include/xo/reader2/DExpectTypeSsm.hpp index 84654f83..aebec716 100644 --- a/xo-reader2/include/xo/reader2/DExpectTypeSsm.hpp +++ b/xo-reader2/include/xo/reader2/DExpectTypeSsm.hpp @@ -6,6 +6,7 @@ #pragma once #include "SyntaxStateMachine.hpp" +#include 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 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 make(); }; } /*namespace scm*/ } /*namespace xo*/ -/* end expect_type_xs.hpp */ +/* end DExpectTypeSsm.hpp */ diff --git a/xo-reader2/include/xo/reader2/ssm/IPrintable_DExpectTypeSsm.hpp b/xo-reader2/include/xo/reader2/ssm/IPrintable_DExpectTypeSsm.hpp new file mode 100644 index 00000000..271df307 --- /dev/null +++ b/xo-reader2/include/xo/reader2/ssm/IPrintable_DExpectTypeSsm.hpp @@ -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 +#include +#include "DExpectTypeSsm.hpp" + +namespace xo { namespace scm { class IPrintable_DExpectTypeSsm; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +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 */ \ No newline at end of file diff --git a/xo-reader2/include/xo/reader2/ssm/ISyntaxStateMachine_DExpectTypeSsm.hpp b/xo-reader2/include/xo/reader2/ssm/ISyntaxStateMachine_DExpectTypeSsm.hpp new file mode 100644 index 00000000..c56f21d5 --- /dev/null +++ b/xo-reader2/include/xo/reader2/ssm/ISyntaxStateMachine_DExpectTypeSsm.hpp @@ -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 + { + using ImplType = xo::scm::ISyntaxStateMachine_Xfer + ; + }; + } +} + +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 */ \ No newline at end of file diff --git a/xo-reader2/src/reader2/CMakeLists.txt b/xo-reader2/src/reader2/CMakeLists.txt index 6b17e3d3..b09f015a 100644 --- a/xo-reader2/src/reader2/CMakeLists.txt +++ b/xo-reader2/src/reader2/CMakeLists.txt @@ -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 ) diff --git a/xo-reader2/src/reader2/DDefineSsm.cpp b/xo-reader2/src/reader2/DDefineSsm.cpp index 8941a20d..98a9fa4a 100644 --- a/xo-reader2/src/reader2/DDefineSsm.cpp +++ b/xo-reader2/src/reader2/DDefineSsm.cpp @@ -5,6 +5,7 @@ #include "DDefineSsm.hpp" #include "DExpectSymbolSsm.hpp" +#include "DExpectTypeSsm.hpp" #include "ssm/ISyntaxStateMachine_DDefineSsm.hpp" #include "ssm/IPrintable_DDefineSsm.hpp" #include @@ -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; } diff --git a/xo-reader2/src/reader2/DExpectTypeSsm.cpp b/xo-reader2/src/reader2/DExpectTypeSsm.cpp index b034ae23..ce38473e 100644 --- a/xo-reader2/src/reader2/DExpectTypeSsm.cpp +++ b/xo-reader2/src/reader2/DExpectTypeSsm.cpp @@ -4,8 +4,20 @@ **/ #include "DExpectTypeSsm.hpp" +#include "ssm/ISyntaxStateMachine_DExpectTypeSsm.hpp" +#include "SyntaxStateMachine.hpp" +#include +#include +#include +#include +#include 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 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(); + else if (tk.text() == "str") + td = Reflect::require(); + else if (tk.text() == "f64") + td = Reflect::require(); + else if(tk.text() == "f32") + td = Reflect::require(); + else if(tk.text() == "i16") + td = Reflect::require(); + else if(tk.text() == "i32") + td = Reflect::require(); + else if(tk.text() == "i64") + td = Reflect::require(); + + 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*/ diff --git a/xo-reader2/src/reader2/IPrintable_DExpectTypeSsm.cpp b/xo-reader2/src/reader2/IPrintable_DExpectTypeSsm.cpp new file mode 100644 index 00000000..c82d726e --- /dev/null +++ b/xo-reader2/src/reader2/IPrintable_DExpectTypeSsm.cpp @@ -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 */ \ No newline at end of file diff --git a/xo-reader2/src/reader2/ISyntaxStateMachine_DExpectTypeSsm.cpp b/xo-reader2/src/reader2/ISyntaxStateMachine_DExpectTypeSsm.cpp new file mode 100644 index 00000000..c520aea8 --- /dev/null +++ b/xo-reader2/src/reader2/ISyntaxStateMachine_DExpectTypeSsm.cpp @@ -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 */ \ No newline at end of file diff --git a/xo-reader2/src/reader2/reader2_register_facets.cpp b/xo-reader2/src/reader2/reader2_register_facets.cpp index ee838864..a393eead 100644 --- a/xo-reader2/src/reader2/reader2_register_facets.cpp +++ b/xo-reader2/src/reader2/reader2_register_facets.cpp @@ -14,6 +14,9 @@ #include #include +#include +#include + #include #include #include @@ -39,9 +42,13 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + log && log(xtag("DExprSeqState.tseq", typeseq::id())); log && log(xtag("DDefineSsm.tseq", typeseq::id())); log && log(xtag("DExpectSymbolSsm.tseq", typeseq::id())); + log && log(xtag("DExpectTypeSsm.tseq", typeseq::id())); return true; } diff --git a/xo-reader2/utest/SchematikaParser.test.cpp b/xo-reader2/utest/SchematikaParser.test.cpp index 4e4b778f..af9b8303 100644 --- a/xo-reader2/utest/SchematikaParser.test.cpp +++ b/xo-reader2/utest/SchematikaParser.test.cpp @@ -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());