diff --git a/src/frontends/lean/parser_expr.cpp b/src/frontends/lean/parser_expr.cpp index 65e848df8..9a7fcfa06 100644 --- a/src/frontends/lean/parser_expr.cpp +++ b/src/frontends/lean/parser_expr.cpp @@ -146,26 +146,23 @@ expr parser_imp::parse_prefix(operator_info const & op) { } /** \brief Parse a user defined postfix operator. */ -expr parser_imp::parse_postfix(expr const & left, operator_info const & op) { - return mk_application(op, pos(), left); +expr parser_imp::parse_postfix(expr const & left, operator_info const & op, pos_info const & op_pos) { + return mk_application(op, op_pos, left); } /** \brief Parse a user defined infix operator. */ -expr parser_imp::parse_infix(expr const & left, operator_info const & op) { - auto p = pos(); - return mk_application(op, p, {left, parse_expr(op.get_precedence()+1)}); +expr parser_imp::parse_infix(expr const & left, operator_info const & op, pos_info const & op_pos) { + return mk_application(op, op_pos, {left, parse_expr(op.get_precedence()+1)}); } /** \brief Parse a user defined infix-left operator. */ -expr parser_imp::parse_infixl(expr const & left, operator_info const & op) { - auto p = pos(); - return mk_application(op, p, {left, parse_expr(op.get_precedence())}); +expr parser_imp::parse_infixl(expr const & left, operator_info const & op, pos_info const & op_pos) { + return mk_application(op, op_pos, {left, parse_expr(op.get_precedence())}); } /** \brief Parse a user defined infix-right operator. */ -expr parser_imp::parse_infixr(expr const & left, operator_info const & op) { - auto p = pos(); - return mk_application(op, p, {left, parse_expr(op.get_precedence()-1)}); +expr parser_imp::parse_infixr(expr const & left, operator_info const & op, pos_info const & op_pos) { + return mk_application(op, op_pos, {left, parse_expr(op.get_precedence()-1)}); } /** @@ -204,8 +201,7 @@ expr parser_imp::parse_mixfixl(operator_info const & op) { } /** \brief Parse user defined mixfixr operator. It has the form: _ ID ... _ ID */ -expr parser_imp::parse_mixfixr(expr const & left, operator_info const & op) { - auto p = pos(); +expr parser_imp::parse_mixfixr(expr const & left, operator_info const & op, pos_info const & op_pos) { buffer args; args.push_back(left); auto parts = op.get_op_name_parts(); @@ -216,17 +212,16 @@ expr parser_imp::parse_mixfixr(expr const & left, operator_info const & op) { check_op_part(*it); ++it; } - return mk_application(op, p, args); + return mk_application(op, op_pos, args); } /** \brief Parse user defined mixfixr operator. It has the form: _ ID ... _ ID _ */ -expr parser_imp::parse_mixfixo(expr const & left, operator_info const & op) { - auto p = pos(); +expr parser_imp::parse_mixfixo(expr const & left, operator_info const & op, pos_info const & op_pos) { buffer args; args.push_back(left); args.push_back(parse_expr(op.get_precedence())); parse_mixfix_args(op.get_op_name_parts(), op.get_precedence(), args); - return mk_application(op, p, args); + return mk_application(op, op_pos, args); } /** \brief Parse user defined mixfixc operator. It has the form: ID _ ID ... _ ID */ @@ -553,12 +548,12 @@ expr parser_imp::parse_led_id(expr const & left) { operator_info op = find_led(m_env, id); if (op) { switch (op.get_fixity()) { - case fixity::Infix: return parse_infix(left, op); - case fixity::Infixl: return parse_infixl(left, op); - case fixity::Infixr: return parse_infixr(left, op); - case fixity::Mixfixr: return parse_mixfixr(left, op); - case fixity::Mixfixo: return parse_mixfixo(left, op); - case fixity::Postfix: return parse_postfix(left, op); + case fixity::Infix: return parse_infix(left, op, p); + case fixity::Infixl: return parse_infixl(left, op, p); + case fixity::Infixr: return parse_infixr(left, op, p); + case fixity::Mixfixr: return parse_mixfixr(left, op, p); + case fixity::Mixfixo: return parse_mixfixo(left, op, p); + case fixity::Postfix: return parse_postfix(left, op, p); default: lean_unreachable(); // LCOV_EXCL_LINE } } else { diff --git a/src/frontends/lean/parser_imp.h b/src/frontends/lean/parser_imp.h index 367c8bc85..f2be60a32 100644 --- a/src/frontends/lean/parser_imp.h +++ b/src/frontends/lean/parser_imp.h @@ -264,15 +264,15 @@ private: expr mk_application(operator_info const & op, pos_info const & pos, expr const & arg); expr mk_application(operator_info const & op, pos_info const & pos, buffer const & args); expr parse_prefix(operator_info const & op); - expr parse_postfix(expr const & left, operator_info const & op); - expr parse_infix(expr const & left, operator_info const & op); - expr parse_infixl(expr const & left, operator_info const & op); - expr parse_infixr(expr const & left, operator_info const & op); + expr parse_postfix(expr const & left, operator_info const & op, pos_info const & op_pos); + expr parse_infix(expr const & left, operator_info const & op, pos_info const & op_pos); + expr parse_infixl(expr const & left, operator_info const & op, pos_info const & op_pos); + expr parse_infixr(expr const & left, operator_info const & op, pos_info const & op_pos); void check_op_part(name const & op_part); void parse_mixfix_args(list const & ops, unsigned prec, buffer & args); expr parse_mixfixl(operator_info const & op); - expr parse_mixfixr(expr const & left, operator_info const & op); - expr parse_mixfixo(expr const & left, operator_info const & op); + expr parse_mixfixr(expr const & left, operator_info const & op, pos_info const & op_pos); + expr parse_mixfixo(expr const & left, operator_info const & op, pos_info const & op_pos); expr parse_mixfixc(operator_info const & op); void propagate_position(expr const & e, pos_info p); bool is_curr_begin_expr() const; diff --git a/tests/lean/ex2.lean.expected.out b/tests/lean/ex2.lean.expected.out index 0aaf996b1..6ff1cac5b 100644 --- a/tests/lean/ex2.lean.expected.out +++ b/tests/lean/ex2.lean.expected.out @@ -10,7 +10,7 @@ Error (line: 8, pos: 0) invalid object declaration, environment already has an o Assumed: b and a b Assumed: A -Error (line: 12, pos: 11) type mismatch at application +Error (line: 12, pos: 8) type mismatch at application and a A Function type: Bool -> Bool -> Bool diff --git a/tests/lean/ex3.lean.expected.out b/tests/lean/ex3.lean.expected.out index 1dd8800cd..8ca06a32b 100644 --- a/tests/lean/ex3.lean.expected.out +++ b/tests/lean/ex3.lean.expected.out @@ -16,7 +16,7 @@ Failed to solve Set: lean::pp::implicit Failed to solve ⊢ Bool ≺ T - (line: 9: pos: 15) Type of argument 2 must be convertible to the expected type in the application of + (line: 9: pos: 11) Type of argument 2 must be convertible to the expected type in the application of @myeq2 with arguments: T diff --git a/tests/lean/overload2.lean.expected.out b/tests/lean/overload2.lean.expected.out index 9d1c2e4c0..e901dbf00 100644 --- a/tests/lean/overload2.lean.expected.out +++ b/tests/lean/overload2.lean.expected.out @@ -4,25 +4,25 @@ Imported 'Real' Failed to solve ⊢ (?M::0 ≈ Nat::add) ⊕ (?M::0 ≈ Int::add) ⊕ (?M::0 ≈ Real::add) - (line: 3: pos: 10) Overloading at + (line: 3: pos: 8) Overloading at (Real::add | Int::add | Nat::add) 1 ⊤ Failed to solve ⊢ Bool ≺ ℕ - (line: 3: pos: 10) Type of argument 2 must be convertible to the expected type in the application of + (line: 3: pos: 8) Type of argument 2 must be convertible to the expected type in the application of Nat::add with arguments: 1 ⊤ Failed to solve ⊢ Bool ≺ ℤ - (line: 3: pos: 10) Type of argument 2 must be convertible to the expected type in the application of + (line: 3: pos: 8) Type of argument 2 must be convertible to the expected type in the application of Int::add with arguments: 1 ⊤ Failed to solve ⊢ Bool ≺ ℝ - (line: 3: pos: 10) Type of argument 2 must be convertible to the expected type in the application of + (line: 3: pos: 8) Type of argument 2 must be convertible to the expected type in the application of Real::add with arguments: 1