xo-reader: refactor: parserstatemachine w/ exprstate.on_lambda_token
This commit is contained in:
parent
e5dc8d14d4
commit
8cae38817b
7 changed files with 22 additions and 16 deletions
|
|
@ -20,8 +20,7 @@ namespace xo {
|
||||||
static void start(exprstatestack * p_stack);
|
static void start(exprstatestack * p_stack);
|
||||||
|
|
||||||
virtual void on_lambda_token(const token_type & tk,
|
virtual void on_lambda_token(const token_type & tk,
|
||||||
exprstatestack * p_stack,
|
parserstatemachine * p_psm) override;
|
||||||
rp<Expression> * p_emit_expr) override;
|
|
||||||
virtual void on_leftparen_token(const token_type & tk,
|
virtual void on_leftparen_token(const token_type & tk,
|
||||||
exprstatestack * p_stack,
|
exprstatestack * p_stack,
|
||||||
rp<Expression> * p_emit_expr) override;
|
rp<Expression> * p_emit_expr) override;
|
||||||
|
|
|
||||||
|
|
@ -123,8 +123,7 @@ namespace xo {
|
||||||
parserstatemachine * p_psm);
|
parserstatemachine * p_psm);
|
||||||
/** handle incoming 'lambda' token **/
|
/** handle incoming 'lambda' token **/
|
||||||
virtual void on_lambda_token(const token_type & tk,
|
virtual void on_lambda_token(const token_type & tk,
|
||||||
exprstatestack * p_stack,
|
parserstatemachine * p_psm);
|
||||||
rp<Expression> * p_emit_expr);
|
|
||||||
/** handle incoming symbol token **/
|
/** handle incoming symbol token **/
|
||||||
virtual void on_symbol_token(const token_type & tk,
|
virtual void on_symbol_token(const token_type & tk,
|
||||||
exprstatestack * p_stack,
|
exprstatestack * p_stack,
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,7 @@ namespace xo {
|
||||||
static void start(exprstatestack * p_stack, rp<Expression> * p_emit_expr);
|
static void start(exprstatestack * p_stack, rp<Expression> * p_emit_expr);
|
||||||
|
|
||||||
virtual void on_lambda_token(const token_type & tk,
|
virtual void on_lambda_token(const token_type & tk,
|
||||||
exprstatestack * p_stack,
|
parserstatemachine * p_psm) override;
|
||||||
rp<Expression> * p_emit_expr) override;
|
|
||||||
virtual void on_formal_arglist(const std::vector<rp<Variable>> & argl,
|
virtual void on_formal_arglist(const std::vector<rp<Variable>> & argl,
|
||||||
exprstatestack * p_stack,
|
exprstatestack * p_stack,
|
||||||
rp<Expression> * p_emit_expr) override;
|
rp<Expression> * p_emit_expr) override;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "expect_expr_xs.hpp"
|
#include "expect_expr_xs.hpp"
|
||||||
|
#include "parserstatemachine.hpp"
|
||||||
#include "lambda_xs.hpp"
|
#include "lambda_xs.hpp"
|
||||||
#include "paren_xs.hpp"
|
#include "paren_xs.hpp"
|
||||||
#include "progress_xs.hpp"
|
#include "progress_xs.hpp"
|
||||||
|
|
@ -32,14 +33,16 @@ namespace xo {
|
||||||
|
|
||||||
void
|
void
|
||||||
expect_expr_xs::on_lambda_token(const token_type & /*tk*/,
|
expect_expr_xs::on_lambda_token(const token_type & /*tk*/,
|
||||||
exprstatestack * p_stack,
|
parserstatemachine * p_psm)
|
||||||
rp<Expression> * p_emit_expr)
|
|
||||||
{
|
{
|
||||||
constexpr bool c_debug_flag = true;
|
constexpr bool c_debug_flag = true;
|
||||||
scope log(XO_DEBUG(c_debug_flag));
|
scope log(XO_DEBUG(c_debug_flag));
|
||||||
|
|
||||||
//constexpr const char * self_name = "exprstate::on_leftparen";
|
//constexpr const char * self_name = "exprstate::on_leftparen";
|
||||||
|
|
||||||
|
auto p_stack = p_psm->p_stack_;
|
||||||
|
auto p_emit_expr = p_psm->p_emit_expr_;
|
||||||
|
|
||||||
/* push lparen_0 to remember to look for subsequent rightparen. */
|
/* push lparen_0 to remember to look for subsequent rightparen. */
|
||||||
lambda_xs::start(p_stack, p_emit_expr);
|
lambda_xs::start(p_stack, p_emit_expr);
|
||||||
//p_stack->top_exprstate().on_lambda_token(tk, p_stack, p_emit_expr);
|
//p_stack->top_exprstate().on_lambda_token(tk, p_stack, p_emit_expr);
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,7 @@ namespace xo {
|
||||||
|
|
||||||
void
|
void
|
||||||
exprstate::on_lambda_token(const token_type & tk,
|
exprstate::on_lambda_token(const token_type & tk,
|
||||||
exprstatestack * /*p_stack*/,
|
parserstatemachine * /*p_psm*/)
|
||||||
rp<Expression> * /*p_emit_expr*/)
|
|
||||||
{
|
{
|
||||||
this->illegal_input_error("exprstate::on_lambda_token", tk);
|
this->illegal_input_error("exprstate::on_lambda_token", tk);
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +263,7 @@ namespace xo {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case tokentype::tk_lambda:
|
case tokentype::tk_lambda:
|
||||||
this->on_lambda_token(tk, p_stack, p_emit_expr);
|
this->on_lambda_token(tk, p_psm);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case tokentype::tk_i64:
|
case tokentype::tk_i64:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
/* @file lambda_xs.cpp */
|
/* @file lambda_xs.cpp */
|
||||||
|
|
||||||
#include "lambda_xs.hpp"
|
#include "lambda_xs.hpp"
|
||||||
|
#include "parserstatemachine.hpp"
|
||||||
#include "expect_formal_arglist_xs.hpp"
|
#include "expect_formal_arglist_xs.hpp"
|
||||||
#include "expect_expr_xs.hpp"
|
#include "expect_expr_xs.hpp"
|
||||||
#include "xo/expression/Lambda.hpp"
|
#include "xo/expression/Lambda.hpp"
|
||||||
|
|
@ -18,23 +19,26 @@ namespace xo {
|
||||||
lambda_xs::start(exprstatestack * p_stack,
|
lambda_xs::start(exprstatestack * p_stack,
|
||||||
rp<Expression> * p_emit_expr)
|
rp<Expression> * p_emit_expr)
|
||||||
{
|
{
|
||||||
|
parserstatemachine psm(p_stack, p_emit_expr);
|
||||||
|
|
||||||
p_stack->push_exprstate(lambda_xs::make());
|
p_stack->push_exprstate(lambda_xs::make());
|
||||||
p_stack->top_exprstate()
|
p_stack->top_exprstate()
|
||||||
.on_lambda_token(token_type::lambda(), p_stack, p_emit_expr);
|
.on_lambda_token(token_type::lambda(), &psm);
|
||||||
}
|
}
|
||||||
|
|
||||||
lambda_xs::lambda_xs() : exprstate(exprstatetype::lambdaexpr) {}
|
lambda_xs::lambda_xs() : exprstate(exprstatetype::lambdaexpr) {}
|
||||||
|
|
||||||
void
|
void
|
||||||
lambda_xs::on_lambda_token(const token_type & tk,
|
lambda_xs::on_lambda_token(const token_type & tk,
|
||||||
exprstatestack * p_stack,
|
parserstatemachine * p_psm)
|
||||||
rp<Expression> * p_emit_expr)
|
|
||||||
{
|
{
|
||||||
|
auto p_stack = p_psm->p_stack_;
|
||||||
|
|
||||||
if (lmxs_type_ == lambdastatetype::lm_0) {
|
if (lmxs_type_ == lambdastatetype::lm_0) {
|
||||||
this->lmxs_type_ = lambdastatetype::lm_1;
|
this->lmxs_type_ = lambdastatetype::lm_1;
|
||||||
expect_formal_arglist_xs::start(p_stack);
|
expect_formal_arglist_xs::start(p_stack);
|
||||||
} else {
|
} else {
|
||||||
exprstate::on_lambda_token(tk, p_stack, p_emit_expr);
|
exprstate::on_lambda_token(tk, p_psm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "parser.hpp"
|
#include "parser.hpp"
|
||||||
|
#include "parserstatemachine.hpp"
|
||||||
#include "define_xs.hpp"
|
#include "define_xs.hpp"
|
||||||
#include "exprseq_xs.hpp"
|
#include "exprseq_xs.hpp"
|
||||||
#include "xo/expression/DefineExpr.hpp"
|
#include "xo/expression/DefineExpr.hpp"
|
||||||
|
|
@ -50,7 +51,9 @@ namespace xo {
|
||||||
|
|
||||||
rp<Expression> retval;
|
rp<Expression> retval;
|
||||||
|
|
||||||
xs_stack_.top_exprstate().on_input(tk, &xs_stack_, &retval);
|
parserstatemachine psm(&xs_stack_, &retval);
|
||||||
|
|
||||||
|
xs_stack_.top_exprstate().on_input(tk, &psm);
|
||||||
|
|
||||||
log && log(xtag("retval", retval));
|
log && log(xtag("retval", retval));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue