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

@ -70,7 +70,7 @@ namespace xo {
static const define_xs * from(const exprstate * x) { return dynamic_cast<const define_xs *>(x); }
static void start(exprstatestack * p_stack);
static void start(parserstatemachine * p_psm);
defexprstatetype defxs_type() const { return defxs_type_; }
@ -84,7 +84,7 @@ namespace xo {
exprstatestack * p_stack,
rp<Expression> * p_emit_expr) override;
virtual void on_def_token(const token_type & tk,
exprstatestack * p_stack) override;
parserstatemachine * p_psm) override;
virtual void on_colon_token(const token_type & tk,
exprstatestack * p_stack) override;
virtual void on_semicolon_token(const token_type & tk,

View file

@ -24,7 +24,7 @@ namespace xo {
// ----- token input methods -----
virtual void on_def_token(const token_type & tk,
exprstatestack * p_stack) override;
parserstatemachine * p_psm) override;
virtual void on_symbol_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr) override;

View file

@ -63,6 +63,7 @@ namespace xo {
return os;
}
class parserstatemachine;
class exprstatestack;
class formal_arg;
@ -120,7 +121,7 @@ namespace xo {
/** handle incoming 'def' token **/
virtual void on_def_token(const token_type & tk,
exprstatestack * p_stack);
parserstatemachine * p_psm);
/** handle incoming 'lambda' token **/
virtual void on_lambda_token(const token_type & tk,
exprstatestack * p_stack,

View file

@ -45,7 +45,7 @@ namespace xo {
rp<Expression> * /*p_emit_expr*/) override;
virtual void on_def_token(const token_type & tk,
exprstatestack * p_stack) override;
parserstatemachine * p_psm) override;
virtual void on_symbol_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr) override;

View file

@ -0,0 +1,36 @@
/* file parserstatemachine.hpp
*
* author: Roland Conybeare, Aug 2024
*/
#pragma once
#include "exprstate.hpp"
namespace xo {
namespace scm {
/** @class parserstatemachine
* @brief public parser state.
*
* Schematica parser state; sent to subsidiary single-feature state machines.
* For example entry points for the lambda feature (@ref lambda_xs)
* will accept a non-const parserstatemachine pointer argument
**/
class parserstatemachine {
public:
using Expression = xo::ast::Expression;
public:
parserstatemachine(exprstatestack * p_stack,
rp<Expression> * p_emit_expr)
: p_stack_{p_stack}, p_emit_expr_{p_emit_expr} {}
public:
exprstatestack * p_stack_;
rp<Expression> * p_emit_expr_;
};
} /*namespace scm*/
} /*namespace xo*/
/* end parserstatemachine.hpp */

View file

@ -66,7 +66,7 @@ namespace xo {
rp<Expression> * /*p_emit_expr*/) override;
virtual void on_def_token(const token_type & tk,
exprstatestack * p_stack) override;
parserstatemachine * p_psm) override;
virtual void on_colon_token(const token_type & tk,
exprstatestack * p_stack) override;
virtual void on_semicolon_token(const token_type & tk,