Skip to content

Commit 2561612

Browse files
author
Sebastian Graf
committed
feat: subsections for obligations_by
1 parent dc5d6fe commit 2561612

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/Lean/Elab/Obligations.lean

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def mkObligations {m} [Monad m] [MonadError m] (stx : TSyntax ``Parser.Term.obli
2424
return { ref := stx, tactic := ⟨.missing⟩ }
2525
if let some ob := stx.raw.getOptional? then
2626
match ob with
27-
| `(Parser.Term.obligationsBy| obligations_by $tactic) => do
27+
| `(Parser.Term.obligationsBy| obligations_by $tactic) =>
2828
return { ref := stx, tactic }
29-
| _ => throwErrorAt stx s!"Unexpected obligationsBy syntax: {stx} of kind {stx.raw.getKind}"
29+
| `(Parser.Term.obligationsBy| obligations_by) =>
30+
return { ref := stx, tactic := ⟨.missing⟩ }
31+
| `(Parser.Term.obligationsBy| $_) =>
32+
throwErrorAt stx "`obligations_by` does not currently support any named sub-sections `| sectionName => ...`"
3033
else return .none

src/Lean/Parser/Term.lean

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,12 +810,19 @@ Termination hints are `termination_by` and `decreasing_by`, in that order.
810810
end Termination
811811
namespace Term
812812

813+
/--
814+
A named subsection of `obligations_by`. In the future, sections such as `decreasing_by` might become
815+
syntactic sugar for an `obligations_by` subsection `| decreasing => ...`.
816+
-/
817+
def obligationsBySubSection := leading_parser
818+
ppLine >> "| " >> ident >> darrow >> Tactic.tacticSeq
819+
813820
/--
814821
`obligations_by` opens a tactic block to discharge proof obligations introduced by
815822
use of `?hole`s in the definition body.
816823
-/
817824
@[builtin_doc] def obligationsBy := leading_parser
818-
ppDedent ppLine >> "obligations_by " >> Tactic.tacticSeqIndentGt
825+
ppDedent ppLine >> withPosition ("obligations_by " >> optional Tactic.tacticSeqIndentGt >> manyIndent obligationsBySubSection)
819826

820827
/-- `letRecDecl` matches the body of a let-rec declaration: a doc comment, attributes, and then
821828
a let declaration without the `let` keyword, such as `/-- foo -/ @[simp] bar := 1`. -/

tests/lean/obligations.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,13 @@ def obligation_in_rec_let_and_def (i : Nat) (xs : Array Nat) (h : i < xs.size) :
6262
f i + xs[i]'?hole₂
6363
obligations_by
6464
case hole₂ => exact h
65+
66+
/--
67+
error: `obligations_by` does not currently support any named sub-sections `| sectionName => ...`
68+
-/
69+
#guard_msgs in
70+
def obligation_decreasing_does_not_exist (i : Nat) (xs : Array Nat) (h : i < xs.size) : Nat :=
71+
xs[i]'?hole
72+
obligations_by
73+
case hole => exact h
74+
| decreasing => skip

0 commit comments

Comments
 (0)