diff --git a/CMakeLists.txt b/CMakeLists.txt index d8c82e1d..11ce1f07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,6 +138,32 @@ xo_add_genfacetimpl( # ---------------------------------------------------------------- +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-reader2-facetimpl-syntaxstatemachine-expectexprssm + FACET_PKG xo_reader2 + FACET SyntaxStateMachine + REPR ExpectExprSsm + INPUT idl/ISyntaxStateMachine_DExpectExprSsm.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-expectexprssm + FACET_PKG xo_printable2 + FACET Printable + REPR ExpectExprSsm + INPUT idl/IPrintable_DExpectExprSsm.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/idl/IPrintable_DExpectExprSsm.json5 b/idl/IPrintable_DExpectExprSsm.json5 new file mode 100644 index 00000000..72d19cd7 --- /dev/null +++ b/idl/IPrintable_DExpectExprSsm.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + local_types: [], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DExpectExprSsm", + using_doxygen: true, + repr: "DExpectExprSsm", + doc: [ "implement APrintable for DExpectExprSsm" ], +} diff --git a/idl/ISyntaxStateMachine_DExpectExprSsm.json5 b/idl/ISyntaxStateMachine_DExpectExprSsm.json5 new file mode 100644 index 00000000..068ac481 --- /dev/null +++ b/idl/ISyntaxStateMachine_DExpectExprSsm.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 DExpectExprSsm", + using_doxygen: true, + repr: "DExpectExprSsm", + doc: [ "implement ASyntaxStateMachine for DExpectExprSsm" ], +} \ No newline at end of file diff --git a/include/xo/reader2/DExpectExprSsm.hpp b/include/xo/reader2/DExpectExprSsm.hpp index 788f04e8..07456d76 100644 --- a/include/xo/reader2/DExpectExprSsm.hpp +++ b/include/xo/reader2/DExpectExprSsm.hpp @@ -32,7 +32,16 @@ namespace xo { bool allow_defs, bool cxl_on_rightparen, ParserStateMachine * p_psm); + static void start(DArena & parser_mm, + ParserStateMachine * p_psm); + /** @defgroup scm-expectexpr-access-methods access methods **/ + ///@{ + + bool allow_defs() const noexcept { return allow_defs_; } + bool cxl_on_rightbrace() const noexcept { return cxl_on_rightbrace_; } + + ///@} /** @defgroup scm-expectexpr-ssm-facet syntaxstatemachine facet methods **/ ///@{ diff --git a/include/xo/reader2/ssm/IPrintable_DExpectExprSsm.hpp b/include/xo/reader2/ssm/IPrintable_DExpectExprSsm.hpp new file mode 100644 index 00000000..c3f9abc0 --- /dev/null +++ b/include/xo/reader2/ssm/IPrintable_DExpectExprSsm.hpp @@ -0,0 +1,62 @@ +/** @file IPrintable_DExpectExprSsm.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DExpectExprSsm.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DExpectExprSsm.json5] + **/ + +#pragma once + +#include "Printable.hpp" +#include +#include +#include "DExpectExprSsm.hpp" + +namespace xo { namespace scm { class IPrintable_DExpectExprSsm; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DExpectExprSsm + **/ + class IPrintable_DExpectExprSsm { + public: + /** @defgroup scm-printable-dexpectexprssm-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + using Copaque = xo::print::APrintable::Copaque; + using Opaque = xo::print::APrintable::Opaque; + ///@} + /** @defgroup scm-printable-dexpectexprssm-methods **/ + ///@{ + // const methods + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DExpectExprSsm & self, const ppindentinfo & ppii); + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/include/xo/reader2/ssm/ISyntaxStateMachine_DExpectExprSsm.hpp b/include/xo/reader2/ssm/ISyntaxStateMachine_DExpectExprSsm.hpp new file mode 100644 index 00000000..5921f615 --- /dev/null +++ b/include/xo/reader2/ssm/ISyntaxStateMachine_DExpectExprSsm.hpp @@ -0,0 +1,77 @@ +/** @file ISyntaxStateMachine_DExpectExprSsm.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/ISyntaxStateMachine_DExpectExprSsm.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/ISyntaxStateMachine_DExpectExprSsm.json5] + **/ + +#pragma once + +#include "SyntaxStateMachine.hpp" +#include "SyntaxStateMachine.hpp" +#include "ssm/ISyntaxStateMachine_Xfer.hpp" +#include "DExpectExprSsm.hpp" + +namespace xo { namespace scm { class ISyntaxStateMachine_DExpectExprSsm; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::scm::ISyntaxStateMachine_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class ISyntaxStateMachine_DExpectExprSsm + **/ + class ISyntaxStateMachine_DExpectExprSsm { + public: + /** @defgroup scm-syntaxstatemachine-dexpectexprssm-type-traits **/ + ///@{ + using TypeDescr = xo::scm::ASyntaxStateMachine::TypeDescr; + using Copaque = xo::scm::ASyntaxStateMachine::Copaque; + using Opaque = xo::scm::ASyntaxStateMachine::Opaque; + ///@} + /** @defgroup scm-syntaxstatemachine-dexpectexprssm-methods **/ + ///@{ + // const methods + /** identify a type of syntax state machine **/ + static syntaxstatetype ssm_type(const DExpectExprSsm & self) noexcept; + /** text describing expected/allowed input to this ssm in current state **/ + static std::string_view get_expect_str(const DExpectExprSsm & self) noexcept; + + // non-const methods + /** operate state machine for incoming symbol-token @p tk **/ + static void on_symbol_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm); + /** update state machine for incoming define-keyword-token @p tk **/ + static void on_def_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm); + /** update state machine for incoming if-keyword-token @p tk **/ + static void on_if_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm); + /** update state machine for incoming colon-token @p tk **/ + 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 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 **/ + static void on_parsed_typedescr(DExpectExprSsm & self, TypeDescr td, ParserStateMachine * p_psm); + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/include/xo/reader2/syntaxstatetype.hpp b/include/xo/reader2/syntaxstatetype.hpp index 8cb48938..312ec07c 100644 --- a/include/xo/reader2/syntaxstatetype.hpp +++ b/include/xo/reader2/syntaxstatetype.hpp @@ -27,6 +27,9 @@ namespace xo { /** expecting a type. See @ref DExpectTypeSsm **/ expect_type, + /** expecting a rhs expression. See @ref DExpectExprSsm **/ + expect_rhs_expression, + /** handle define-expression. See @ref DDefineSsm **/ defexpr, diff --git a/src/reader2/CMakeLists.txt b/src/reader2/CMakeLists.txt index 661aae2e..ecf8f297 100644 --- a/src/reader2/CMakeLists.txt +++ b/src/reader2/CMakeLists.txt @@ -29,6 +29,8 @@ set(SELF_SRCS IPrintable_DExpectTypeSsm.cpp DExpectExprSsm.cpp + ISyntaxStateMachine_DExpectExprSsm.cpp + IPrintable_DExpectExprSsm.cpp reader2_register_facets.cpp reader2_register_types.cpp diff --git a/src/reader2/DDefineSsm.cpp b/src/reader2/DDefineSsm.cpp index 78667376..ea0d976a 100644 --- a/src/reader2/DDefineSsm.cpp +++ b/src/reader2/DDefineSsm.cpp @@ -6,6 +6,7 @@ #include "DDefineSsm.hpp" #include "DExpectSymbolSsm.hpp" #include "DExpectTypeSsm.hpp" +#include "DExpectExprSsm.hpp" #include "ssm/ISyntaxStateMachine_DDefineSsm.hpp" #include "ssm/IPrintable_DDefineSsm.hpp" #include @@ -554,9 +555,8 @@ namespace xo { { this->defstate_ = defexprstatetype::def_5; - // TODO: DExpectExprSsm::start(...) - log && log("STUB: DExpectExprSsm not implemented"); - + DExpectExprSsm::start(p_psm->parser_alloc(), + p_psm); return; } diff --git a/src/reader2/DExpectExprSsm.cpp b/src/reader2/DExpectExprSsm.cpp index 696aa790..235f4b19 100644 --- a/src/reader2/DExpectExprSsm.cpp +++ b/src/reader2/DExpectExprSsm.cpp @@ -5,6 +5,10 @@ #include "DExpectExprSsm.hpp" #include "ParserStateMachine.hpp" +#include "SyntaxStateMachine.hpp" +#include "ssm/ISyntaxStateMachine_DExpectExprSsm.hpp" +#include "syntaxstatetype.hpp" +#include #ifdef NOT_YET #include "exprstatestack.hpp" @@ -24,43 +28,64 @@ namespace xo { using xo::scm::Constant; #endif + using xo::reflect::typeseq; + using xo::facet::with_facet; + namespace scm { -#ifdef NOT_YET - std::unique_ptr - expect_expr_xs::make(bool allow_defs, + DExpectExprSsm::DExpectExprSsm(bool allow_defs, + bool cxl_on_rightbrace) + : allow_defs_{allow_defs}, + cxl_on_rightbrace_{cxl_on_rightbrace} + { + } + + DExpectExprSsm * + DExpectExprSsm::make(DArena & mm, + bool allow_defs, bool cxl_on_rightbrace) { - return std::make_unique(expect_expr_xs(allow_defs, - cxl_on_rightbrace)); + void * mem = mm.alloc(typeseq::id(), + sizeof(DExpectExprSsm)); + return new (mem) DExpectExprSsm(allow_defs, + cxl_on_rightbrace); } void - expect_expr_xs::start(bool allow_defs, + DExpectExprSsm::start(DArena & mm, + bool allow_defs, bool cxl_on_rightbrace, - parserstatemachine * p_psm) + ParserStateMachine * p_psm) { - p_psm->push_exprstate(expect_expr_xs::make(allow_defs, - cxl_on_rightbrace)); + DExpectExprSsm * exp_expr + = DExpectExprSsm::make(mm, + allow_defs, + cxl_on_rightbrace); + obj ssm + = with_facet::mkobj(exp_expr); + + p_psm->push_ssm(ssm); } void - expect_expr_xs::start(parserstatemachine * p_psm) { - start(false /*!allow_defs*/, + DExpectExprSsm::start(DArena & mm, + ParserStateMachine * p_psm) + { + start(mm, + false /*!allow_defs*/, false /*!cxl_on_rightbrace*/, p_psm); } - expect_expr_xs::expect_expr_xs(bool allow_defs, - bool cxl_on_rightbrace) - : exprstate(exprstatetype::expect_rhs_expression), - allow_defs_{allow_defs}, - cxl_on_rightbrace_{cxl_on_rightbrace} - {} + syntaxstatetype + DExpectExprSsm::ssm_type() const noexcept + { + return syntaxstatetype::expect_rhs_expression; + } - const char * - expect_expr_xs::get_expect_str() const + std::string_view + DExpectExprSsm::get_expect_str() const noexcept { if (allow_defs_) { return "def|lambda|lparen|lbrace|literal|var"; @@ -69,6 +94,80 @@ namespace xo { } } + void + DExpectExprSsm::on_symbol_token(const Token & tk, + ParserStateMachine * p_psm) + { + p_psm->illegal_input_on_token("DExpectExprSsm", + tk, + this->get_expect_str()); + } + + void + DExpectExprSsm::on_def_token(const Token & tk, + ParserStateMachine * p_psm) + { + p_psm->illegal_input_on_token("DExpectExprSsm", + tk, + this->get_expect_str()); + } + + void + DExpectExprSsm::on_if_token(const Token & tk, + ParserStateMachine * p_psm) + { + p_psm->illegal_input_on_token("DExpectExprSsm", + tk, + this->get_expect_str()); + } + + void + DExpectExprSsm::on_colon_token(const Token & tk, + ParserStateMachine * p_psm) + { + p_psm->illegal_input_on_token("DExpectExprSsm", + tk, + this->get_expect_str()); + } + + void + DExpectExprSsm::on_singleassign_token(const Token & tk, + ParserStateMachine * p_psm) + { + p_psm->illegal_input_on_token("DExpectExprSsm", + tk, + this->get_expect_str()); + } + + void + DExpectExprSsm::on_parsed_symbol(std::string_view sym, + ParserStateMachine * p_psm) + { + p_psm->illegal_input_on_symbol("DExpectExprSsm", + sym, + this->get_expect_str()); + } + + void + DExpectExprSsm::on_parsed_typedescr(TypeDescr td, + ParserStateMachine * p_psm) + { + p_psm->illegal_input_on_typedescr("DExpectExprSsm", + td, + this->get_expect_str()); + } + + bool + DExpectExprSsm::pretty(const ppindentinfo & ppii) const + { + return ppii.pps()->pretty_struct + (ppii, + "DExpectExprSsm", + refrtag("allow_defs", allow_defs_), + refrtag("cxl_on_rightbrace", cxl_on_rightbrace_)); + } + +#ifdef NOT_YET void expect_expr_xs::on_def_token(const token_type & tk, parserstatemachine * p_psm) diff --git a/src/reader2/IPrintable_DExpectExprSsm.cpp b/src/reader2/IPrintable_DExpectExprSsm.cpp new file mode 100644 index 00000000..2b656fb2 --- /dev/null +++ b/src/reader2/IPrintable_DExpectExprSsm.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DExpectExprSsm.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DExpectExprSsm.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DExpectExprSsm.json5] +**/ + +#include "ssm/IPrintable_DExpectExprSsm.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DExpectExprSsm::pretty(const DExpectExprSsm & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DExpectExprSsm.cpp */ \ No newline at end of file diff --git a/src/reader2/ISyntaxStateMachine_DExpectExprSsm.cpp b/src/reader2/ISyntaxStateMachine_DExpectExprSsm.cpp new file mode 100644 index 00000000..de751479 --- /dev/null +++ b/src/reader2/ISyntaxStateMachine_DExpectExprSsm.cpp @@ -0,0 +1,69 @@ +/** @file ISyntaxStateMachine_DExpectExprSsm.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/ISyntaxStateMachine_DExpectExprSsm.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/ISyntaxStateMachine_DExpectExprSsm.json5] +**/ + +#include "ssm/ISyntaxStateMachine_DExpectExprSsm.hpp" + +namespace xo { + namespace scm { + auto + ISyntaxStateMachine_DExpectExprSsm::ssm_type(const DExpectExprSsm & self) noexcept -> syntaxstatetype + { + return self.ssm_type(); + } + + auto + ISyntaxStateMachine_DExpectExprSsm::get_expect_str(const DExpectExprSsm & self) noexcept -> std::string_view + { + return self.get_expect_str(); + } + + auto + ISyntaxStateMachine_DExpectExprSsm::on_symbol_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void + { + self.on_symbol_token(tk, p_psm); + } + auto + ISyntaxStateMachine_DExpectExprSsm::on_def_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void + { + self.on_def_token(tk, p_psm); + } + auto + ISyntaxStateMachine_DExpectExprSsm::on_if_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void + { + self.on_if_token(tk, p_psm); + } + auto + ISyntaxStateMachine_DExpectExprSsm::on_colon_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void + { + self.on_colon_token(tk, p_psm); + } + auto + ISyntaxStateMachine_DExpectExprSsm::on_singleassign_token(DExpectExprSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void + { + self.on_singleassign_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); + } + auto + ISyntaxStateMachine_DExpectExprSsm::on_parsed_typedescr(DExpectExprSsm & self, TypeDescr td, ParserStateMachine * p_psm) -> void + { + self.on_parsed_typedescr(td, p_psm); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end ISyntaxStateMachine_DExpectExprSsm.cpp */ \ No newline at end of file diff --git a/src/reader2/reader2_register_facets.cpp b/src/reader2/reader2_register_facets.cpp index a393eead..cdade07b 100644 --- a/src/reader2/reader2_register_facets.cpp +++ b/src/reader2/reader2_register_facets.cpp @@ -17,6 +17,9 @@ #include #include +#include +#include + #include #include #include @@ -45,10 +48,14 @@ 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())); + log && log(xtag("DExpectExprSsm.tseq", typeseq::id())); return true; } diff --git a/src/reader2/syntaxstatetype.cpp b/src/reader2/syntaxstatetype.cpp index cf8a9784..ac09b92e 100644 --- a/src/reader2/syntaxstatetype.cpp +++ b/src/reader2/syntaxstatetype.cpp @@ -19,6 +19,8 @@ namespace xo { return "expect-symbol"; case syntaxstatetype::expect_type: return "expect-type"; + case syntaxstatetype::expect_rhs_expression: + return "expect-rhs-expression"; case syntaxstatetype::defexpr: return "defexpr"; case syntaxstatetype::N: diff --git a/utest/SchematikaParser.test.cpp b/utest/SchematikaParser.test.cpp index 203f2eaa..e0f813e4 100644 --- a/utest/SchematikaParser.test.cpp +++ b/utest/SchematikaParser.test.cpp @@ -5,6 +5,8 @@ #include #include +#include +#include #include #include #include @@ -15,10 +17,12 @@ namespace xo { using xo::scm::ASyntaxStateMachine; using xo::scm::syntaxstatetype; using xo::scm::DDefineSsm; + using xo::scm::DExpectExprSsm; using xo::scm::defexprstatetype; - using xo::scm::ParserResult; - using xo::scm::parser_result_type; + //using xo::scm::ParserResult; + //using xo::scm::parser_result_type; using xo::scm::Token; + using xo::scm::DString; using xo::mm::ArenaConfig; using xo::mm::AAllocator; using xo::mm::DArena; @@ -150,12 +154,39 @@ namespace xo { log && log(xtag("parser", &parser)); log && log(xtag("result", result)); + auto exp_ssm + = obj::from(parser.top_ssm()); + + REQUIRE(exp_ssm); + REQUIRE(exp_ssm.data()->ssm_type() == syntaxstatetype::expect_rhs_expression); + REQUIRE(exp_ssm.data()->allow_defs() == false); + 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"); + + auto & result = parser.on_token(Token::f64_token(std::string(*str))); + + REQUIRE(parser.has_incomplete_expr() == true); + + log && log("after typename symbol token:"); + log && log(xtag("parser", &parser)); + log && log(xtag("result", result)); + } +#endif + + { +#ifdef NOT_YET auto def_ssm = obj::from(parser.top_ssm()); REQUIRE(def_ssm); REQUIRE(def_ssm.data()->ssm_type() == syntaxstatetype::defexpr); REQUIRE(def_ssm.data()->defstate() == defexprstatetype::def_5); +#endif } // define-expressions not properly implemented