xo-reader: ++ logging

This commit is contained in:
Roland Conybeare 2024-08-28 09:34:30 -04:00
commit 84e6d3f347
8 changed files with 74 additions and 19 deletions

View file

@ -57,7 +57,10 @@ namespace xo {
inline std::ostream &
operator<< (std::ostream & os, const exprstatestack * x) {
x->print(os);
if (x)
x->print(os);
else
os << "nullptr";
return os;
}
} /*namespace scm*/

View file

@ -32,6 +32,15 @@ namespace xo {
n_lambdastatetype
};
extern const char *
lambdastatetype_descr(lambdastatetype x);
inline std::ostream &
operator<< (std::ostream & os, lambdastatetype x) {
os << lambdastatetype_descr(x);
return os;
}
/** @class lambda_xs
* @brief parsing state-machine for a lambda-expression
*
@ -53,6 +62,8 @@ namespace xo {
virtual void on_semicolon_token(const token_type & tk,
parserstatemachine * p_psm) override;
virtual void print(std::ostream & os) const override;
private:
static std::unique_ptr<lambda_xs> make();

View file

@ -64,7 +64,7 @@ namespace xo {
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag));
log && log("defxs_type", defxs_type_);
log && log(xtag("defxs_type", defxs_type_));
if (this->defxs_type_ == defexprstatetype::def_5) {
/* have all the ingredients to create an expression
@ -84,10 +84,11 @@ namespace xo {
rp<Expression> def_expr = this->def_expr_;
this->defxs_type_ = defexprstatetype::def_6;
return;
} else {
exprstate::on_expr(expr, p_psm);
}
}
exprstate::on_expr(expr, p_psm);
void
define_xs::on_expr_with_semicolon(ref::brw<Expression> expr,
parserstatemachine * p_psm)
@ -177,6 +178,8 @@ namespace xo {
define_xs::on_semicolon_token(const token_type & tk,
parserstatemachine * p_psm)
{
/* def expr consumes semicolon */
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag));
@ -200,7 +203,7 @@ namespace xo {
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag));
constexpr const char * self_name = "exprstate::on_singleassign";
constexpr const char * self_name = "define_xs::on_singleassign_token";
log && log("defxs_type", defxs_type_);
@ -237,7 +240,7 @@ namespace xo {
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag));
constexpr const char * self_name = "exprstate::on_rightparen";
constexpr const char * self_name = "define_xs::on_rightparen";
this->illegal_input_error(self_name, tk);
}
@ -249,7 +252,7 @@ namespace xo {
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag));
constexpr const char * self_name = "exprstate::on_f64";
constexpr const char * self_name = "define_xs::on_f64";
this->illegal_input_error(self_name, tk);
}
@ -257,13 +260,14 @@ namespace xo {
void
define_xs::print(std::ostream & os) const {
os << "<define_xs"
<< xtag("this", (void*)this)
//<< xtag("type", exs_type_)
<< xtag("defxs_type", defxs_type_);
if (def_expr_)
os << xtag("def_expr", def_expr_);
if (cvt_expr_)
os << xtag("cvt_expr", cvt_expr_);
//if (def_expr_)
// os << xtag("def_expr", def_expr_);
//if (cvt_expr_)
// os << xtag("cvt_expr", cvt_expr_);
os << ">";
}
} /*namespace scm*/

View file

@ -31,7 +31,8 @@ namespace xo {
void
expect_expr_xs::start(bool allow_defs,
bool cxl_on_rightbrace,
parserstatemachine * p_psm) {
parserstatemachine * p_psm)
{
p_psm->push_exprstate(expect_expr_xs::make(allow_defs,
cxl_on_rightbrace));
}
@ -192,7 +193,7 @@ namespace xo {
std::unique_ptr<exprstate> self = p_psm->pop_exprstate();
p_psm->top_exprstate().on_expr(expr, p_psm);
p_psm->on_expr(expr);
} /*on_expr*/
void

View file

@ -11,6 +11,22 @@ namespace xo {
using xo::ast::Lambda;
namespace scm {
const char *
lambdastatetype_descr(lambdastatetype x) {
switch(x) {
case lambdastatetype::invalid: return "invalid";
case lambdastatetype::lm_0: return "lm_0";
case lambdastatetype::lm_1: return "lm_1";
case lambdastatetype::lm_2: return "lm_2";
case lambdastatetype::lm_3: return "lm_3";
default: break;
}
return "???lambdastatetype";
}
// ----- lambda_xs - ----
std::unique_ptr<lambda_xs>
lambda_xs::make() {
return std::make_unique<lambda_xs>(lambda_xs());
@ -97,6 +113,14 @@ namespace xo {
exprstate::on_semicolon_token(tk, p_psm);
}
void
lambda_xs::print(std::ostream & os) const {
os << "<lambda_xs"
<< xtag("lmxs_type", lmxs_type_)
<< ">";
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -235,6 +235,7 @@ namespace xo {
void
paren_xs::print(std::ostream & os) const {
os << "<paren_xs"
<< xtag("this", (void*)this)
//<< xtag("type", exs_type_);
<< xtag("parenxs_type", parenxs_type_);

View file

@ -87,6 +87,19 @@ namespace xo {
->top_exprstate().on_symbol(x, this);
}
void
parserstatemachine::on_semicolon_token(const token_type & tk)
{
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag));
log && log(xtag("tk", tk),
xtag("psm", *this));
this->p_stack_
->top_exprstate().on_semicolon_token(tk, this);
}
void
parserstatemachine::on_leftbrace_token(const token_type & tk)
{

View file

@ -237,14 +237,11 @@ namespace xo {
* b. 1.234 pushes (in case operators) [lparen_0:expect_rhs_expression:expr_progress]
* (see exprstate::on_f64())
* c. semicolon completes expr_progress [lparen_0:expect_rhs_expression]
* deliver expresssion to expect_rhs_expression.on_expr()
* (see exprstate::on_expr())
* deliver expresssion to expect_rhs_expression.on_expr_with_semicolon()
* (see exprstate::on_expr_with_semicolon())
* d. expr_rhs_expression forwards expression to [lparen_0]
* e. lparen_0 advances to [lparen_1]
* f. now deliver semicolon; [lparen_1] rejects
* e. lparen_0 would advance to [lparen_1], but rejects semicolon
*/
p_psm->top_exprstate().on_semicolon_token(tk, p_psm);
}
void
@ -420,6 +417,7 @@ namespace xo {
void
progress_xs::print(std::ostream & os) const {
os << "<progress_xs"
<< xtag("this", (void*)this)
<< xtag("type", exs_type_);
if (lhs_)
os << xtag("lhs", lhs_);