xo-reader: uncopy: with + exprstate.illegal_input_error()
This commit is contained in:
parent
60a7ec1cd0
commit
74099cacab
5 changed files with 61 additions and 81 deletions
|
|
@ -156,6 +156,13 @@ namespace xo {
|
|||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr);
|
||||
|
||||
protected:
|
||||
/** throw exception when next token is inconsistent with
|
||||
* parsing state
|
||||
**/
|
||||
void illegal_input_error(const char * self_name,
|
||||
const token_type & tk) const;
|
||||
|
||||
protected:
|
||||
/** explicit subtype: identifies derived class **/
|
||||
exprstatetype exs_type_;
|
||||
|
|
|
|||
|
|
@ -382,7 +382,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
define_xs::on_singleassign_token(const token_type & /*tk*/,
|
||||
define_xs::on_singleassign_token(const token_type & tk,
|
||||
exprstatestack * p_stack)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
|
|
@ -390,11 +390,8 @@ namespace xo {
|
|||
|
||||
constexpr const char * self_name = "exprstate::on_singleassign";
|
||||
|
||||
if (!this->admits_singleassign())
|
||||
{
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": unexpected equals for parsing state",
|
||||
xtag("state", *this)));
|
||||
if (!this->admits_singleassign()) {
|
||||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
if ((this->defxs_type_ == defexprstatetype::def_1)
|
||||
|
|
@ -409,7 +406,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
define_xs::on_leftparen_token(const token_type & /*tk*/,
|
||||
define_xs::on_leftparen_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/,
|
||||
rp<Expression> * /*p_emit_expr*/)
|
||||
{
|
||||
|
|
@ -420,16 +417,14 @@ namespace xo {
|
|||
|
||||
if (!this->admits_leftparen())
|
||||
{
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": unexpected leftparen '(' for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
assert(false); /* inserting this during refactor...? */
|
||||
}
|
||||
|
||||
void
|
||||
define_xs::on_rightparen_token(const token_type & /*tk*/,
|
||||
define_xs::on_rightparen_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/,
|
||||
rp<Expression> * /*p_emit_expr*/)
|
||||
{
|
||||
|
|
@ -440,16 +435,14 @@ namespace xo {
|
|||
|
||||
if (!this->admits_rightparen())
|
||||
{
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": unexpected rightparen ')' for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
assert(false); /* inserting this during refactor..? */
|
||||
}
|
||||
|
||||
void
|
||||
define_xs::on_f64_token(const token_type & /*tk*/,
|
||||
define_xs::on_f64_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/,
|
||||
rp<Expression> * /*p_emit_expr*/)
|
||||
{
|
||||
|
|
@ -460,9 +453,7 @@ namespace xo {
|
|||
|
||||
if (!this->admits_f64())
|
||||
{
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": unexpected floating-point literal for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
assert(false);
|
||||
|
|
|
|||
|
|
@ -320,19 +320,18 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
exprstate::on_def_token(const token_type & /*tk*/,
|
||||
exprstatestack * p_stack) {
|
||||
exprstate::on_def_token(const token_type & tk,
|
||||
exprstatestack * p_stack)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
constexpr const char * self_name = "exprstate::on_def";
|
||||
constexpr const char * c_self_name = "exprstate::on_def_token";
|
||||
|
||||
/* lots of illegal states */
|
||||
if (!this->admits_definition())
|
||||
{
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": unexpected keyword 'def' for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
|
||||
p_stack->push_exprstate(define_xs::def_0());
|
||||
|
|
@ -358,20 +357,16 @@ namespace xo {
|
|||
|
||||
log && log(xtag("exstype", p_stack->top_exprstate().exs_type()));
|
||||
|
||||
constexpr const char * self_name = "exprstate::on_symbol";
|
||||
constexpr const char * c_self_name = "exprstate::on_symbol_token";
|
||||
|
||||
if (!this->admits_symbol()) {
|
||||
throw std::runtime_error
|
||||
(tostr(self_name,
|
||||
": unexpected symbol-token for parsing state",
|
||||
xtag("symbol", tk),
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
|
||||
switch (this->exs_type_) {
|
||||
case exprstatetype::expect_toplevel_expression_sequence:
|
||||
throw std::runtime_error
|
||||
(tostr(self_name,
|
||||
(tostr(c_self_name,
|
||||
": unexpected symbol-token at top-level",
|
||||
" (expecting decl|def)",
|
||||
xtag("symbol", tk)));
|
||||
|
|
@ -442,7 +437,7 @@ namespace xo {
|
|||
|
||||
if (!td) {
|
||||
throw std::runtime_error
|
||||
(tostr(self_name,
|
||||
(tostr(c_self_name,
|
||||
": unknown type name",
|
||||
" (expecting f64|f32|i16|i32|i64)",
|
||||
xtag("typename", tk.text())));
|
||||
|
|
@ -835,6 +830,17 @@ namespace xo {
|
|||
os << ">";
|
||||
}
|
||||
|
||||
void
|
||||
exprstate::illegal_input_error(const char * self_name,
|
||||
const token_type & tk) const
|
||||
{
|
||||
throw std::runtime_error
|
||||
(tostr(self_name,
|
||||
": unexpected input token for parsing state",
|
||||
xtag("token", tk),
|
||||
xtag("state", *this)));
|
||||
}
|
||||
|
||||
// ----- exprstatestack -----
|
||||
|
||||
exprstate &
|
||||
|
|
|
|||
|
|
@ -73,14 +73,12 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
paren_xs::on_def_token(const token_type & /*tk*/,
|
||||
paren_xs::on_def_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/)
|
||||
{
|
||||
constexpr const char * c_self_name = "paren_xs::on_def";
|
||||
|
||||
throw std::runtime_error(tostr(c_self_name,
|
||||
": unexpected keyword 'def' for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -110,66 +108,56 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
paren_xs::on_colon_token(const token_type & /*tk*/,
|
||||
paren_xs::on_colon_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/)
|
||||
{
|
||||
constexpr const char * c_self_name = "paren_xs::on_colon";
|
||||
|
||||
throw std::runtime_error(tostr(c_self_name,
|
||||
": unexpected colon for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
paren_xs::on_semicolon_token(const token_type & /*tk*/,
|
||||
paren_xs::on_semicolon_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/,
|
||||
rp<Expression> * /*p_emit_expr*/)
|
||||
{
|
||||
constexpr const char * c_self_name = "paren_xs::on_semicolon";
|
||||
|
||||
throw std::runtime_error(tostr(c_self_name,
|
||||
": unexpected semicolon for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
paren_xs::on_singleassign_token(const token_type & /*tk*/,
|
||||
paren_xs::on_singleassign_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/)
|
||||
{
|
||||
constexpr const char * c_self_name = "paren_xs::on_singleassign";
|
||||
|
||||
throw std::runtime_error(tostr(c_self_name,
|
||||
": unexpected equals for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
paren_xs::on_leftparen_token(const token_type & /*tk*/,
|
||||
paren_xs::on_leftparen_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/,
|
||||
rp<Expression> * /*p_emit_expr*/)
|
||||
{
|
||||
constexpr const char * c_self_name = "paren_xs::on_leftparen";
|
||||
|
||||
throw std::runtime_error(tostr(c_self_name,
|
||||
": unexpected leftparen '(' for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
paren_xs::on_rightparen_token(const token_type & /*tk*/,
|
||||
paren_xs::on_rightparen_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 = "paren_xs::on_rightparen";
|
||||
constexpr const char * c_self_name = "paren_xs::on_rightparen";
|
||||
|
||||
if (!this->admits_rightparen())
|
||||
{
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": unexpected rightparen ')' for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
|
||||
if (this->parenxs_type_ == parenexprstatetype::lparen_1) {
|
||||
|
|
@ -182,7 +170,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
paren_xs::on_f64_token(const token_type & /*tk*/,
|
||||
paren_xs::on_f64_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/,
|
||||
rp<Expression> * /*p_emit_expr*/)
|
||||
{
|
||||
|
|
@ -193,9 +181,7 @@ namespace xo {
|
|||
|
||||
if (!this->admits_f64())
|
||||
{
|
||||
throw std::runtime_error(tostr(c_self_name,
|
||||
": unexpected floating-point literal for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
|
||||
assert(false);
|
||||
|
|
|
|||
|
|
@ -43,15 +43,13 @@ namespace xo {
|
|||
progress_xs::admits_f64() const { return false; }
|
||||
|
||||
void
|
||||
progress_xs::on_def_token(const token_type & /*tk*/,
|
||||
progress_xs::on_def_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/)
|
||||
{
|
||||
constexpr const char * self_name = "progress_xs::on_def";
|
||||
|
||||
/* nothing here - admits_definition unconditionally false */
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": unexpected keyword 'def' for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(self_name, tk) ;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -84,14 +82,12 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
progress_xs::on_colon_token(const token_type & /*tk*/,
|
||||
progress_xs::on_colon_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/)
|
||||
{
|
||||
constexpr const char * self_name = "progress_xs::on_colon";
|
||||
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": unexpected colon for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -128,18 +124,16 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
progress_xs::on_singleassign_token(const token_type & /*tk*/,
|
||||
progress_xs::on_singleassign_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/)
|
||||
{
|
||||
constexpr const char * self_name = "progress_xs::on_singleassign";
|
||||
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": unexpected equals for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_leftparen_token(const token_type & /*tk*/,
|
||||
progress_xs::on_leftparen_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/,
|
||||
rp<Expression> * /*p_emit_expr*/)
|
||||
{
|
||||
|
|
@ -148,9 +142,7 @@ namespace xo {
|
|||
|
||||
constexpr const char * self_name = "exprstate::on_leftparen";
|
||||
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": unexpected leftparen '(' for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -194,7 +186,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
progress_xs::on_f64_token(const token_type & /*tk*/,
|
||||
progress_xs::on_f64_token(const token_type & tk,
|
||||
exprstatestack * /*p_stack*/,
|
||||
rp<Expression> * /*p_emit_expr*/)
|
||||
{
|
||||
|
|
@ -203,9 +195,7 @@ namespace xo {
|
|||
|
||||
constexpr const char * self_name = "progress_xs::on_f64";
|
||||
|
||||
throw std::runtime_error(tostr(self_name,
|
||||
": unexpected floating-point literal for parsing state",
|
||||
xtag("state", *this)));
|
||||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue