This PR wraps the top-level command parser with `withPosition` to enforce indentation in `by` blocks, combined with an empty-by fallback for better error messages. This subsumes #3215 (which introduced `withPosition commandParser` but without the empty-by fallback). It is also related to #9524, which explores elaboration with empty tactic sequences — this PR reuses that idea for the empty-by fallback, so that a `by` not followed by an indented tactic produces an elaboration error (unsolved goals) rather than a parse error. **Changes:** - `topLevelCommandParserFn` now uses `(withPosition commandParser).fn`, setting the saved position at the start of each top-level command - `tacticSeqIndentGt` gains an empty tactic sequence fallback (`pushNone`) so that missing indentation produces an elaboration error (unsolved goals) instead of a parse error - `isEmptyBy` in `goalsAt?` removed: with strict `by` indentation, empty `by` blocks parse successfully via `pushNone` (producing empty nodes) rather than producing `.missing` syntax, making the `isEmptyBy` check dead code. The `isEmpty` helper in `isSyntheticTacticCompletion` continues to work correctly because it handles both `.missing` and empty nodes from `pushNone` (via the vacuously-true `args.all isEmpty` on `#[]`) - Test files updated to indent `by` blocks and expression continuations that were previously at column 0 **Behavior:** - Top-level `by` blocks now require indentation (column > 0 for commands at column 0) - Commands indented inside `section` require proofs to be indented past the command's column - `#guard_msgs in example : True := by` works because tactic indentation is checked against the outermost command's column - Expression continuations (not just `by`) must also be indented past the command, which is slightly more strict but more consistent - `have : True := by` followed by a dedent now correctly puts `this` in scope in the outer tactic block (the `have` is structurally complete with an unsolved-goal error, rather than a parse error) **Code changes observed in practice (lean4 test suite + Mathlib):** - `by` blocks: top-level `theorem ... := by` / `decreasing_by` followed by tactics at column 0 must be indented - `variable` continuations: `variable {A : Type*} [Foo A]\n{B : Type*}` where the second line starts at column 0 must be indented (most common category in Mathlib) - Expression continuations: `def f : T :=\nexpr` or `#synth Foo\n[args]` where the body/arguments start at column 0 - Structure literals: `.symm\n{ toFun := ...` where the struct literal starts at column 0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
160 lines
3.6 KiB
Text
160 lines
3.6 KiB
Text
example : α → α := by
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
intro a
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
--v $/lean/plainGoal
|
||
focus
|
||
apply a
|
||
|
||
example : α → α := by
|
||
--^ $/lean/plainGoal
|
||
|
||
example : 0 + n = n := by
|
||
induction n with
|
||
| zero => simp; simp
|
||
--^ $/lean/plainGoal
|
||
| succ
|
||
--^ $/lean/plainGoal
|
||
|
||
example : α → α := by
|
||
intro a; apply a
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
|
||
example (h1 : n = m) (h2 : m = 0) : 0 = n := by
|
||
rw [h1, h2]
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
|
||
example : 0 + n = n := by
|
||
induction n
|
||
focus
|
||
--^ $/lean/plainGoal
|
||
rfl
|
||
-- TODO: goal state after dedent
|
||
|
||
example : 0 + n = n := by
|
||
induction n
|
||
--^ $/lean/plainGoal
|
||
|
||
example : 0 + n = n := by
|
||
cases n
|
||
--^ $/lean/plainGoal
|
||
|
||
example : ∀ a b : Nat, a = b := by
|
||
intro a b
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
|
||
example : α → α := (by
|
||
--^ $/lean/plainGoal
|
||
|
||
example (p : α → Prop) (a b : α) [DecidablePred p] (h : ∀ {p} [DecidablePred p], p a → p b) : p b := by
|
||
apply h _
|
||
--^ $/lean/plainGoal
|
||
-- should not display solved goal `⊢ DecidablePred p`
|
||
|
||
example : True ∧ False := by
|
||
constructor
|
||
{ constructor }
|
||
--^ $/lean/plainGoal
|
||
{ }
|
||
--^ $/lean/plainGoal
|
||
|
||
example : True ∧ False := by
|
||
constructor
|
||
· constructor
|
||
--^ $/lean/plainGoal
|
||
·
|
||
--^ $/lean/plainGoal
|
||
|
||
theorem left_distrib (t a b : Nat) : t * (a + b) = t * a + t * b := by
|
||
induction b
|
||
next => simp
|
||
next =>
|
||
rw [Nat.add_succ]
|
||
repeat (rw [Nat.mul_succ])
|
||
--^ $/lean/plainGoal
|
||
|
||
example (as bs cs : List α) : (as ++ bs) ++ cs = as ++ (bs ++ cs) := by
|
||
induction as <;> skip <;> (try rename_i h; simp[h]) <;> rfl
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
|
||
example : True := (by exact True.intro)
|
||
--^ $/lean/plainGoal
|
||
|
||
example : True := (by exact True.intro )
|
||
--^ $/lean/plainGoal
|
||
|
||
example : True ∧ False := by
|
||
· constructor; constructor
|
||
--^ $/lean/plainGoal
|
||
|
||
example : True = True := by
|
||
conv =>
|
||
--^ $/lean/plainGoal
|
||
whnf
|
||
--^ $/lean/plainGoal
|
||
--
|
||
--^ $/lean/plainGoal
|
||
|
||
example : True := by
|
||
have : True := by
|
||
-- type here
|
||
--^ $/lean/plainGoal
|
||
-- `this` is in scope: empty `by` is parsed successfully
|
||
--^ $/lean/plainGoal
|
||
|
||
example : True := by
|
||
have : True := by
|
||
-- type here
|
||
--^ $/lean/plainGoal
|
||
apply this
|
||
--^ $/lean/plainGoal
|
||
|
||
example : False := by
|
||
-- EOF test
|
||
--^ $/lean/plainGoal
|
||
|
||
example (hp : p) (hq : q) : p ∧ q := by
|
||
suffices q ∧ p by
|
||
--^ $/lean/plainGoal
|
||
|
||
example (hp : p) (hq : q) : p ∧ q :=
|
||
show id (p ∧ q) by
|
||
--^ $/lean/plainGoal
|
||
|
||
example : True ∧ False := by
|
||
constructor
|
||
· --
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
|
||
section
|
||
|
||
example : True := by induction 1 with
|
||
--^ $/lean/plainGoal
|
||
|
||
example : True := by induction 1 with |
|
||
--^ $/lean/plainGoal
|
||
|
||
example : True := by induction 1 with done
|
||
--^ $/lean/plainGoal
|
||
|
||
end
|
||
|
||
section
|
||
|
||
example (f : Nat → Nat) (n : Nat) (hf : ∀ x, f x = x + 0 + 1) : f n + 0 = 1 + n := by
|
||
simpa [Nat.add_zero, Nat.add_comm] using hf n
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
--^ $/lean/plainGoal
|
||
|
||
end
|