Add locations to patterns.
This commit is contained in:
		
							parent
							
								
									dd4aa6fb9d
								
							
						
					
					
						commit
						d0fac50cfd
					
				| @ -29,6 +29,9 @@ struct ast { | |||||||
| using ast_ptr = std::unique_ptr<ast>; | using ast_ptr = std::unique_ptr<ast>; | ||||||
| 
 | 
 | ||||||
| struct pattern { | struct pattern { | ||||||
|  |     yy::location loc; | ||||||
|  | 
 | ||||||
|  |     pattern(yy::location l) : loc(std::move(l)) {} | ||||||
|     virtual ~pattern() = default; |     virtual ~pattern() = default; | ||||||
| 
 | 
 | ||||||
|     virtual void print(std::ostream& to) const = 0; |     virtual void print(std::ostream& to) const = 0; | ||||||
| @ -171,8 +174,8 @@ struct ast_lambda : public ast { | |||||||
| struct pattern_var : public pattern { | struct pattern_var : public pattern { | ||||||
|     std::string var; |     std::string var; | ||||||
| 
 | 
 | ||||||
|     pattern_var(std::string v) |     pattern_var(std::string v, yy::location l = yy::location()) | ||||||
|         : var(std::move(v)) {} |         : pattern(std::move(l)), var(std::move(v)) {} | ||||||
| 
 | 
 | ||||||
|     void print(std::ostream &to) const; |     void print(std::ostream &to) const; | ||||||
|     void find_variables(std::set<std::string>& into) const; |     void find_variables(std::set<std::string>& into) const; | ||||||
| @ -183,8 +186,8 @@ struct pattern_constr : public pattern { | |||||||
|     std::string constr; |     std::string constr; | ||||||
|     std::vector<std::string> params; |     std::vector<std::string> params; | ||||||
| 
 | 
 | ||||||
|     pattern_constr(std::string c, std::vector<std::string> p) |     pattern_constr(std::string c, std::vector<std::string> p, yy::location l = yy::location()) | ||||||
|         : constr(std::move(c)), params(std::move(p)) {} |         : pattern(std::move(l)), constr(std::move(c)), params(std::move(p)) {} | ||||||
| 
 | 
 | ||||||
|     void print(std::ostream &to) const; |     void print(std::ostream &to) const; | ||||||
|     void find_variables(std::set<std::string>& into) const; |     void find_variables(std::set<std::string>& into) const; | ||||||
|  | |||||||
| @ -136,9 +136,9 @@ branch | |||||||
|     ; |     ; | ||||||
| 
 | 
 | ||||||
| pattern | pattern | ||||||
|     : LID { $$ = pattern_ptr(new pattern_var(std::move($1))); } |     : LID { $$ = pattern_ptr(new pattern_var(std::move($1), @$)); } | ||||||
|     | UID lowercaseParams |     | 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 | data | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user