diff --git a/src/frontends/lean/parser.cpp b/src/frontends/lean/parser.cpp index ec1976322d..7a3c61f99b 100644 --- a/src/frontends/lean/parser.cpp +++ b/src/frontends/lean/parser.cpp @@ -2077,7 +2077,38 @@ expr parser::patexpr_to_expr_core(expr const & pat_or_expr) { return patexpr_to_expr_fn(*this)(pat_or_expr); } -optional parser::resolve_local(name const & id, pos_info const & p, list const & extra_locals, +static expr mk_constant(parser & p, const name & id, const levels & ls, const ast_data & id_data, ast_id levels_id) { + expr r = mk_constant(id, ls); + ast_id c = p.new_ast("const", id_data.m_start).push(id_data.m_id).push(levels_id).m_id; + p.finalize_ast(c, r); + return r; +} + +static expr mk_field_notation_ast(parser & p, const expr & s, const expr & r, ast_id field_id) { + ast_id sid = p.get_id(s); + ast_id ast = p.new_ast("field", p.ast_pos(sid)).push(sid).push(field_id).m_id; + p.finalize_ast(ast, r); + return r; +} + +static expr mk_field_notation_compact(parser & p, const expr & s, const pos_info & field_pos, const char * field) { + ast_id field_id = p.new_ast("ident", field_pos, field).m_id; + expr r = p.save_pos(mk_field_notation_compact(s, field), field_pos); + return mk_field_notation_ast(p, s, r, field_id); +} + +static expr mk_field_notation(parser & p, const expr & s, const pos_info & field_pos, const name & field) { + ast_id field_id = p.new_ast("ident", field_pos, field).m_id; + expr r = p.save_pos(mk_field_notation(s, field), field_pos); + return mk_field_notation_ast(p, s, r, field_id); +} + +static expr mk_field_notation(parser & p, const expr & s, const pos_info & field_pos, ast_id field_id, unsigned fidx) { + expr r = p.save_pos(mk_field_notation(s, fidx), field_pos); + return mk_field_notation_ast(p, s, r, field_id); +} + +optional parser::resolve_local(name const & id, ast_data & id_data, pos_info const & p, list const & extra_locals, bool allow_field_notation) { /* Remark: (auxiliary) local constants many not be atomic. Example: when elaborating @@ -2092,21 +2123,27 @@ optional parser::resolve_local(name const & id, pos_info const & p, list parser::resolve_local(name const & id, pos_info const & p, list const & extra_locals) { buffer lvl_buffer; @@ -2183,9 +2189,8 @@ expr parser::id_to_expr(name const & id, ast_data & id_data, return r; } - if (auto r = resolve_local(id, p, extra_locals, allow_field_notation)) { + if (auto r = resolve_local(id, id_data, p, extra_locals, allow_field_notation)) { check_no_levels(ls, p); - finalize_ast(id_data.m_id, *r); return *r; } diff --git a/src/frontends/lean/parser.h b/src/frontends/lean/parser.h index 41c359f38d..6a13069982 100644 --- a/src/frontends/lean/parser.h +++ b/src/frontends/lean/parser.h @@ -288,7 +288,7 @@ class parser : public abstract_parser, public parser_info { std::shared_ptr mk_snapshot(); - optional resolve_local(name const & id, pos_info const & p, list const & extra_locals, + optional resolve_local(name const & id, ast_data & id_data, pos_info const & p, list const & extra_locals, bool allow_field_notation = true); friend class module_parser;