lean4-htt/src/Init
Joachim Breitner 06fb4bec52
feat: require indentation in commands, allow empty tactic sequences (#13229)
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>
2026-04-08 14:05:47 +00:00
..
Control feat: add rfl lemmas about ExceptCpsT.runK (#12912) 2026-03-26 08:13:20 +00:00
Data feat: require indentation in commands, allow empty tactic sequences (#13229) 2026-04-08 14:05:47 +00:00
Grind feat: require indentation in commands, allow empty tactic sequences (#13229) 2026-04-08 14:05:47 +00:00
GrindInstances feat: add PowIdentity typeclass for grind ring solver (#13086) 2026-04-08 09:05:12 +00:00
Internal feat: unfold and rewrap instances in inferInstanceAs and deriving 2026-03-22 13:25:46 +01:00
Meta feat: new, extensible do elaborator (#12459) 2026-02-21 17:17:29 +00:00
Omega fix: assorted fixes in the string library (#13201) 2026-03-31 06:28:20 +00:00
Sym feat: add control and arrow_telescope simproc DSL primitives (#13048) 2026-03-23 02:19:13 +00:00
System feat: Runtime.hold (#13270) 2026-04-07 08:44:35 +00:00
BinderNameHint.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
BinderPredicates.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
ByCases.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
CbvSimproc.lean feat: add cbv_simproc infrastructure for user-extensible cbv simplification procedures (#12597) 2026-03-10 10:59:13 +00:00
Classical.lean fix: address unused simp theorem warnings (#12829) 2026-03-06 23:12:03 +00:00
Coe.lean doc: fix typo in Init.Coe module docstring (#11567) 2025-12-10 08:48:55 +00:00
Control.lean chore: turn on new do elaborator in Core (#12656) 2026-03-09 12:38:33 +00:00
Conv.lean chore: disable cbv usage warning (#12986) 2026-03-19 14:12:04 +00:00
Core.lean feat: Thunk is inhabited (#12469) 2026-03-19 21:58:46 +00:00
Data.lean chore: more reorganization of strings (#10928) 2025-10-23 11:56:11 +00:00
Dynamic.lean fix: address unused simp theorem warnings (#12829) 2026-03-06 23:12:03 +00:00
Ext.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
GetElem.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Grind.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
GrindInstances.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Guard.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Hints.lean feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
Internal.lean
LawfulBEqTactics.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
MacroTrace.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Meta.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
MetaTypes.lean refactor: rename instance_reducible to implicit_reducible (#12567) 2026-02-18 22:19:16 +00:00
MethodSpecsSimp.lean
Notation.lean feat: add deprecated_arg attribute (#13011) 2026-03-30 10:20:44 +00:00
NotationExtra.lean feat: use unicode(...) in Init/Notation and elsewhere (#10384) 2026-03-09 22:17:32 +00:00
Omega.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Prelude.lean doc: fix typo in doc of Functor.mapConst (#13285) 2026-04-05 09:16:49 +00:00
PropLemmas.lean perf: remove simp annotations (#12977) 2026-03-19 07:58:32 +00:00
RCases.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
ShareCommon.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
SimpLemmas.lean feat: improves simpArrowTelescope simproc (#12153) 2026-01-25 22:29:38 +00:00
Simproc.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
SizeOf.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
SizeOfLemmas.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Sym.lean feat: add sym_simproc and sym_discharger DSL syntax categories (#13026) 2026-03-21 22:29:25 +00:00
Syntax.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
System.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Tactics.lean chore: revert @[mvcgen_witness_type] attribute (#12882) (#13111) 2026-03-25 14:38:59 +00:00
TacticsExtra.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Task.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Try.lean feat: add first_par combinator for try? with grind +locals (#11949) 2026-01-09 21:09:41 +00:00
Util.lean feat: new, extensible do elaborator (#12459) 2026-02-21 17:17:29 +00:00
WF.lean feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
WFComputable.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
WFExtrinsicFix.lean feat: add cbv annotations to iterators and strings (#12961) 2026-03-20 11:39:40 +00:00
WFTactics.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
While.lean feat: new, extensible do elaborator (#12459) 2026-02-21 17:17:29 +00:00