xo-reader: refactor: simplify expect_formal_xs api

This commit is contained in:
Roland Conybeare 2024-08-19 00:13:59 -04:00
commit a5e2f622a4
3 changed files with 11 additions and 3 deletions

View file

@ -47,7 +47,7 @@ namespace xo {
public:
expect_formal_xs();
static std::unique_ptr<expect_formal_xs> make();
static void start(exprstatestack * p_stack);
virtual void on_symbol(const std::string & symbol_name,
exprstatestack * p_stack,
@ -71,6 +71,9 @@ namespace xo {
virtual void print(std::ostream & os) const override;
private:
static std::unique_ptr<expect_formal_xs> make();
private:
/** parsing state-machine state **/
formalstatetype formalxs_type_ = formalstatetype::formal_0;

View file

@ -54,7 +54,7 @@ namespace xo {
if (farglxs_type_ == formalarglstatetype::argl_0) {
this->farglxs_type_ = formalarglstatetype::argl_1a;
/* TODO: refactor to have setup method on each exprstate */
p_stack->push_exprstate(expect_formal_xs::make());
expect_formal_xs::start(p_stack);
expect_symbol_xs::start(p_stack);
} else {
exprstate::on_leftparen_token(tk, p_stack, p_emit_expr);
@ -81,7 +81,7 @@ namespace xo {
{
if (farglxs_type_ == formalarglstatetype::argl_1b) {
this->farglxs_type_ = formalarglstatetype::argl_1a;
p_stack->push_exprstate(expect_formal_xs::make());
expect_formal_xs::start(p_stack);
} else {
exprstate::on_comma_token(tk, p_stack, p_emit_expr);
}

View file

@ -34,6 +34,11 @@ namespace xo {
return std::make_unique<expect_formal_xs>(expect_formal_xs());
}
void
expect_formal_xs::start(exprstatestack * p_stack) {
p_stack->push_exprstate(expect_formal_xs::make());
}
expect_formal_xs::expect_formal_xs()
: exprstate(exprstatetype::expect_formal)
{}