xo-reader2: corrections to toplevel SchematikaParser setup
This commit is contained in:
parent
0aa1692f8c
commit
a8eb35bd1a
7 changed files with 93 additions and 34 deletions
|
|
@ -30,25 +30,21 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
DExprSeqState::start_interactive(obj<AAllocator> mm,
|
||||
ParserStateMachine * p_psm)
|
||||
DExprSeqState::establish_interactive(obj<AAllocator> mm,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
|
||||
|
||||
p_psm->push_ssm(make_exprseq_ssm(mm,
|
||||
exprseqtype::toplevel_interactive));
|
||||
p_psm->establish_toplevel_ssm(make_exprseq_ssm
|
||||
(mm,
|
||||
exprseqtype::toplevel_interactive));
|
||||
}
|
||||
|
||||
void
|
||||
DExprSeqState::start_batch(obj<AAllocator> mm,
|
||||
ParserStateMachine * p_psm)
|
||||
DExprSeqState::establish_batch(obj<AAllocator> mm,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
(void)mm;
|
||||
(void)p_psm;
|
||||
#ifdef NOT_YET
|
||||
p_psm->push_ssm(make_exprseq_ssm(mm,
|
||||
exprseqtype::toplevel_batch));
|
||||
#endif
|
||||
p_psm->establish_toplevel_ssm(make_exprseq_ssm
|
||||
(mm,
|
||||
exprseqtype::toplevel_batch));
|
||||
}
|
||||
|
||||
// SyntaxStateMachine facet methods
|
||||
|
|
|
|||
|
|
@ -16,14 +16,15 @@ namespace xo {
|
|||
{}
|
||||
|
||||
ParserStack *
|
||||
ParserStack::push(obj<AAllocator> mm,
|
||||
ParserStack::push(ParserStack * stack,
|
||||
obj<AAllocator> mm,
|
||||
obj<ASyntaxStateMachine> ssm)
|
||||
|
||||
{
|
||||
void * mem = mm.alloc(typeseq::id<ParserStack>(),
|
||||
sizeof(ParserStack));
|
||||
|
||||
return new (mem) ParserStack(ssm, parent_);
|
||||
return new (mem) ParserStack(ssm, stack);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -23,6 +23,35 @@ namespace xo {
|
|||
{
|
||||
}
|
||||
|
||||
bool
|
||||
ParserStateMachine::is_at_toplevel() const noexcept
|
||||
{
|
||||
return ((stack_ == nullptr)
|
||||
|| (stack_->parent() == nullptr));
|
||||
}
|
||||
|
||||
bool
|
||||
ParserStateMachine::has_incomplete_expr() const noexcept
|
||||
{
|
||||
// don't count toplevel expression
|
||||
|
||||
return !(this->is_at_toplevel());
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::establish_toplevel_ssm(obj<ASyntaxStateMachine> ssm)
|
||||
{
|
||||
scope log(XO_DEBUG(debug_flag_));
|
||||
|
||||
assert(stack_ == nullptr);
|
||||
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&parser_alloc_);
|
||||
|
||||
this->stack_ = ParserStack::push(nullptr /*stack*/,
|
||||
alloc, ssm);
|
||||
this->parser_alloc_ckp_ = parser_alloc_.checkpoint();
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::push_ssm(obj<ASyntaxStateMachine> ssm)
|
||||
{
|
||||
|
|
@ -32,7 +61,24 @@ namespace xo {
|
|||
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&parser_alloc_);
|
||||
|
||||
this->stack_ = stack_->push(alloc, ssm);
|
||||
this->stack_ = ParserStack::push(stack_, alloc, ssm);
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::reset_result()
|
||||
{
|
||||
this->result_ = ParserResult();
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::clear_error_reset()
|
||||
{
|
||||
this->reset_result();
|
||||
|
||||
while (stack_ && stack_->parent())
|
||||
stack_ = stack_->parent();
|
||||
|
||||
this->parser_alloc_.restore(parser_alloc_ckp_);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -25,26 +25,23 @@ namespace xo {
|
|||
|
||||
bool
|
||||
SchematikaParser::is_at_toplevel() const {
|
||||
return psm_.stack() == nullptr;
|
||||
return psm_.is_at_toplevel();
|
||||
}
|
||||
|
||||
bool
|
||||
SchematikaParser::has_incomplete_expr() const {
|
||||
/* (don't count toplevel exprseq) */
|
||||
ParserStack * stack = psm_.stack();
|
||||
if (!stack)
|
||||
return false;
|
||||
return stack->parent() != nullptr;
|
||||
return !(this->is_at_toplevel());
|
||||
}
|
||||
|
||||
void
|
||||
SchematikaParser::begin_interactive_session() {
|
||||
DExprSeqState::start_interactive(psm_.expr_alloc(), &psm_);
|
||||
DExprSeqState::establish_interactive(psm_.expr_alloc(), &psm_);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
SchematikaParser::begin_translation_unit() {
|
||||
DExprSeqState::start_batch(psm_.expr_alloc(), &psm_);
|
||||
DExprSeqState::establish_batch(psm_.expr_alloc(), &psm_);
|
||||
}
|
||||
|
||||
const ParserResult &
|
||||
|
|
@ -75,8 +72,7 @@ namespace xo {
|
|||
void
|
||||
SchematikaParser::reset_to_idle_toplevel()
|
||||
{
|
||||
psm_.reset_stack();
|
||||
psm_.reset_result();
|
||||
psm_.clear_error_reset();
|
||||
} /*reset_to_idle_toplevel*/
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue