feat(frontends/lean): namespaces also define scope for variables

This commit is contained in:
Leonardo de Moura 2014-10-10 16:21:30 -07:00
parent 0641ee33ce
commit f0523a3465
3 changed files with 14 additions and 2 deletions

View file

@ -113,6 +113,7 @@ environment namespace_cmd(parser & p) {
name n = p.check_atomic_id_next("invalid namespace declaration, atomic identifier expected"); name n = p.check_atomic_id_next("invalid namespace declaration, atomic identifier expected");
if (is_root_namespace(n)) if (is_root_namespace(n))
throw parser_error(sstream() << "invalid namespace name, '" << n << "' is reserved", pos); throw parser_error(sstream() << "invalid namespace name, '" << n << "' is reserved", pos);
p.push_local_scope();
return push_scope(p.env(), p.ios(), scope_kind::Namespace, n); return push_scope(p.env(), p.ios(), scope_kind::Namespace, n);
} }
@ -152,8 +153,7 @@ static void redeclare_aliases(parser & p,
environment end_scoped_cmd(parser & p) { environment end_scoped_cmd(parser & p) {
list<pair<name, level>> level_entries = p.get_local_level_entries(); list<pair<name, level>> level_entries = p.get_local_level_entries();
list<pair<name, expr>> entries = p.get_local_entries(); list<pair<name, expr>> entries = p.get_local_entries();
if (in_section_or_context(p.env())) p.pop_local_scope();
p.pop_local_scope();
if (p.curr_is_identifier()) { if (p.curr_is_identifier()) {
name n = p.check_atomic_id_next("invalid end of scope, atomic identifier expected"); name n = p.check_atomic_id_next("invalid end of scope, atomic identifier expected");
environment env = pop_scope(p.env(), n); environment env = pop_scope(p.env(), n);

View file

@ -185,6 +185,7 @@ class parser {
friend environment section_cmd(parser & p); friend environment section_cmd(parser & p);
friend environment context_cmd(parser & p); friend environment context_cmd(parser & p);
friend environment namespace_cmd(parser & p);
friend environment end_scoped_cmd(parser & p); friend environment end_scoped_cmd(parser & p);
void push_local_scope(bool save_options = false); void push_local_scope(bool save_options = false);

View file

@ -0,0 +1,11 @@
namespace foo
variable A : Type
end foo
namespace bla
variable A : Type
end bla
namespace foo
variable A : Type
end foo