xo-reader: streamline: simplify expect_expr_xs

This commit is contained in:
Roland Conybeare 2024-08-10 15:56:48 -05:00
commit d1d72f9fc9
4 changed files with 69 additions and 112 deletions

View file

@ -38,6 +38,41 @@ namespace xo {
p_stack->push_exprstate(expect_expr_xs::expect_rhs_expression());
}
void
expect_expr_xs::on_symbol_token(const token_type & /*tk*/,
exprstatestack * /*p_stack*/,
rp<Expression> * /*p_emit_expr*/)
{
/* todo: treat symbol as variable name */
/* various possibilities when looking for rhs expression:
*
* x := y // (1)
* x := f(a) // (2)
* x := f(a,b) // (3)
*
* need lookahead token following symbol to distinguish
* between (1) (symbol completes rhs expression)
* and {(2), (3)} (symbol is function call)
*/
/* have to do pop first, before sending symbol to
* the o.g. symbol-requester
*/
#ifdef NOT_YET
p_stack->push_exprstate(exprstate(exprstatetype::expr_progress,
Variable::make(name, type)));
#endif
#ifdef LATER
p_stack->pop_exprstate();
p_stack->top_exprstate().on_symbol(tk.text(),
p_stack, p_emit_expr);
#endif
return;
}
void
expect_expr_xs::on_f64_token(const token_type & tk,
exprstatestack * p_stack,
@ -57,6 +92,24 @@ namespace xo {
(Constant<double>::make(tk.f64_value())));
}
void
expect_expr_xs::on_expr(ref::brw<Expression> expr,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr)
{
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag));
log && log(xtag("exstype", this->exs_type_),
xtag("expr", expr));
std::unique_ptr<exprstate> self = p_stack->pop_exprstate();
p_stack->top_exprstate().on_expr(expr,
p_stack,
p_emit_expr);
} /*on_expr*/
} /*namespace scm*/
} /*namespace xo*/