fix(frontends/lean/builtin_cmds): allow token and metaclass to have the same name

This commit is contained in:
Leonardo de Moura 2015-12-28 09:57:45 -08:00
parent 89a5d00714
commit 96bec8b4f9
2 changed files with 30 additions and 14 deletions

View file

@ -204,7 +204,7 @@ static bool is_next_metaclass_tk(parser const & p) {
return p.curr_is_token(get_lbracket_tk()) || p.curr_is_token(get_unfold_hints_bracket_tk()); return p.curr_is_token(get_lbracket_tk()) || p.curr_is_token(get_unfold_hints_bracket_tk());
} }
static name parse_metaclass(parser & p) { static optional<name> parse_metaclass(parser & p) {
if (p.curr_is_token(get_lbracket_tk())) { if (p.curr_is_token(get_lbracket_tk())) {
p.next(); p.next();
auto pos = p.pos(); auto pos = p.pos();
@ -223,14 +223,22 @@ static name parse_metaclass(parser & p) {
p.check_token_next(get_rbracket_tk(), "invalid 'open' command, ']' expected"); p.check_token_next(get_rbracket_tk(), "invalid 'open' command, ']' expected");
if (!is_metaclass(n) && n != get_decls_tk() && n != get_declarations_tk()) if (!is_metaclass(n) && n != get_decls_tk() && n != get_declarations_tk())
throw parser_error(sstream() << "invalid metaclass name '[" << n << "]'", pos); throw parser_error(sstream() << "invalid metaclass name '[" << n << "]'", pos);
return n; return optional<name>(n);
} else if (p.curr_is_token(get_unfold_hints_bracket_tk())) { } else if (p.curr() == scanner::token_kind::CommandKeyword) {
name v = p.get_token_info().value();
if (v.is_atomic() && v.is_string() && v.size() > 2 && v.get_string()[0] == '[' && v.get_string()[v.size()-1] == ']') {
auto pos = p.pos();
p.next(); p.next();
return get_unfold_hints_tk(); std::string s(v.get_string() + 1);
} else { s.pop_back();
return name(); name n(s);
if (!is_metaclass(n) && n != get_decls_tk() && n != get_declarations_tk())
throw parser_error(sstream() << "invalid metaclass name '[" << n << "]'", pos);
return optional<name>(n);
} }
} }
return optional<name>();
}
static void parse_metaclasses(parser & p, buffer<name> & r) { static void parse_metaclasses(parser & p, buffer<name> & r) {
if (p.curr_is_token(get_sub_tk())) { if (p.curr_is_token(get_sub_tk())) {
@ -238,16 +246,23 @@ static void parse_metaclasses(parser & p, buffer<name> & r) {
buffer<name> tmp; buffer<name> tmp;
get_metaclasses(tmp); get_metaclasses(tmp);
tmp.push_back(get_decls_tk()); tmp.push_back(get_decls_tk());
while (is_next_metaclass_tk(p)) { while (true) {
name m = parse_metaclass(p); if (optional<name> m = parse_metaclass(p)) {
tmp.erase_elem(m); tmp.erase_elem(*m);
if (m == get_declarations_tk()) if (*m == get_declarations_tk())
tmp.erase_elem(get_decls_tk()); tmp.erase_elem(get_decls_tk());
} else {
break;
}
} }
r.append(tmp); r.append(tmp);
} else { } else {
while (is_next_metaclass_tk(p)) { while (true) {
r.push_back(parse_metaclass(p)); if (optional<name> m = parse_metaclass(p)) {
r.push_back(*m);
} else {
break;
}
} }
} }
} }

View file

@ -0,0 +1 @@
open - [forward] nat