lean4-htt/src/Init/Data
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
..
Array feat: add List.prod, Array.prod, and Vector.prod (#13200) 2026-04-08 04:01:49 +00:00
BitVec perf: fixup BitVec.cpop termination proof performance (#12764) 2026-03-02 16:53:45 +00:00
ByteArray perf: use memcmp for ByteArray equality (#13235) 2026-04-01 15:30:03 +00:00
Char feat: Char.toNat_mk (#13090) 2026-03-24 07:16:29 +00:00
Dyadic chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Fin refactor: replace grind canonicalizer with type-directed normalizer (#13166) 2026-03-28 02:43:22 +00:00
FloatArray chore: do not use internal append in ToString instances for basic types (#12885) 2026-03-11 15:25:54 +00:00
Format feat: use StateT.run instead of function application (#5121) 2026-03-03 03:12:26 +00:00
Int feat: verification of String.toInt? (#13003) 2026-03-20 10:31:51 +00:00
Iterators chore: fix spelling errors (#13274) 2026-04-04 07:34:34 +00:00
List feat: add List.prod, Array.prod, and Vector.prod (#13200) 2026-04-08 04:01:49 +00:00
Nat fix: suggest (rfl) not id rfl in linter (#13319) 2026-04-08 08:21:23 +00:00
Option chore: turn on new do elaborator in Core (#12656) 2026-03-09 12:38:33 +00:00
Ord fix: assorted fixes in the string library (#13201) 2026-03-31 06:28:20 +00:00
Order feat: verification of String.dropWhile and String.takeWhile (#13155) 2026-04-03 14:02:21 +00:00
Range feat: require indentation in commands, allow empty tactic sequences (#13229) 2026-04-08 14:05:47 +00:00
Rat chore: do not use internal append in ToString instances for basic types (#12885) 2026-03-11 15:25:54 +00:00
SInt chore: do not use internal append in ToString instances for basic types (#12885) 2026-03-11 15:25:54 +00:00
Slice feat: add further cbv annotations (#13135) 2026-03-26 14:55:40 +00:00
String chore: fix typo in isInvalidContinuationByte (#13275) 2026-04-07 09:01:19 +00:00
Subtype chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Sum doc: correct typos in documentation and comments (#11465) 2025-12-02 06:38:05 +00:00
ToString feat: verification of String.toInt? (#13003) 2026-03-20 10:31:51 +00:00
UInt feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
Vector feat: add List.prod, Array.prod, and Vector.prod (#13200) 2026-04-08 04:01:49 +00:00
AC.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Array.lean feat: Array.mergeSort (#12385) 2026-03-06 13:18:13 +00:00
BEq.lean feat: EquivBEq and LawfulHashable for String.Slice (#13058) 2026-03-23 11:10:00 +00:00
BitVec.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Bool.lean feat: add simp lemmas for kernel-friendly functions (#12950) 2026-03-18 07:22:06 +00:00
ByteArray.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Cast.lean feat: make private the default in module (#9044) 2025-06-28 16:30:53 +00:00
Char.lean feat: Fin and Char ranges (#12058) 2026-01-22 07:44:55 +00:00
Dyadic.lean feat: (approximate) inverses of dyadic rationals (#10194) 2025-09-02 03:43:53 +00:00
Fin.lean feat: Fin and Char ranges (#12058) 2026-01-22 07:44:55 +00:00
Float.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Float32.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
FloatArray.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Format.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Function.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Hashable.lean feat: order instances for string positions (#12641) 2026-02-23 08:20:52 +00:00
Int.lean feat: verification of String.toInt? (#13003) 2026-03-20 10:31:51 +00:00
Iterators.lean feat: List slices (#11019) 2025-11-14 11:33:25 +00:00
LawfulHashable.lean style: fix typos in Init/ and Std/ docstrings (#11864) 2026-01-09 07:24:07 +00:00
List.lean feat: upstream List.splitOn(P) (#12702) 2026-02-26 13:45:34 +00:00
Nat.lean feat: verification of Nat.toDigits, Nat.repr and ToString Nat (#12445) 2026-02-18 12:33:01 +00:00
NeZero.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
OfScientific.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Option.lean feat: Fin and Char ranges (#12058) 2026-01-22 07:44:55 +00:00
Ord.lean perf: shorten critical build path around String.Basic (#10614) 2025-09-29 19:45:21 +00:00
Order.lean feat: projected minima and maxima (#11938) 2026-01-31 16:16:32 +00:00
PLift.lean feat: make private the default in module (#9044) 2025-06-28 16:30:53 +00:00
Prod.lean chore: grind attributes for Prod (#11085) 2025-11-05 20:52:28 +00:00
Queue.lean feat: make private the default in module (#9044) 2025-06-28 16:30:53 +00:00
Random.lean chore: reorganize Init imports around strings (#10289) 2025-09-07 17:09:14 +00:00
Range.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
RArray.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Rat.lean feat: upstream definition of Rat from Batteries (#9957) 2025-08-19 01:58:24 +00:00
Repr.lean feat: verification of String.toInt? (#13003) 2026-03-20 10:31:51 +00:00
SInt.lean feat: make private the default in module (#9044) 2025-06-28 16:30:53 +00:00
Slice.lean feat: List slices (#11019) 2025-11-14 11:33:25 +00:00
Stream.lean refactor: move Std.Range to Std.Legacy.Range (#11438) 2025-12-18 02:07:33 +00:00
String.lean feat: order instances for string positions (#12641) 2026-02-23 08:20:52 +00:00
Subtype.lean feat: high-level order typeclasses (#9729) 2025-08-11 14:55:17 +00:00
Sum.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
ToString.lean chore: do not use internal append in ToString instances for basic types (#12885) 2026-03-11 15:25:54 +00:00
UInt.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
ULift.lean feat: make private the default in module (#9044) 2025-06-28 16:30:53 +00:00
Vector.lean feat: lemmas about sums of lists/arrays/vectors (#11994) 2026-02-02 07:52:36 +00:00
Zero.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00