feat(frontends/lean/builtin_cmds): allow many namespaces in the same 'using' command
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
d30f387e72
commit
b9d08ff28c
5 changed files with 48 additions and 48 deletions
|
@ -170,52 +170,56 @@ static void check_identifier(parser & p, environment const & env, name const & n
|
||||||
// using [class] id (id ...) (renaming id->id id->id) (hiding id ... id)
|
// using [class] id (id ...) (renaming id->id id->id) (hiding id ... id)
|
||||||
environment using_cmd(parser & p) {
|
environment using_cmd(parser & p) {
|
||||||
environment env = p.env();
|
environment env = p.env();
|
||||||
name cls = parse_class(p);
|
while (true) {
|
||||||
bool decls = cls.is_anonymous() || cls == g_decls || cls == g_declarations;
|
name cls = parse_class(p);
|
||||||
name ns = p.check_id_next("invalid 'using' command, identifier expected");
|
bool decls = cls.is_anonymous() || cls == g_decls || cls == g_declarations;
|
||||||
env = using_namespace(env, p.ios(), ns, cls);
|
name ns = p.check_id_next("invalid 'using' command, identifier expected");
|
||||||
if (decls) {
|
env = using_namespace(env, p.ios(), ns, cls);
|
||||||
// Remark: we currently to not allow renaming and hiding of universe levels
|
if (decls) {
|
||||||
buffer<name> exceptions;
|
// Remark: we currently to not allow renaming and hiding of universe levels
|
||||||
bool found_explicit = false;
|
buffer<name> exceptions;
|
||||||
while (p.curr_is_token(g_lparen)) {
|
bool found_explicit = false;
|
||||||
p.next();
|
while (p.curr_is_token(g_lparen)) {
|
||||||
if (p.curr_is_token_or_id(g_renaming)) {
|
|
||||||
p.next();
|
p.next();
|
||||||
while (p.curr_is_identifier()) {
|
if (p.curr_is_token_or_id(g_renaming)) {
|
||||||
name from_id = p.get_name_val();
|
|
||||||
p.next();
|
p.next();
|
||||||
p.check_token_next(g_arrow, "invalid 'using' command renaming, '->' expected");
|
while (p.curr_is_identifier()) {
|
||||||
name to_id = p.check_id_next("invalid 'using' command renaming, identifier expected");
|
name from_id = p.get_name_val();
|
||||||
check_identifier(p, env, ns, from_id);
|
p.next();
|
||||||
exceptions.push_back(from_id);
|
p.check_token_next(g_arrow, "invalid 'using' command renaming, '->' expected");
|
||||||
env = add_alias(env, to_id, mk_constant(ns+from_id));
|
name to_id = p.check_id_next("invalid 'using' command renaming, identifier expected");
|
||||||
}
|
check_identifier(p, env, ns, from_id);
|
||||||
} else if (p.curr_is_token_or_id(g_hiding)) {
|
exceptions.push_back(from_id);
|
||||||
p.next();
|
env = add_alias(env, to_id, mk_constant(ns+from_id));
|
||||||
while (p.curr_is_identifier()) {
|
}
|
||||||
name id = p.get_name_val();
|
} else if (p.curr_is_token_or_id(g_hiding)) {
|
||||||
p.next();
|
p.next();
|
||||||
check_identifier(p, env, ns, id);
|
while (p.curr_is_identifier()) {
|
||||||
exceptions.push_back(id);
|
name id = p.get_name_val();
|
||||||
|
p.next();
|
||||||
|
check_identifier(p, env, ns, id);
|
||||||
|
exceptions.push_back(id);
|
||||||
|
}
|
||||||
|
} else if (p.curr_is_identifier()) {
|
||||||
|
found_explicit = true;
|
||||||
|
while (p.curr_is_identifier()) {
|
||||||
|
name id = p.get_name_val();
|
||||||
|
p.next();
|
||||||
|
check_identifier(p, env, ns, id);
|
||||||
|
env = add_alias(env, id, mk_constant(ns+id));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw parser_error("invalid 'using' command option, identifier, 'hiding' or 'renaming' expected", p.pos());
|
||||||
}
|
}
|
||||||
} else if (p.curr_is_identifier()) {
|
if (found_explicit && !exceptions.empty())
|
||||||
found_explicit = true;
|
throw parser_error("invalid 'using' command option, mixing explicit and implicit 'using' options", p.pos());
|
||||||
while (p.curr_is_identifier()) {
|
p.check_token_next(g_rparen, "invalid 'using' command option, ')' expected");
|
||||||
name id = p.get_name_val();
|
|
||||||
p.next();
|
|
||||||
check_identifier(p, env, ns, id);
|
|
||||||
env = add_alias(env, id, mk_constant(ns+id));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw parser_error("invalid 'using' command option, identifier, 'hiding' or 'renaming' expected", p.pos());
|
|
||||||
}
|
}
|
||||||
if (found_explicit && !exceptions.empty())
|
if (!found_explicit)
|
||||||
throw parser_error("invalid 'using' command option, mixing explicit and implicit 'using' options", p.pos());
|
env = add_aliases(env, ns, name(), exceptions.size(), exceptions.data());
|
||||||
p.check_token_next(g_rparen, "invalid 'using' command option, ')' expected");
|
|
||||||
}
|
}
|
||||||
if (!found_explicit)
|
if (!p.curr_is_token(g_lbracket) && !p.curr_is_identifier())
|
||||||
env = add_aliases(env, ns, name(), exceptions.size(), exceptions.data());
|
break;
|
||||||
}
|
}
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import standard
|
import standard
|
||||||
using num
|
using num pair
|
||||||
using pair
|
|
||||||
|
|
||||||
definition H : inhabited (Bool × num × (num → num)) := _
|
definition H : inhabited (Bool × num × (num → num)) := _
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import standard
|
import standard
|
||||||
using num
|
using num pair
|
||||||
using pair
|
|
||||||
|
|
||||||
theorem H {A B : Type} (H1 : inhabited A) : inhabited (Bool × A × (B → num))
|
theorem H {A B : Type} (H1 : inhabited A) : inhabited (Bool × A × (B → num))
|
||||||
:= _
|
:= _
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import standard
|
import standard
|
||||||
using num
|
using num pair
|
||||||
using pair
|
|
||||||
|
|
||||||
section
|
section
|
||||||
parameter {A : Type}
|
parameter {A : Type}
|
||||||
|
|
|
@ -25,8 +25,7 @@ namespace nat
|
||||||
end
|
end
|
||||||
|
|
||||||
section
|
section
|
||||||
using algebra
|
using algebra nat
|
||||||
using nat
|
|
||||||
variables a b c : nat
|
variables a b c : nat
|
||||||
check a * b * c
|
check a * b * c
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue