diff --git a/include/xo/reader/define_xs.hpp b/include/xo/reader/define_xs.hpp index dad682c3..9e616b31 100644 --- a/include/xo/reader/define_xs.hpp +++ b/include/xo/reader/define_xs.hpp @@ -86,18 +86,15 @@ namespace xo { virtual void on_def_token(const token_type & tk, parserstatemachine * p_psm) override; virtual void on_colon_token(const token_type & tk, - exprstatestack * p_stack) override; + parserstatemachine * p_psm) override; virtual void on_semicolon_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) override; + parserstatemachine * p_psm) override; virtual void on_singleassign_token(const token_type & tk, - exprstatestack * p_stack) override; + parserstatemachine * p_psm) override; virtual void on_rightparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) override; + parserstatemachine * p_psm) override; virtual void on_f64_token(const token_type & tk, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) override; + parserstatemachine * p_psm) override; virtual void print(std::ostream & os) const override; diff --git a/include/xo/reader/expect_expr_xs.hpp b/include/xo/reader/expect_expr_xs.hpp index 0259e6a6..3808e7bc 100644 --- a/include/xo/reader/expect_expr_xs.hpp +++ b/include/xo/reader/expect_expr_xs.hpp @@ -21,16 +21,15 @@ namespace xo { virtual void on_lambda_token(const token_type & tk, parserstatemachine * p_psm) override; + virtual void on_leftparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) override; + parserstatemachine * p_psm) override; virtual void on_symbol_token(const token_type & tk, parserstatemachine * p_psm) override; virtual void on_f64_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) override; + parserstatemachine * p_psm) override; /** update exprstate in response to a successfully-parsed subexpression **/ virtual void on_expr(ref::brw expr, diff --git a/include/xo/reader/expect_formal_arglist_xs.hpp b/include/xo/reader/expect_formal_arglist_xs.hpp index 442dde62..7eef773d 100644 --- a/include/xo/reader/expect_formal_arglist_xs.hpp +++ b/include/xo/reader/expect_formal_arglist_xs.hpp @@ -56,17 +56,14 @@ namespace xo { static void start(exprstatestack * p_stack); virtual void on_leftparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) override; + parserstatemachine * p_psm) override; virtual void on_formal(const rp & formal, exprstatestack * p_stack, rp * p_emit_expr) override; virtual void on_comma_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) override; + parserstatemachine * p_psm) override; virtual void on_rightparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) override; + parserstatemachine * p_psm) override; virtual void print(std::ostream & os) const override; private: diff --git a/include/xo/reader/expect_formal_xs.hpp b/include/xo/reader/expect_formal_xs.hpp index 892e447f..b757f6f5 100644 --- a/include/xo/reader/expect_formal_xs.hpp +++ b/include/xo/reader/expect_formal_xs.hpp @@ -54,8 +54,7 @@ namespace xo { rp * p_emit_expr) override; virtual void on_colon_token(const token_type & tk, - exprstatestack * p_stack - /*rp * p_emit_expr*/) override; + parserstatemachine * p_psm) override; // virtual void on_comma_token(...) override; diff --git a/include/xo/reader/exprstate.hpp b/include/xo/reader/exprstate.hpp index ab091fdc..bf93a3f5 100644 --- a/include/xo/reader/exprstate.hpp +++ b/include/xo/reader/exprstate.hpp @@ -129,34 +129,30 @@ namespace xo { parserstatemachine * p_psm); /** handle incoming ',' token **/ virtual void on_comma_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr); + parserstatemachine * p_psm); /** handle incoming ':' token **/ virtual void on_colon_token(const token_type & tk, - exprstatestack * p_stack); + parserstatemachine * p_psm); /** handle incoming ';' token **/ virtual void on_semicolon_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr); + parserstatemachine * p_psm); /** handle incoming '=' token **/ virtual void on_singleassign_token(const token_type & tk, - exprstatestack * p_stack); + parserstatemachine * p_psm); /** handle incoming '(' token **/ virtual void on_leftparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr); + parserstatemachine * p_psm); /** handle incoming ')' token **/ virtual void on_rightparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr); + parserstatemachine * p_psm); + /** handle incoming operator token **/ virtual void on_operator_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr); + parserstatemachine * p_psm); + /** handle incoming floating-point-literal token **/ virtual void on_f64_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr); + parserstatemachine * p_psm); protected: /** throw exception when next token is inconsistent with diff --git a/include/xo/reader/lambda_xs.hpp b/include/xo/reader/lambda_xs.hpp index 7597e937..59f9f78a 100644 --- a/include/xo/reader/lambda_xs.hpp +++ b/include/xo/reader/lambda_xs.hpp @@ -51,8 +51,7 @@ namespace xo { exprstatestack * p_stack, rp * p_emit_expr) override; virtual void on_semicolon_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) override; + parserstatemachine * p_psm) override; private: static std::unique_ptr make(); diff --git a/include/xo/reader/paren_xs.hpp b/include/xo/reader/paren_xs.hpp index 9e8c8dff..b4225f4e 100644 --- a/include/xo/reader/paren_xs.hpp +++ b/include/xo/reader/paren_xs.hpp @@ -49,21 +49,17 @@ namespace xo { virtual void on_symbol_token(const token_type & tk, parserstatemachine * p_psm) override; virtual void on_colon_token(const token_type & tk, - exprstatestack * p_stack) override; + parserstatemachine * p_psm) override; virtual void on_semicolon_token(const token_type & tk, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) override; + parserstatemachine * p_psm) override; virtual void on_singleassign_token(const token_type & tk, - exprstatestack * p_stack) override; + parserstatemachine * p_psm) override; virtual void on_leftparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) override; + parserstatemachine * p_psm) override; virtual void on_rightparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) override; + parserstatemachine * p_psm) override; virtual void on_f64_token(const token_type & tk, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) override; + parserstatemachine * p_psm) override; virtual void print(std::ostream & os) const override; diff --git a/include/xo/reader/progress_xs.hpp b/include/xo/reader/progress_xs.hpp index 06107bad..965da117 100644 --- a/include/xo/reader/progress_xs.hpp +++ b/include/xo/reader/progress_xs.hpp @@ -67,27 +67,22 @@ namespace xo { virtual void on_def_token(const token_type & tk, parserstatemachine * p_psm) override; virtual void on_colon_token(const token_type & tk, - exprstatestack * p_stack) override; + parserstatemachine * p_psm) override; virtual void on_semicolon_token(const token_type & tk, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) override; + parserstatemachine * p_psm) override; virtual void on_singleassign_token(const token_type & tk, - exprstatestack * p_stack) override; + parserstatemachine * p_psm) override; virtual void on_leftparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) override; + parserstatemachine * p_psm) override; virtual void on_rightparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) override; + parserstatemachine * p_psm) override; /* entry point for an infix operator token */ virtual void on_operator_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) override; + parserstatemachine * p_psm) override; virtual void on_f64_token(const token_type & tk, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) override; + parserstatemachine * p_psm) override; virtual void print(std::ostream & os) const override; diff --git a/src/reader/define_xs.cpp b/src/reader/define_xs.cpp index a141bfb8..0f5561dc 100644 --- a/src/reader/define_xs.cpp +++ b/src/reader/define_xs.cpp @@ -109,30 +109,34 @@ namespace xo { void define_xs::on_colon_token(const token_type & tk, - exprstatestack * p_stack) + parserstatemachine * p_psm) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); //constexpr const char * self_name = "define_xs::on_colon_token"; + auto p_stack = p_psm->p_stack_; + if (this->defxs_type_ == defexprstatetype::def_2) { this->defxs_type_ = defexprstatetype::def_3; expect_type_xs::start(p_stack); } else { - exprstate::on_colon_token(tk, p_stack); + exprstate::on_colon_token(tk, p_psm); } } void define_xs::on_semicolon_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) + parserstatemachine * p_psm) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); + auto p_stack = p_psm->p_stack_; + auto p_emit_expr = p_psm->p_emit_expr_; + //constexpr const char * self_name = "exprstate::on_semicolon"; if (this->defxs_type_ == defexprstatetype::def_6) { @@ -144,13 +148,13 @@ namespace xo { p_stack, p_emit_expr); } else { - exprstate::on_semicolon_token(tk, p_stack, p_emit_expr); + exprstate::on_semicolon_token(tk, p_psm); } } void define_xs::on_singleassign_token(const token_type & tk, - exprstatestack * p_stack) + parserstatemachine * p_psm) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -177,7 +181,7 @@ namespace xo { { this->defxs_type_ = defexprstatetype::def_5; - expect_expr_xs::start(p_stack); + expect_expr_xs::start(p_psm->p_stack_); } else { this->illegal_input_error(self_name, tk); } @@ -185,8 +189,7 @@ namespace xo { void define_xs::on_rightparen_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -198,8 +201,7 @@ namespace xo { void define_xs::on_f64_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); diff --git a/src/reader/expect_expr_xs.cpp b/src/reader/expect_expr_xs.cpp index 9e28eb6e..123f52da 100644 --- a/src/reader/expect_expr_xs.cpp +++ b/src/reader/expect_expr_xs.cpp @@ -51,14 +51,15 @@ namespace xo { void expect_expr_xs::on_leftparen_token(const token_type & /*tk*/, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) + parserstatemachine * p_psm) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); //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); } @@ -99,8 +100,7 @@ namespace xo { void expect_expr_xs::on_f64_token(const token_type & tk, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) + parserstatemachine * p_psm) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -113,7 +113,7 @@ namespace xo { */ progress_xs::start (Constant::make(tk.f64_value()), - p_stack); + p_psm->p_stack_); } void diff --git a/src/reader/expect_formal_arglist_xs.cpp b/src/reader/expect_formal_arglist_xs.cpp index 5b58e3cf..6bb9b099 100644 --- a/src/reader/expect_formal_arglist_xs.cpp +++ b/src/reader/expect_formal_arglist_xs.cpp @@ -6,6 +6,7 @@ #include "expect_formal_arglist_xs.hpp" #include "expect_formal_xs.hpp" #include "expect_symbol_xs.hpp" +#include "parserstatemachine.hpp" #include "xo/expression/Variable.hpp" #include "xo/indentlog/print/vector.hpp" @@ -48,15 +49,16 @@ namespace xo { void expect_formal_arglist_xs::on_leftparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) + parserstatemachine * p_psm) { + auto p_stack = p_psm->p_stack_; + if (farglxs_type_ == formalarglstatetype::argl_0) { this->farglxs_type_ = formalarglstatetype::argl_1a; /* TODO: refactor to have setup method on each exprstate */ expect_formal_xs::start(p_stack); } else { - exprstate::on_leftparen_token(tk, p_stack, p_emit_expr); + exprstate::on_leftparen_token(tk, p_psm); } } @@ -75,29 +77,32 @@ namespace xo { void expect_formal_arglist_xs::on_comma_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) + parserstatemachine * p_psm) { + auto p_stack = p_psm->p_stack_; + if (farglxs_type_ == formalarglstatetype::argl_1b) { this->farglxs_type_ = formalarglstatetype::argl_1a; expect_formal_xs::start(p_stack); } else { - exprstate::on_comma_token(tk, p_stack, p_emit_expr); + exprstate::on_comma_token(tk, p_psm); } } void expect_formal_arglist_xs::on_rightparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) + parserstatemachine * p_psm) { + auto p_stack = p_psm->p_stack_; + auto p_emit_expr = p_psm->p_emit_expr_; + if (farglxs_type_ == formalarglstatetype::argl_1b) { std::unique_ptr self = p_stack->pop_exprstate(); p_stack->top_exprstate().on_formal_arglist(this->argl_, p_stack, p_emit_expr); } else { - exprstate::on_rightparen_token(tk, p_stack, p_emit_expr); + exprstate::on_rightparen_token(tk, p_psm); } } diff --git a/src/reader/expect_formal_xs.cpp b/src/reader/expect_formal_xs.cpp index 3be6bcf8..3455de23 100644 --- a/src/reader/expect_formal_xs.cpp +++ b/src/reader/expect_formal_xs.cpp @@ -6,6 +6,7 @@ #include "expect_formal_xs.hpp" #include "expect_symbol_xs.hpp" #include "expect_type_xs.hpp" +#include "parserstatemachine.hpp" #include "xo/expression/Variable.hpp" namespace xo { @@ -63,16 +64,17 @@ namespace xo { void expect_formal_xs::on_colon_token(const token_type & tk, - exprstatestack * p_stack - /* rp * p_emit_expr */) + parserstatemachine * p_psm) { + auto p_stack = p_psm->p_stack_; + if (this->formalxs_type_ == formalstatetype::formal_1) { this->formalxs_type_ = formalstatetype::formal_2; expect_type_xs::start(p_stack); /* control reenters via expect_formal_xs::on_typedescr() */ } else { exprstate::on_colon_token(tk, - p_stack); + p_psm); } } diff --git a/src/reader/exprstate.cpp b/src/reader/exprstate.cpp index 97be6fec..ba58eb79 100644 --- a/src/reader/exprstate.cpp +++ b/src/reader/exprstate.cpp @@ -146,7 +146,7 @@ namespace xo { void exprstate::on_colon_token(const token_type & tk, - exprstatestack * /*p_stack*/) + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -158,8 +158,7 @@ namespace xo { void exprstate::on_comma_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -171,8 +170,7 @@ namespace xo { void exprstate::on_semicolon_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -184,7 +182,7 @@ namespace xo { void exprstate::on_singleassign_token(const token_type & tk, - exprstatestack * /*p_stack*/) { + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -195,8 +193,7 @@ namespace xo { void exprstate::on_leftparen_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -208,8 +205,7 @@ namespace xo { void exprstate::on_rightparen_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -221,8 +217,7 @@ namespace xo { void exprstate::on_operator_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -234,8 +229,7 @@ namespace xo { void exprstate::on_f64_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -254,9 +248,6 @@ namespace xo { log && log(xtag("tk", tk)); log && log(xtag("state", *this)); - auto p_stack = p_psm->p_stack_; - auto p_emit_expr = p_psm->p_emit_expr_; - switch (tk.tk_type()) { case tokentype::tk_def: @@ -272,7 +263,7 @@ namespace xo { return; case tokentype::tk_f64: - this->on_f64_token(tk, p_stack, p_emit_expr); + this->on_f64_token(tk, p_psm); return; case tokentype::tk_string: @@ -284,11 +275,11 @@ namespace xo { return; case tokentype::tk_leftparen: - this->on_leftparen_token(tk, p_stack, p_emit_expr); + this->on_leftparen_token(tk, p_psm); return; case tokentype::tk_rightparen: - this->on_rightparen_token(tk, p_stack, p_emit_expr); + this->on_rightparen_token(tk, p_psm); return; case tokentype::tk_leftbracket: @@ -303,11 +294,11 @@ namespace xo { return; case tokentype::tk_comma: - this->on_comma_token(tk, p_stack, p_emit_expr); + this->on_comma_token(tk, p_psm); return; case tokentype::tk_colon: - this->on_colon_token(tk, p_stack); + this->on_colon_token(tk, p_psm); return; case tokentype::tk_doublecolon: @@ -315,11 +306,11 @@ namespace xo { return; case tokentype::tk_semicolon: - this->on_semicolon_token(tk, p_stack, p_emit_expr); + this->on_semicolon_token(tk, p_psm); return; case tokentype::tk_singleassign: - this->on_singleassign_token(tk, p_stack); + this->on_singleassign_token(tk, p_psm); return; case tokentype::tk_assign: @@ -329,7 +320,7 @@ namespace xo { case tokentype::tk_minus: case tokentype::tk_star: case tokentype::tk_slash: - this->on_operator_token(tk, p_stack, p_emit_expr); + this->on_operator_token(tk, p_psm); return; case tokentype::tk_type: diff --git a/src/reader/lambda_xs.cpp b/src/reader/lambda_xs.cpp index f861d1aa..8824ab26 100644 --- a/src/reader/lambda_xs.cpp +++ b/src/reader/lambda_xs.cpp @@ -71,9 +71,11 @@ namespace xo { void lambda_xs::on_semicolon_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) + parserstatemachine * p_psm) { + auto p_stack = p_psm->p_stack_; + auto p_emit_expr = p_psm->p_emit_expr_; + if (lmxs_type_ == lambdastatetype::lm_3) { /* done! */ @@ -84,12 +86,12 @@ namespace xo { rp lm = Lambda::make(name, argl_, body_); p_stack->top_exprstate().on_expr(lm, p_stack, p_emit_expr); - p_stack->top_exprstate().on_semicolon_token(tk, p_stack, p_emit_expr); + p_stack->top_exprstate().on_semicolon_token(tk, p_psm); return; } - exprstate::on_semicolon_token(tk, p_stack, p_emit_expr); + exprstate::on_semicolon_token(tk, p_psm); } } /*namespace scm*/ } /*namespace xo*/ diff --git a/src/reader/paren_xs.cpp b/src/reader/paren_xs.cpp index 9ec0a0b8..8f6dff50 100644 --- a/src/reader/paren_xs.cpp +++ b/src/reader/paren_xs.cpp @@ -101,7 +101,7 @@ namespace xo { void paren_xs::on_colon_token(const token_type & tk, - exprstatestack * /*p_stack*/) + parserstatemachine * /*p_psm*/) { constexpr const char * c_self_name = "paren_xs::on_colon"; @@ -110,8 +110,7 @@ namespace xo { void paren_xs::on_semicolon_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr const char * c_self_name = "paren_xs::on_semicolon"; @@ -120,7 +119,7 @@ namespace xo { void paren_xs::on_singleassign_token(const token_type & tk, - exprstatestack * /*p_stack*/) + parserstatemachine * /*p_psm*/) { constexpr const char * c_self_name = "paren_xs::on_singleassign"; @@ -129,8 +128,7 @@ namespace xo { void paren_xs::on_leftparen_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr const char * c_self_name = "paren_xs::on_leftparen"; @@ -139,8 +137,7 @@ namespace xo { void paren_xs::on_rightparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) + parserstatemachine * p_psm) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -155,6 +152,9 @@ namespace xo { if (this->parenxs_type_ == parenexprstatetype::lparen_1) { rp expr = this->gen_expr_; + auto p_stack = p_psm->p_stack_; + auto p_emit_expr = p_psm->p_emit_expr_; + std::unique_ptr self = p_stack->pop_exprstate(); p_stack->top_exprstate().on_expr(expr, p_stack, p_emit_expr); @@ -163,20 +163,14 @@ namespace xo { void paren_xs::on_f64_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); constexpr const char * c_self_name = "paren_xs::on_f64"; - if (!this->admits_f64()) - { - this->illegal_input_error(c_self_name, tk); - } - - assert(false); + this->illegal_input_error(c_self_name, tk); } void diff --git a/src/reader/progress_xs.cpp b/src/reader/progress_xs.cpp index 431b0cb8..12f62740 100644 --- a/src/reader/progress_xs.cpp +++ b/src/reader/progress_xs.cpp @@ -2,6 +2,7 @@ #include "progress_xs.hpp" #include "expect_expr_xs.hpp" +#include "parserstatemachine.hpp" #include "xo/expression/Apply.hpp" namespace xo { @@ -183,7 +184,7 @@ namespace xo { void progress_xs::on_colon_token(const token_type & tk, - exprstatestack * /*p_stack*/) + parserstatemachine * /*p_psm*/) { constexpr const char * self_name = "progress_xs::on_colon"; @@ -192,14 +193,16 @@ namespace xo { void progress_xs::on_semicolon_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) + parserstatemachine * p_psm) { /* note: implementation parllels .on_rightparen_token() */ constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); + auto p_stack = p_psm->p_stack_; + auto p_emit_expr = p_psm->p_emit_expr_; + rp expr = this->assemble_expr(); std::unique_ptr self = p_stack->pop_exprstate(); @@ -222,12 +225,12 @@ namespace xo { * f. now deliver semicolon; [lparen_1] rejects */ - p_stack->top_exprstate().on_semicolon_token(tk, p_stack, p_emit_expr); + p_stack->top_exprstate().on_semicolon_token(tk, p_psm); } void progress_xs::on_singleassign_token(const token_type & tk, - exprstatestack * /*p_stack*/) + parserstatemachine * /*p_psm*/) { constexpr const char * self_name = "progress_xs::on_singleassign"; @@ -236,8 +239,7 @@ namespace xo { void progress_xs::on_leftparen_token(const token_type & tk, - exprstatestack * /*p_stack*/, - rp * /*p_emit_expr*/) + parserstatemachine * /*p_psm*/) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -249,8 +251,7 @@ namespace xo { void progress_xs::on_rightparen_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) + parserstatemachine * p_psm) { /* note: implementation parallels .on_semicolon_token() */ @@ -260,6 +261,9 @@ namespace xo { constexpr const char * self_name = "progress_xs::on_rightparen"; + auto p_stack = p_psm->p_stack_; + auto p_emit_expr = p_psm->p_emit_expr_; + /* stack may be something like: * * lparen_0 @@ -286,8 +290,7 @@ namespace xo { p_stack->top_exprstate().on_expr(expr, p_stack, p_emit_expr); /* now deliver rightparen */ - p_stack->top_exprstate().on_rightparen_token(tk, p_stack, p_emit_expr); - + p_stack->top_exprstate().on_rightparen_token(tk, p_psm); } namespace { @@ -312,11 +315,12 @@ namespace xo { void progress_xs::on_operator_token(const token_type & tk, - exprstatestack * p_stack, - rp * /*p_emit_expr*/) + parserstatemachine * p_psm) { constexpr const char * c_self_name = "progress_xs::on_operator_token"; + auto p_stack = p_psm->p_stack_; + if (op_type_ == optype::invalid) { this->op_type_ = tk2op(tk.tk_type()); @@ -383,8 +387,7 @@ namespace xo { void progress_xs::on_f64_token(const token_type & tk, - exprstatestack * p_stack, - rp * p_emit_expr) + parserstatemachine * p_psm) { constexpr bool c_debug_flag = true; scope log(XO_DEBUG(c_debug_flag)); @@ -394,8 +397,7 @@ namespace xo { if (this->op_type_ == optype::invalid) { this->illegal_input_error(self_name, tk); } else { - assert(false); - exprstate::on_f64_token(tk, p_stack, p_emit_expr); + exprstate::on_f64_token(tk, p_psm); } }