From d0fac50cfd3918eb9d60395dfbdacef23b1fe32b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 9 Sep 2020 15:15:09 -0700 Subject: [PATCH] Add locations to patterns. --- code/compiler/13/ast.hpp | 11 +++++++---- code/compiler/13/parser.y | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/code/compiler/13/ast.hpp b/code/compiler/13/ast.hpp index 162f1e0..5eeabd2 100644 --- a/code/compiler/13/ast.hpp +++ b/code/compiler/13/ast.hpp @@ -29,6 +29,9 @@ struct ast { using ast_ptr = std::unique_ptr; 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& into) const; @@ -183,8 +186,8 @@ struct pattern_constr : public pattern { std::string constr; std::vector params; - pattern_constr(std::string c, std::vector p) - : constr(std::move(c)), params(std::move(p)) {} + pattern_constr(std::string c, std::vector 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& into) const; diff --git a/code/compiler/13/parser.y b/code/compiler/13/parser.y index 93fabce..1bf8c48 100644 --- a/code/compiler/13/parser.y +++ b/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