xo-reader: simplify paren handling for expressions

This commit is contained in:
Roland Conybeare 2024-08-09 20:33:28 -04:00
commit 6b9503ef76
4 changed files with 21 additions and 45 deletions

View file

@ -19,6 +19,9 @@ namespace xo {
static std::unique_ptr<expect_expr_xs> expect_rhs_expression();
virtual void on_leftparen_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr) override;
virtual void on_f64_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr) override;

View file

@ -70,11 +70,6 @@ namespace xo {
{}
virtual ~exprstate() = default;
#ifdef RELOCATED
static std::unique_ptr<exprstate> expect_rhs_expression() {
return std::make_unique<exprstate>(exprstate(exprstatetype::expect_rhs_expression));
}
#endif
static std::unique_ptr<exprstate> expect_symbol() {
return std::make_unique<exprstate>(exprstate(exprstatetype::expect_symbol));
}
@ -96,10 +91,6 @@ namespace xo {
virtual bool admits_leftparen() const;
/** truee iff this parsing state admits a rightparen ')' as next token **/
virtual bool admits_rightparen() const;
#ifdef OBSOLETE
/** true iff this parsing state admits a 64-bit floating point literal token **/
virtual bool admits_f64() const;
#endif
/** update exprstate in response to incoming token @p tk,
* forward instructions to parent parser

View file

@ -4,6 +4,7 @@
*/
#include "expect_expr_xs.hpp"
#include "paren_xs.hpp"
#include "progress_xs.hpp"
#include "xo/expression/Constant.hpp"
@ -22,6 +23,21 @@ namespace xo {
: exprstate(exprstatetype::expect_rhs_expression)
{}
void
expect_expr_xs::on_leftparen_token(const token_type & /*tk*/,
exprstatestack * p_stack,
rp<Expression> * /*p_emit_expr*/)
{
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag));
//constexpr const char * self_name = "exprstate::on_leftparen";
/* push lparen_0 to remember to look for subsequent rightparen. */
p_stack->push_exprstate(paren_xs::lparen_0());
p_stack->push_exprstate(expect_expr_xs::expect_rhs_expression());
}
void
expect_expr_xs::on_f64_token(const token_type & tk,
exprstatestack * p_stack,

View file

@ -196,14 +196,11 @@ namespace xo {
case exprstatetype::defexpr:
case exprstatetype::parenexpr:
/* unreachable - redirects to define_xs */
case exprstatetype::expect_rhs_expression:
/* unreachable - redirects to define_xs etc */
assert(false);
return false;
case exprstatetype::expect_rhs_expression:
/* can always begin non-toplevel expression with '(' */
return true;
case exprstatetype::expect_type:
return false;
@ -257,37 +254,6 @@ namespace xo {
return false;
}
#ifdef OBSOLETE
bool
exprstate::admits_f64() const {
switch (exs_type_) {
case exprstatetype::expect_toplevel_expression_sequence:
case exprstatetype::defexpr:
case exprstatetype::parenexpr:
case exprstatetype::expect_rhs_expression:
/* unreachable - redirects to define_xs */
assert(false);
return false;
case exprstatetype::expect_symbol:
case exprstatetype::expect_type:
return false;
case exprstatetype::expr_progress:
/* unreachable */
assert(false);
return false;
case exprstatetype::invalid:
case exprstatetype::n_exprstatetype:
/* unreachable */
return false;
}
return false;
}
#endif
void
exprstate::on_def_token(const token_type & tk,
exprstatestack * /*p_stack*/)