xo-reader: simplify expect_expr_xs,expect_lparen_xs using qsm
This commit is contained in:
parent
6dcc0d420e
commit
0b0c424b84
7 changed files with 14 additions and 18 deletions
|
|
@ -17,7 +17,7 @@ namespace xo {
|
|||
public:
|
||||
expect_expr_xs();
|
||||
|
||||
static void start(exprstatestack * p_stack);
|
||||
static void start(parserstatemachine * p_psm);
|
||||
|
||||
virtual void on_lambda_token(const token_type & tk,
|
||||
parserstatemachine * p_psm) override;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace xo {
|
|||
|
||||
static const paren_xs * from(const exprstate * x) { return dynamic_cast<const paren_xs *>(x); }
|
||||
|
||||
static void start(exprstatestack * p_stack);
|
||||
static void start(parserstatemachine * p_psm);
|
||||
|
||||
bool admits_f64() const;
|
||||
bool admits_rightparen() const;
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ namespace xo {
|
|||
{
|
||||
this->defxs_type_ = defexprstatetype::def_5;
|
||||
|
||||
expect_expr_xs::start(p_psm->p_stack_);
|
||||
expect_expr_xs::start(p_psm);
|
||||
} else {
|
||||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
expect_expr_xs::start(exprstatestack * p_stack) {
|
||||
p_stack->push_exprstate(expect_expr_xs::make());
|
||||
expect_expr_xs::start(parserstatemachine * p_psm) {
|
||||
p_psm->push_exprstate(expect_expr_xs::make());
|
||||
}
|
||||
|
||||
expect_expr_xs::expect_expr_xs()
|
||||
|
|
@ -54,10 +54,8 @@ namespace xo {
|
|||
|
||||
//constexpr const char * self_name = "exprstate::on_leftparen";
|
||||
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
/* push lparen_0 to remember to look for subsequent rightparen. */
|
||||
paren_xs::start(p_stack);
|
||||
paren_xs::start(p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -42,12 +42,10 @@ namespace xo {
|
|||
lambda_xs::on_formal_arglist(const std::vector<rp<Variable>> & argl,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
if (lmxs_type_ == lambdastatetype::lm_1) {
|
||||
this->lmxs_type_ = lambdastatetype::lm_2;
|
||||
this->argl_ = argl;
|
||||
expect_expr_xs::start(p_stack);
|
||||
expect_expr_xs::start(p_psm);
|
||||
} else {
|
||||
exprstate::on_formal_arglist(argl, p_psm);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
paren_xs::start(exprstatestack * p_stack)
|
||||
paren_xs::start(parserstatemachine * p_psm)
|
||||
{
|
||||
p_stack->push_exprstate(paren_xs::make());
|
||||
expect_expr_xs::start(p_stack);
|
||||
p_psm->push_exprstate(paren_xs::make());
|
||||
expect_expr_xs::start(p_psm);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -319,7 +319,7 @@ namespace xo {
|
|||
this->op_type_ = tk2op(tk.tk_type());
|
||||
|
||||
/* infix operator must be followed by non-empty expression */
|
||||
expect_expr_xs::start(p_stack);
|
||||
expect_expr_xs::start(p_psm);
|
||||
} else if (rhs_) {
|
||||
/* already have complete expression stashed.
|
||||
* behavior depends on operator precedence for tk with stored operator
|
||||
|
|
@ -348,7 +348,7 @@ namespace xo {
|
|||
progress_xs::start(expr, op2, p_stack);
|
||||
|
||||
/* infix operator must be followed by non-empty expression */
|
||||
expect_expr_xs::start(p_stack);
|
||||
expect_expr_xs::start(p_psm);
|
||||
} else {
|
||||
/* e.g.
|
||||
* 6.2 + 4.9 * ...
|
||||
|
|
@ -367,9 +367,9 @@ namespace xo {
|
|||
|
||||
/* 1. replace with nested incomplete infix exprs */
|
||||
progress_xs::start(lhs_, op_type_, p_stack);
|
||||
expect_expr_xs::start(p_stack);
|
||||
expect_expr_xs::start(p_psm);
|
||||
progress_xs::start(rhs_, op2, p_stack);
|
||||
expect_expr_xs::start(p_stack);
|
||||
expect_expr_xs::start(p_psm);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue