xo-reader: feat: + var lookup in envframestack, psm

This commit is contained in:
Roland Conybeare 2024-08-19 18:11:28 -04:00
commit eed5cdf691
4 changed files with 51 additions and 0 deletions

View file

@ -13,12 +13,21 @@ namespace xo {
* @brief A stack of envframe objects
**/
class envframestack {
public:
using Variable = xo::ast::Variable;
public:
envframestack() {}
bool empty() const { return stack_.empty(); }
std::size_t size() const { return stack_.size(); }
/** lookup variable in environment stack.
* Visit frames in fifo order, report first match;
* nullptr if no matches.
**/
rp<Variable> lookup(const std::string & x) const;
envframe & top_envframe();
void push_envframe(envframe x);
void pop_envframe();

View file

@ -20,6 +20,7 @@ namespace xo {
class parserstatemachine {
public:
using Expression = xo::ast::Expression;
using Variable = xo::ast::Variable;
public:
parserstatemachine(exprstatestack * p_stack,
@ -33,6 +34,14 @@ namespace xo {
exprstate & top_exprstate();
void push_exprstate(std::unique_ptr<exprstate> x);
/** lookup variable name in lexical context represented by
* this psm. nullptr if not found
**/
rp<Variable> lookup_var(const std::string & x) const;
void push_envframe(envframe x);
void pop_envframe();
public:
/** stack of incomplete parser work.
* generally speaking, push when to start new work for nested content;