xo-reader: + expect_formal_xs [wip - not used]
This commit is contained in:
parent
f677995f77
commit
6d5387eef7
8 changed files with 282 additions and 12 deletions
|
|
@ -11,6 +11,7 @@ set(SELF_SRCS
|
|||
exprseq_xs.cpp
|
||||
expect_expr_xs.cpp
|
||||
expect_symbol_xs.cpp
|
||||
expect_formal_xs.cpp
|
||||
expect_type_xs.cpp)
|
||||
|
||||
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
|
||||
|
|
|
|||
87
src/reader/expect_formal_xs.cpp
Normal file
87
src/reader/expect_formal_xs.cpp
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/* file expect_formal_xs.cpp
|
||||
*
|
||||
* author: Roland Conybeare
|
||||
*/
|
||||
|
||||
#include "expect_formal_xs.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::reflect::TypeDescr;
|
||||
|
||||
namespace scm{
|
||||
const char *
|
||||
formalstatetype_descr(formalstatetype x) {
|
||||
switch (x) {
|
||||
case formalstatetype::invalid:
|
||||
case formalstatetype::n_formalstatetype:
|
||||
return "?formalstatetype";
|
||||
case formalstatetype::formal_0:
|
||||
return "formal_0";
|
||||
case formalstatetype::formal_1:
|
||||
return "formal_1";
|
||||
case formalstatetype::formal_2:
|
||||
return "formal_2";
|
||||
}
|
||||
|
||||
return "???formalstatetype";
|
||||
}
|
||||
|
||||
void
|
||||
expect_formal_xs::on_symbol(const std::string & symbol_name,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr)
|
||||
{
|
||||
if (this->formalxs_type_ == formalstatetype::formal_0) {
|
||||
this->formalxs_type_ = formalstatetype::formal_1;
|
||||
this->result_.assign_name(symbol_name);
|
||||
} else {
|
||||
exprstate::on_symbol(symbol_name,
|
||||
p_stack,
|
||||
p_emit_expr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
expect_formal_xs::on_colon_token(const token_type & tk,
|
||||
exprstatestack * p_stack
|
||||
/* rp<Expression> * p_emit_expr */)
|
||||
{
|
||||
if (this->formalxs_type_ == formalstatetype::formal_1) {
|
||||
this->formalxs_type_ = formalstatetype::formal_2;
|
||||
} else {
|
||||
exprstate::on_colon_token(tk,
|
||||
p_stack);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
expect_formal_xs::on_typedescr(TypeDescr td,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr)
|
||||
{
|
||||
if (this->formalxs_type_ == formalstatetype::formal_2) {
|
||||
this->result_.assign_td(td);
|
||||
|
||||
std::unique_ptr<exprstate> self = p_stack->pop_exprstate();
|
||||
|
||||
//p_stack->top_exprstate().on_formal(result_, p_stack, p_emit_expr);
|
||||
} else {
|
||||
exprstate::on_typedescr(td, p_stack, p_emit_expr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
expect_formal_xs::print(std::ostream & os) const {
|
||||
os << "<expect_formal_xs"
|
||||
<< xtag("type", formalxs_type_);
|
||||
if (!result_.name().empty())
|
||||
os << xtag("result.name", result_.name());
|
||||
if (result_.td())
|
||||
os << xtag("result.td", result_.td());
|
||||
os << ">";
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end expect_formal_xs.cpp */
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
/* @file exprstate.cpp */
|
||||
|
||||
#include "exprstate.hpp"
|
||||
#include "formal_arg.hpp"
|
||||
#include <stdexcept>
|
||||
//#include "define_xs.hpp"
|
||||
//#include "progress_xs.hpp"
|
||||
//#include "paren_xs.hpp"
|
||||
|
|
@ -63,15 +65,45 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
exprstate::on_typedescr(TypeDescr /*td*/,
|
||||
exprstatestack * /*p_stack*/,
|
||||
exprstate::on_typedescr(TypeDescr td,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * /*p_emit_expr*/)
|
||||
{
|
||||
/* returning type description to something that wants it */
|
||||
|
||||
/* unreachable - implement in derived class */
|
||||
assert(false);
|
||||
return;
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
log && log(xtag("exstype",
|
||||
p_stack->top_exprstate().exs_type()));
|
||||
|
||||
constexpr const char * c_self_name = "exprstate::on_typedescr";
|
||||
|
||||
throw std::runtime_error(tostr(c_self_name,
|
||||
": unexpected typedescr for parsing state",
|
||||
xtag("td", td),
|
||||
xtag("state", *this)));
|
||||
}
|
||||
|
||||
void
|
||||
exprstate::on_formal(const formal_arg & formal,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * /*p_emit_expr*/)
|
||||
{
|
||||
/* returning type description to something that wants it */
|
||||
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
log && log(xtag("exstype",
|
||||
p_stack->top_exprstate().exs_type()));
|
||||
|
||||
constexpr const char * c_self_name = "exprstate::on_formal";
|
||||
|
||||
throw std::runtime_error(tostr(c_self_name,
|
||||
": unexpected formal-arg for parsing state",
|
||||
xtag("formal", formal),
|
||||
xtag("state", *this)));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -254,13 +286,19 @@ namespace xo {
|
|||
} /*on_expr*/
|
||||
|
||||
void
|
||||
exprstate::on_symbol(const std::string & /*symbol_name*/,
|
||||
exprstate::on_symbol(const std::string & symbol_name,
|
||||
exprstatestack * /*p_stack*/,
|
||||
rp<Expression> * /*p_emit_expr*/)
|
||||
{
|
||||
/* unreachable - derived class that can receive
|
||||
* will override this method
|
||||
*/
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
log && log(xtag("exstype", this->exs_type_),
|
||||
xtag("symbol_name", symbol_name));
|
||||
|
||||
assert(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue