diff --git a/src/reader2/DDefineSsm.cpp b/src/reader2/DDefineSsm.cpp index 78e29250..aae07b90 100644 --- a/src/reader2/DDefineSsm.cpp +++ b/src/reader2/DDefineSsm.cpp @@ -678,6 +678,8 @@ namespace xo { Super::on_parsed_expression_with_token(expr, tk, p_psm); } + // ----- printable facet ----- + bool DDefineSsm::pretty(const ppindentinfo & ppii) const { diff --git a/src/reader2/ParserStateMachine.cpp b/src/reader2/ParserStateMachine.cpp index 1223abe2..0b2367ad 100644 --- a/src/reader2/ParserStateMachine.cpp +++ b/src/reader2/ParserStateMachine.cpp @@ -6,6 +6,8 @@ #include "ParserStateMachine.hpp" #include "ParserStack.hpp" #include "SyntaxStateMachine.hpp" +#include "ToplevelSeqSsm.hpp" +#include "DefineSsm.hpp" #include #include #include @@ -39,16 +41,52 @@ namespace xo { bool ParserStateMachine::is_at_toplevel() const noexcept { - return ((stack_ == nullptr) - || (stack_->parent() == nullptr)); + /* top-level alwyas has DToplevelSeqSsm */ + + ParserStack * s = stack_; + + if (s) { + auto def = obj::from(s->top()); + + if (def) { + /* carve-out for top-level DefineSsm: report 'at top-level' when + * that top-level DefineSsm is on the stack, so we detect + * this condition inside DefineSsm's event handling + */ + s = stack_->parent(); + } + + if (s && s->parent() == nullptr) { + auto top = obj::from(s->top()); + + return top; + } + } else { + /** this isn't a normal operating state, still need a batch/interactive toplevel seq. + * just the same seems better to call it top-level + **/ + return true; + } + + return false; } bool ParserStateMachine::has_incomplete_expr() const noexcept { + scope log(XO_DEBUG(debug_flag_)); + // don't count toplevel expression - return !(this->is_at_toplevel()); + ParserStack * s = stack_; + + if (s) { + auto top = obj::from(s->top()); + + return !top; + } else { + return false; + } } obj diff --git a/src/reader2/SchematikaParser.cpp b/src/reader2/SchematikaParser.cpp index 9272cfc2..1bb188cb 100644 --- a/src/reader2/SchematikaParser.cpp +++ b/src/reader2/SchematikaParser.cpp @@ -41,7 +41,7 @@ namespace xo { bool SchematikaParser::has_incomplete_expr() const { - return !(this->is_at_toplevel()); + return psm_.has_incomplete_expr(); } obj diff --git a/utest/SchematikaParser.test.cpp b/utest/SchematikaParser.test.cpp index a0557fa6..665342dc 100644 --- a/utest/SchematikaParser.test.cpp +++ b/utest/SchematikaParser.test.cpp @@ -232,7 +232,7 @@ namespace xo { { const auto & testname = Catch::getResultCapture().getCurrentTestName(); - constexpr bool c_debug_flag = false; + constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag), xtag("test", testname)); ParserFixture fixture(testname, c_debug_flag);