xo-reader: refactor: + parserstatemachine; use for def_expr

This commit is contained in:
Roland Conybeare 2024-08-19 00:44:34 -04:00
commit 034dac7dfd
11 changed files with 69 additions and 18 deletions

View file

@ -1,6 +1,7 @@
/* @file define_xs.cpp */
#include "define_xs.hpp"
#include "parserstatemachine.hpp"
#include "expect_symbol_xs.hpp"
#include "expect_expr_xs.hpp"
#include "expect_type_xs.hpp"
@ -13,10 +14,12 @@ namespace xo {
}
void
define_xs::start(exprstatestack * p_stack)
define_xs::start(parserstatemachine * p_psm)
{
auto p_stack = p_psm->p_stack_;
p_stack->push_exprstate(define_xs::make());
p_stack->top_exprstate().on_def_token(token_type::def(), p_stack);
p_stack->top_exprstate().on_def_token(token_type::def(), p_psm);
}
define_xs::define_xs(rp<DefineExprAccess> def_expr)
@ -88,7 +91,7 @@ namespace xo {
void
define_xs::on_def_token(const token_type & tk,
exprstatestack * p_stack)
parserstatemachine * p_psm)
{
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag));
@ -98,9 +101,9 @@ namespace xo {
if (this->defxs_type_ == defexprstatetype::def_0) {
this->defxs_type_ = defexprstatetype::def_1;
expect_symbol_xs::start(p_stack);
expect_symbol_xs::start(p_psm->p_stack_);
} else {
exprstate::on_def_token(tk, p_stack);
exprstate::on_def_token(tk, p_psm);
}
}

View file

@ -25,14 +25,14 @@ namespace xo {
void
exprseq_xs::on_def_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 * c_self_name = "exprseq_xs::on_def_token";
define_xs::start(p_stack);
define_xs::start(p_psm);
/* keyword 'def' introduces a definition:
* def pi : f64 = 3.14159265

View file

@ -1,6 +1,7 @@
/* @file exprstate.cpp */
#include "exprstate.hpp"
#include "parserstatemachine.hpp"
//#include "formal_arg.hpp"
#include "xo/expression/Variable.hpp"
#include "xo/indentlog/print/vector.hpp"
@ -52,7 +53,7 @@ namespace xo {
void
exprstate::on_def_token(const token_type & tk,
exprstatestack * /*p_stack*/)
parserstatemachine * /*p_psm*/)
{
this->illegal_input_error("exprstate::on_def_token", tk);
}
@ -254,10 +255,12 @@ namespace xo {
log && log(xtag("tk", tk));
log && log(xtag("state", *this));
parserstatemachine psm(p_stack, p_emit_expr);
switch (tk.tk_type()) {
case tokentype::tk_def:
this->on_def_token(tk, p_stack);
this->on_def_token(tk, &psm);
return;
case tokentype::tk_lambda:

View file

@ -2,6 +2,7 @@
#include "paren_xs.hpp"
#include "progress_xs.hpp"
#include "expect_expr_xs.hpp"
namespace xo {
namespace scm {
@ -10,10 +11,17 @@ namespace xo {
{}
std::unique_ptr<paren_xs>
paren_xs::lparen_0() {
paren_xs::make() {
return std::make_unique<paren_xs>(paren_xs());
}
void
paren_xs::start(exprstatestack * p_stack)
{
p_stack->push_exprstate(paren_xs::make());
expect_expr_xs::start(p_stack);
}
bool
paren_xs::admits_rightparen() const {
switch (parenxs_type_) {
@ -56,7 +64,7 @@ namespace xo {
void
paren_xs::on_def_token(const token_type & tk,
exprstatestack * /*p_stack*/)
parserstatemachine * /*p_stack*/)
{
constexpr const char * c_self_name = "paren_xs::on_def";

View file

@ -73,7 +73,7 @@ namespace xo {
void
progress_xs::on_def_token(const token_type & tk,
exprstatestack * /*p_stack*/)
parserstatemachine * /*p_stack*/)
{
constexpr const char * self_name = "progress_xs::on_def";