diff --git a/xo-reader2/include/xo/reader2/ParserStateMachine.hpp b/xo-reader2/include/xo/reader2/ParserStateMachine.hpp index c3c179ad..466e07f8 100644 --- a/xo-reader2/include/xo/reader2/ParserStateMachine.hpp +++ b/xo-reader2/include/xo/reader2/ParserStateMachine.hpp @@ -31,15 +31,16 @@ namespace xo { using DArena = xo::mm::DArena; public: - ParserStateMachine(const ArenaConfig & config); + ParserStateMachine(const ArenaConfig & config, + obj * expr_alloc); /** @defgroup scm-parserstatemachine-accessors accessor methods **/ ///@{ bool debug_flag() const noexcept { return debug_flag_; } ParserStack * stack() const noexcept { return stack_; } + obj * expr_alloc() const noexcept { return expr_alloc_; } const ParserResult & result() const noexcept { return result_; } - obj expr_alloc() const noexcept { return expr_alloc_; } /** true iff state machine is currently idle (at top-level) **/ bool is_at_toplevel() const noexcept; @@ -133,7 +134,7 @@ namespace xo { * scenario, where top-level Expressions can be discarded * once compiled. **/ - obj expr_alloc_; + obj * expr_alloc_ = nullptr; /** current output from parser **/ ParserResult result_; diff --git a/xo-reader2/include/xo/reader2/SchematikaParser.hpp b/xo-reader2/include/xo/reader2/SchematikaParser.hpp index 8b4688ce..7d5f36d2 100644 --- a/xo-reader2/include/xo/reader2/SchematikaParser.hpp +++ b/xo-reader2/include/xo/reader2/SchematikaParser.hpp @@ -8,6 +8,7 @@ #include "ParserStateMachine.hpp" #include "ParserResult.hpp" #include +#include namespace xo { namespace scm { @@ -153,6 +154,7 @@ namespace xo { class SchematikaParser { public: using ArenaConfig = xo::mm::ArenaConfig; + using AAllocator = xo::mm::AAllocator; using token_type = Token; public: @@ -160,9 +162,13 @@ namespace xo { * parser is ready to receive tokens via @ref include_token * * @p config arena configuration for parser memory + * @p expr_alloc allocator for schematika expressions. + * Probably shared with execution. * @p debug_flag true to enable debug logging **/ - SchematikaParser(const ArenaConfig & config, bool debug_flag); + SchematikaParser(const ArenaConfig & config, + obj * expr_alloc, + bool debug_flag); bool debug_flag() const { return debug_flag_; } diff --git a/xo-reader2/src/reader2/ParserStateMachine.cpp b/xo-reader2/src/reader2/ParserStateMachine.cpp index 4f54a584..4756975a 100644 --- a/xo-reader2/src/reader2/ParserStateMachine.cpp +++ b/xo-reader2/src/reader2/ParserStateMachine.cpp @@ -16,9 +16,10 @@ namespace xo { using xo::facet::with_facet; namespace scm { - ParserStateMachine::ParserStateMachine(const ArenaConfig & config) + ParserStateMachine::ParserStateMachine(const ArenaConfig & config, + obj * expr_alloc) : parser_alloc_{DArena::map(config)}, - expr_alloc_{with_facet::mkobj(&parser_alloc_)}, + expr_alloc_{expr_alloc}, debug_flag_{config.debug_flag_} { } @@ -176,7 +177,9 @@ namespace xo { xtag("ssm", ssm_name), xtag("via", "ParserStateMachine::illegal_input_on_token")); - auto errmsg = DString::from_view(expr_alloc_, + assert(expr_alloc_); + + auto errmsg = DString::from_view(*expr_alloc_, std::string_view(errmsg_string)); this->capture_error(ssm_name, errmsg); diff --git a/xo-reader2/src/reader2/SchematikaParser.cpp b/xo-reader2/src/reader2/SchematikaParser.cpp index 2e607e77..67af915f 100644 --- a/xo-reader2/src/reader2/SchematikaParser.cpp +++ b/xo-reader2/src/reader2/SchematikaParser.cpp @@ -11,14 +11,17 @@ #include namespace xo { + using xo::mm::AAllocator; using xo::tostr; using xo::xtag; namespace scm { // ----- SchematikaParser ----- - SchematikaParser::SchematikaParser(const ArenaConfig & config, bool debug_flag) - : psm_{config}, + SchematikaParser::SchematikaParser(const ArenaConfig & config, + obj * expr_alloc, + bool debug_flag) + : psm_{config, expr_alloc}, debug_flag_{debug_flag} { } @@ -35,13 +38,13 @@ namespace xo { void SchematikaParser::begin_interactive_session() { - DExprSeqState::establish_interactive(psm_.expr_alloc(), &psm_); + DExprSeqState::establish_interactive(*(psm_.expr_alloc()), &psm_); } void SchematikaParser::begin_translation_unit() { - DExprSeqState::establish_batch(psm_.expr_alloc(), &psm_); + DExprSeqState::establish_batch(*(psm_.expr_alloc()), &psm_); } const ParserResult &