xo-reader: feat: mvp lambda parsing [untested]
This commit is contained in:
parent
0841fd7dbd
commit
1628d8f44c
5 changed files with 134 additions and 27 deletions
|
|
@ -4,9 +4,30 @@
|
|||
*/
|
||||
|
||||
#include "expect_formal_arglist_xs.hpp"
|
||||
#include "expect_formal_xs.hpp"
|
||||
#include "xo/expression/Variable.hpp"
|
||||
#include "xo/indentlog/print/vector.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
const char *
|
||||
formalarglstatetype_descr(formalarglstatetype x) {
|
||||
switch (x) {
|
||||
case formalarglstatetype::invalid:
|
||||
return "invalid";
|
||||
case formalarglstatetype::argl_0:
|
||||
return "argl_0";
|
||||
case formalarglstatetype::argl_1a:
|
||||
return "argl_1a";
|
||||
case formalarglstatetype::argl_1b:
|
||||
return "argl_1b";
|
||||
case formalarglstatetype::n_formalarglstatetype:
|
||||
break;
|
||||
}
|
||||
|
||||
return "?formalarglstatetype";
|
||||
}
|
||||
|
||||
std::unique_ptr<expect_formal_arglist_xs>
|
||||
expect_formal_arglist_xs::make() {
|
||||
return std::make_unique<expect_formal_arglist_xs>
|
||||
|
|
@ -23,13 +44,62 @@ namespace xo {
|
|||
rp<Expression> * p_emit_expr)
|
||||
{
|
||||
if (farglxs_type_ == formalarglstatetype::argl_0) {
|
||||
this->farglxs_type_ = formalarglstatetype::argl_1;
|
||||
return;
|
||||
this->farglxs_type_ = formalarglstatetype::argl_1a;
|
||||
p_stack->push_exprstate(expect_formal_xs::make());
|
||||
} else {
|
||||
exprstate::on_leftparen_token(tk, p_stack, p_emit_expr);
|
||||
}
|
||||
|
||||
exprstate::on_leftparen_token(tk, p_stack, p_emit_expr);
|
||||
}
|
||||
|
||||
void
|
||||
expect_formal_arglist_xs::on_formal(const rp<Variable> & formal,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr)
|
||||
{
|
||||
if (farglxs_type_ == formalarglstatetype::argl_1a) {
|
||||
this->farglxs_type_ = formalarglstatetype::argl_1b;
|
||||
this->argl_.push_back(formal);
|
||||
} else {
|
||||
exprstate::on_formal(formal, p_stack, p_emit_expr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
expect_formal_arglist_xs::on_comma_token(const token_type & tk,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr)
|
||||
{
|
||||
if (farglxs_type_ == formalarglstatetype::argl_1b) {
|
||||
this->farglxs_type_ = formalarglstatetype::argl_1a;
|
||||
p_stack->push_exprstate(expect_formal_xs::make());
|
||||
} else {
|
||||
exprstate::on_comma_token(tk, p_stack, p_emit_expr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
expect_formal_arglist_xs::on_rightparen_token(const token_type & tk,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr)
|
||||
{
|
||||
if (farglxs_type_ == formalarglstatetype::argl_1b) {
|
||||
std::unique_ptr<exprstate> self = p_stack->pop_exprstate();
|
||||
|
||||
p_stack->top_exprstate().on_formal_arglist(this->argl_,
|
||||
p_stack, p_emit_expr);
|
||||
} else {
|
||||
exprstate::on_rightparen_token(tk, p_stack, p_emit_expr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
expect_formal_arglist_xs::print(std::ostream & os) const {
|
||||
os << "<expect_formal_arglist_xs"
|
||||
<< xtag("type", farglxs_type_);
|
||||
os << xtag("farglxs_type", farglxs_type_);
|
||||
os << xtag("argl", argl_);
|
||||
os << ">";
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@
|
|||
*/
|
||||
|
||||
#include "expect_formal_xs.hpp"
|
||||
#include "xo/expression/Variable.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::ast::Variable;
|
||||
using xo::reflect::TypeDescr;
|
||||
|
||||
namespace scm{
|
||||
|
|
@ -26,6 +28,11 @@ namespace xo {
|
|||
return "???formalstatetype";
|
||||
}
|
||||
|
||||
std::unique_ptr<expect_formal_xs>
|
||||
expect_formal_xs::make() {
|
||||
return std::make_unique<expect_formal_xs>(expect_formal_xs());
|
||||
}
|
||||
|
||||
void
|
||||
expect_formal_xs::on_symbol(const std::string & symbol_name,
|
||||
exprstatestack * p_stack,
|
||||
|
|
@ -64,7 +71,10 @@ namespace xo {
|
|||
|
||||
std::unique_ptr<exprstate> self = p_stack->pop_exprstate();
|
||||
|
||||
//p_stack->top_exprstate().on_formal(result_, p_stack, p_emit_expr);
|
||||
rp<Variable> var = Variable::make(result_.name(),
|
||||
result_.td());
|
||||
|
||||
p_stack->top_exprstate().on_formal(var, p_stack, p_emit_expr);
|
||||
} else {
|
||||
exprstate::on_typedescr(td, p_stack, p_emit_expr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,9 @@ namespace xo {
|
|||
if (lmxs_type_ == lambdastatetype::lm_0) {
|
||||
this->lmxs_type_ = lambdastatetype::lm_1;
|
||||
p_stack->push_exprstate(expect_formal_arglist_xs::make());
|
||||
return;
|
||||
} else {
|
||||
exprstate::on_lambda_token(tk, p_stack, p_emit_expr);
|
||||
}
|
||||
|
||||
exprstate::on_lambda_token(tk,
|
||||
p_stack,
|
||||
p_emit_expr);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -41,12 +38,9 @@ namespace xo {
|
|||
this->lmxs_type_ = lambdastatetype::lm_2;
|
||||
this->argl_ = argl;
|
||||
p_stack->push_exprstate(expect_expr_xs::expect_rhs_expression());
|
||||
return;
|
||||
} else {
|
||||
exprstate::on_formal_arglist(argl, p_stack, p_emit_expr);
|
||||
}
|
||||
|
||||
exprstate::on_formal_arglist(argl,
|
||||
p_stack,
|
||||
p_emit_expr);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -57,10 +51,9 @@ namespace xo {
|
|||
if (lmxs_type_ == lambdastatetype::lm_2) {
|
||||
this->lmxs_type_ = lambdastatetype::lm_3;
|
||||
this->body_ = expr.promote();
|
||||
return;
|
||||
} else {
|
||||
exprstate::on_expr(expr, p_stack, p_emit_expr);
|
||||
}
|
||||
|
||||
exprstate::on_expr(expr, p_stack, p_emit_expr);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue