xo-reader: refactor: parserstatemachine w/ exprstate.on_lambda_token

This commit is contained in:
Roland Conybeare 2024-08-19 00:54:45 -04:00
commit 8cae38817b
7 changed files with 22 additions and 16 deletions

View file

@ -20,8 +20,7 @@ namespace xo {
static void start(exprstatestack * p_stack);
virtual void on_lambda_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr) override;
parserstatemachine * p_psm) override;
virtual void on_leftparen_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr) override;

View file

@ -123,8 +123,7 @@ namespace xo {
parserstatemachine * p_psm);
/** handle incoming 'lambda' token **/
virtual void on_lambda_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr);
parserstatemachine * p_psm);
/** handle incoming symbol token **/
virtual void on_symbol_token(const token_type & tk,
exprstatestack * p_stack,

View file

@ -43,8 +43,7 @@ namespace xo {
static void start(exprstatestack * p_stack, rp<Expression> * p_emit_expr);
virtual void on_lambda_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr) override;
parserstatemachine * p_psm) override;
virtual void on_formal_arglist(const std::vector<rp<Variable>> & argl,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr) override;

View file

@ -4,6 +4,7 @@
*/
#include "expect_expr_xs.hpp"
#include "parserstatemachine.hpp"
#include "lambda_xs.hpp"
#include "paren_xs.hpp"
#include "progress_xs.hpp"
@ -32,14 +33,16 @@ namespace xo {
void
expect_expr_xs::on_lambda_token(const token_type & /*tk*/,
exprstatestack * p_stack,
rp<Expression> * 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_;
auto p_emit_expr = p_psm->p_emit_expr_;
/* 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);

View file

@ -60,8 +60,7 @@ namespace xo {
void
exprstate::on_lambda_token(const token_type & tk,
exprstatestack * /*p_stack*/,
rp<Expression> * /*p_emit_expr*/)
parserstatemachine * /*p_psm*/)
{
this->illegal_input_error("exprstate::on_lambda_token", tk);
}
@ -264,7 +263,7 @@ namespace xo {
return;
case tokentype::tk_lambda:
this->on_lambda_token(tk, p_stack, p_emit_expr);
this->on_lambda_token(tk, p_psm);
return;
case tokentype::tk_i64:

View file

@ -1,6 +1,7 @@
/* @file lambda_xs.cpp */
#include "lambda_xs.hpp"
#include "parserstatemachine.hpp"
#include "expect_formal_arglist_xs.hpp"
#include "expect_expr_xs.hpp"
#include "xo/expression/Lambda.hpp"
@ -18,23 +19,26 @@ namespace xo {
lambda_xs::start(exprstatestack * p_stack,
rp<Expression> * p_emit_expr)
{
parserstatemachine psm(p_stack, p_emit_expr);
p_stack->push_exprstate(lambda_xs::make());
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) {}
void
lambda_xs::on_lambda_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr)
parserstatemachine * p_psm)
{
auto p_stack = p_psm->p_stack_;
if (lmxs_type_ == lambdastatetype::lm_0) {
this->lmxs_type_ = lambdastatetype::lm_1;
expect_formal_arglist_xs::start(p_stack);
} else {
exprstate::on_lambda_token(tk, p_stack, p_emit_expr);
exprstate::on_lambda_token(tk, p_psm);
}
}

View file

@ -4,6 +4,7 @@
*/
#include "parser.hpp"
#include "parserstatemachine.hpp"
#include "define_xs.hpp"
#include "exprseq_xs.hpp"
#include "xo/expression/DefineExpr.hpp"
@ -50,7 +51,9 @@ namespace xo {
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));