Add locations to patterns.

This commit is contained in:
Danila Fedorin 2020-09-09 15:15:09 -07:00
parent dd4aa6fb9d
commit d0fac50cfd
2 changed files with 9 additions and 6 deletions

View File

@ -29,6 +29,9 @@ struct ast {
using ast_ptr = std::unique_ptr<ast>;
struct pattern {
yy::location loc;
pattern(yy::location l) : loc(std::move(l)) {}
virtual ~pattern() = default;
virtual void print(std::ostream& to) const = 0;
@ -171,8 +174,8 @@ struct ast_lambda : public ast {
struct pattern_var : public pattern {
std::string var;
pattern_var(std::string v)
: var(std::move(v)) {}
pattern_var(std::string v, yy::location l = yy::location())
: pattern(std::move(l)), var(std::move(v)) {}
void print(std::ostream &to) const;
void find_variables(std::set<std::string>& into) const;
@ -183,8 +186,8 @@ struct pattern_constr : public pattern {
std::string constr;
std::vector<std::string> params;
pattern_constr(std::string c, std::vector<std::string> p)
: constr(std::move(c)), params(std::move(p)) {}
pattern_constr(std::string c, std::vector<std::string> p, yy::location l = yy::location())
: pattern(std::move(l)), constr(std::move(c)), params(std::move(p)) {}
void print(std::ostream &to) const;
void find_variables(std::set<std::string>& into) const;

View File

@ -136,9 +136,9 @@ branch
;
pattern
: LID { $$ = pattern_ptr(new pattern_var(std::move($1))); }
: LID { $$ = pattern_ptr(new pattern_var(std::move($1), @$)); }
| UID lowercaseParams
{ $$ = pattern_ptr(new pattern_constr(std::move($1), std::move($2))); }
{ $$ = pattern_ptr(new pattern_constr(std::move($1), std::move($2), @$)); }
;
data