xo-reader: parsestatemachine.top_exprstate() + use to simplify
This commit is contained in:
parent
4232da4ef2
commit
b988bc6790
11 changed files with 22 additions and 49 deletions
|
|
@ -26,6 +26,7 @@ namespace xo {
|
|||
: p_stack_{p_stack}, p_emit_expr_{p_emit_expr} {}
|
||||
|
||||
std::unique_ptr<exprstate> pop_exprstate();
|
||||
exprstate & top_exprstate();
|
||||
|
||||
public:
|
||||
exprstatestack * p_stack_;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace xo {
|
|||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
p_stack->push_exprstate(define_xs::make());
|
||||
p_stack->top_exprstate().on_def_token(token_type::def(), p_psm);
|
||||
p_psm->top_exprstate().on_def_token(token_type::def(), p_psm);
|
||||
}
|
||||
|
||||
define_xs::define_xs(rp<DefineExprAccess> def_expr)
|
||||
|
|
@ -132,8 +132,6 @@ namespace xo {
|
|||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
//constexpr const char * self_name = "exprstate::on_semicolon";
|
||||
|
||||
if (this->defxs_type_ == defexprstatetype::def_6) {
|
||||
|
|
@ -141,7 +139,7 @@ namespace xo {
|
|||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
p_stack->top_exprstate().on_expr(expr, p_psm);
|
||||
p_psm->top_exprstate().on_expr(expr, p_psm);
|
||||
} else {
|
||||
exprstate::on_semicolon_token(tk, p_psm);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace xo {
|
|||
|
||||
/* push lparen_0 to remember to look for subsequent rightparen. */
|
||||
lambda_xs::start(p_stack, p_emit_expr);
|
||||
//p_stack->top_exprstate().on_lambda_token(tk, p_stack, p_emit_expr);
|
||||
//p_psm->top_exprstate().on_lambda_token(tk, p_stack, p_emit_expr);
|
||||
//p_stack->push_exprstate(expect_expr_xs::expect_rhs_expression());
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +92,7 @@ namespace xo {
|
|||
|
||||
#ifdef LATER
|
||||
p_psm->pop_exprstate();
|
||||
p_stack->top_exprstate().on_symbol(tk.text(),
|
||||
p_psm->top_exprstate().on_symbol(tk.text(),
|
||||
p_stack, p_emit_expr);
|
||||
#endif
|
||||
return;
|
||||
|
|
@ -127,11 +127,9 @@ namespace xo {
|
|||
log && log(xtag("exstype", this->exs_type_),
|
||||
xtag("expr", expr));
|
||||
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
p_stack->top_exprstate().on_expr(expr, p_psm);
|
||||
p_psm->top_exprstate().on_expr(expr, p_psm);
|
||||
} /*on_expr*/
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -93,12 +93,10 @@ namespace xo {
|
|||
expect_formal_arglist_xs::on_rightparen_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
if (farglxs_type_ == formalarglstatetype::argl_1b) {
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
p_stack->top_exprstate().on_formal_arglist(this->argl_, p_psm);
|
||||
p_psm->top_exprstate().on_formal_arglist(this->argl_, p_psm);
|
||||
} else {
|
||||
exprstate::on_rightparen_token(tk, p_psm);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,8 +80,6 @@ namespace xo {
|
|||
expect_formal_xs::on_typedescr(TypeDescr td,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
if (this->formalxs_type_ == formalstatetype::formal_2) {
|
||||
this->result_.assign_td(td);
|
||||
|
||||
|
|
@ -90,7 +88,7 @@ namespace xo {
|
|||
rp<Variable> var = Variable::make(result_.name(),
|
||||
result_.td());
|
||||
|
||||
p_stack->top_exprstate().on_formal(var, p_psm);
|
||||
p_psm->top_exprstate().on_formal(var, p_psm);
|
||||
} else {
|
||||
exprstate::on_typedescr(td, p_psm);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,15 +28,13 @@ namespace xo {
|
|||
expect_symbol_xs::on_symbol_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
/* have to do pop first, before sending symbol to
|
||||
* the o.g. symbol-requester
|
||||
*/
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
|
||||
p_stack->top_exprstate().on_symbol(tk.text(), p_psm);
|
||||
p_psm->top_exprstate().on_symbol(tk.text(), p_psm);
|
||||
return;
|
||||
}
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@ namespace xo {
|
|||
{
|
||||
const char * c_self_name = "expect_type_xs::on_symbol_token";
|
||||
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
TypeDescr td = nullptr;
|
||||
|
||||
/* TODO: replace with typetable lookup */
|
||||
|
|
@ -59,7 +57,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
p_stack->top_exprstate().on_typedescr(td, p_psm);
|
||||
p_psm->top_exprstate().on_typedescr(td, p_psm);
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -73,9 +73,7 @@ namespace xo {
|
|||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
log && log(xtag("exstype", p_stack->top_exprstate().exs_type()));
|
||||
log && log(xtag("exstype", p_psm->top_exprstate().exs_type()));
|
||||
|
||||
constexpr const char * c_self_name = "exprstate::on_symbol_token";
|
||||
|
||||
|
|
@ -91,10 +89,8 @@ namespace xo {
|
|||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
log && log(xtag("exstype",
|
||||
p_stack->top_exprstate().exs_type()));
|
||||
p_psm->top_exprstate().exs_type()));
|
||||
|
||||
constexpr const char * c_self_name = "exprstate::on_typedescr";
|
||||
|
||||
|
|
@ -113,10 +109,8 @@ namespace xo {
|
|||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
log && log(xtag("exstype",
|
||||
p_stack->top_exprstate().exs_type()));
|
||||
p_psm->top_exprstate().exs_type()));
|
||||
|
||||
constexpr const char * c_self_name = "exprstate::on_formal";
|
||||
|
||||
|
|
@ -135,10 +129,8 @@ namespace xo {
|
|||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
log && log(xtag("exstype",
|
||||
p_stack->top_exprstate().exs_type()));
|
||||
p_psm->top_exprstate().exs_type()));
|
||||
|
||||
constexpr const char * c_self_name = "exprstate::on_formal_arglist";
|
||||
|
||||
|
|
|
|||
|
|
@ -74,8 +74,6 @@ namespace xo {
|
|||
lambda_xs::on_semicolon_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
if (lmxs_type_ == lambdastatetype::lm_3) {
|
||||
/* done! */
|
||||
|
||||
|
|
@ -85,8 +83,8 @@ namespace xo {
|
|||
|
||||
rp<Lambda> lm = Lambda::make(name, argl_, body_);
|
||||
|
||||
p_stack->top_exprstate().on_expr(lm, p_psm);
|
||||
p_stack->top_exprstate().on_semicolon_token(tk, p_psm);
|
||||
p_psm->top_exprstate().on_expr(lm, p_psm);
|
||||
p_psm->top_exprstate().on_semicolon_token(tk, p_psm);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,9 +80,7 @@ namespace xo {
|
|||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
log && log(xtag("exstype", p_stack->top_exprstate().exs_type()));
|
||||
log && log(xtag("exstype", p_psm->top_exprstate().exs_type()));
|
||||
|
||||
//constexpr const char * self_name = "paren_xs::on_symbol";
|
||||
|
||||
|
|
@ -152,11 +150,9 @@ namespace xo {
|
|||
if (this->parenxs_type_ == parenexprstatetype::lparen_1) {
|
||||
rp<Expression> expr = this->gen_expr_;
|
||||
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
p_stack->top_exprstate().on_expr(expr, p_psm);
|
||||
p_psm->top_exprstate().on_expr(expr, p_psm);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -199,13 +199,11 @@ namespace xo {
|
|||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
auto p_stack = p_psm->p_stack_;
|
||||
|
||||
rp<Expression> expr = this->assemble_expr();
|
||||
|
||||
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
|
||||
|
||||
p_stack->top_exprstate().on_expr(expr, p_psm);
|
||||
p_psm->top_exprstate().on_expr(expr, p_psm);
|
||||
|
||||
/* control here on input like:
|
||||
* (1.234;
|
||||
|
|
@ -222,7 +220,7 @@ namespace xo {
|
|||
* f. now deliver semicolon; [lparen_1] rejects
|
||||
*/
|
||||
|
||||
p_stack->top_exprstate().on_semicolon_token(tk, p_psm);
|
||||
p_psm->top_exprstate().on_semicolon_token(tk, p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -283,10 +281,10 @@ namespace xo {
|
|||
|
||||
log && log(xtag("stack", p_stack));
|
||||
|
||||
p_stack->top_exprstate().on_expr(expr, p_psm);
|
||||
p_psm->top_exprstate().on_expr(expr, p_psm);
|
||||
|
||||
/* now deliver rightparen */
|
||||
p_stack->top_exprstate().on_rightparen_token(tk, p_psm);
|
||||
p_psm->top_exprstate().on_rightparen_token(tk, p_psm);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue