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
|
|
@ -11,34 +11,63 @@
|
|||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/**
|
||||
* ( name(1) : type(1) , ..., )
|
||||
* ^ ^ ^ ^ ^
|
||||
* | | | | |
|
||||
* | | | | argl_1b
|
||||
* | argl_1a | argla
|
||||
* argl_0 argl_1b
|
||||
*
|
||||
* argl_0 --on_leftparen_token()--> argl_1a
|
||||
* argl_1a --on_formal()--> argl_1b
|
||||
* argl_1b -+-on_comma_token()--> argl_1a
|
||||
* \-on_rightparen_token()--> (done)
|
||||
**/
|
||||
enum class formalarglstatetype {
|
||||
invalid = -1,
|
||||
|
||||
argl_0,
|
||||
argl_1,
|
||||
argl_1a,
|
||||
argl_1b,
|
||||
|
||||
n_formalarglstatetype,
|
||||
};
|
||||
|
||||
extern const char *
|
||||
formalarglstatetype_descr(formalarglstatetype x);
|
||||
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os, formalarglstatetype x) {
|
||||
os << formalarglstatetype_descr(x);
|
||||
return os;
|
||||
}
|
||||
|
||||
/** @class expect_formal_arglist
|
||||
* @brief parser state-machine for a formal parameter list
|
||||
*
|
||||
* ( name(1) : type(1), ..., )
|
||||
* ^
|
||||
* |
|
||||
* argl_0
|
||||
**/
|
||||
class expect_formal_arglist_xs : public exprstate {
|
||||
public:
|
||||
using Variable = xo::ast::Variable;
|
||||
|
||||
public:
|
||||
expect_formal_arglist_xs();
|
||||
|
||||
static std::unique_ptr<expect_formal_arglist_xs> make();
|
||||
|
||||
const std::vector<formal_arg> & argl() const { return argl_; }
|
||||
|
||||
virtual void on_leftparen_token(const token_type & tk,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr) override;
|
||||
virtual void on_formal(const rp<Variable> & formal,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr) override;
|
||||
virtual void on_comma_token(const token_type & tk,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr) override;
|
||||
virtual void on_rightparen_token(const token_type & tk,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr) override;
|
||||
virtual void print(std::ostream & os) const override;
|
||||
|
||||
private:
|
||||
/** parsing state-machine state **/
|
||||
|
|
@ -46,7 +75,7 @@ namespace xo {
|
|||
/** populate with (parmaeter-name, parameter-type) list
|
||||
* as they're encountered
|
||||
**/
|
||||
std::vector<formal_arg> argl_;
|
||||
std::vector<rp<Variable>> argl_;
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ namespace xo {
|
|||
* | formal_1
|
||||
* formal_0
|
||||
*
|
||||
* formal_0 --on_symbol()--> formal_1
|
||||
* formal_1 --on_colon_token()--> formal_2
|
||||
* formal_2 --on_typedescr()--> (done)
|
||||
**/
|
||||
enum class formalstatetype {
|
||||
invalid = -1,
|
||||
|
|
@ -44,6 +47,8 @@ namespace xo {
|
|||
public:
|
||||
expect_formal_xs() = default;
|
||||
|
||||
static std::unique_ptr<expect_formal_xs> make();
|
||||
|
||||
virtual void on_symbol(const std::string & symbol_name,
|
||||
exprstatestack * p_stack,
|
||||
rp<Expression> * p_emit_expr) override;
|
||||
|
|
@ -68,7 +73,7 @@ namespace xo {
|
|||
|
||||
private:
|
||||
/** parsing state-machine state **/
|
||||
formalstatetype formalxs_type_;
|
||||
formalstatetype formalxs_type_ = formalstatetype::formal_0;
|
||||
/** populate with {parameter-name, parameter-type}
|
||||
* as they're encountered
|
||||
**/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue