Browse Source

Add locations to patterns.

search
Danila Fedorin 1 year ago
parent
commit
d0fac50cfd
  1. 11
      code/compiler/13/ast.hpp
  2. 4
      code/compiler/13/parser.y

11
code/compiler/13/ast.hpp

@ -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;

4
code/compiler/13/parser.y

@ -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

Loading…
Cancel
Save