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>
212 lines
11 KiB
Text
212 lines
11 KiB
Text
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 0, "character": 20}}
|
||
{"rendered": "```lean\nα : Sort ?u\n⊢ α → α\n```",
|
||
"goals": ["α : Sort ?u\n⊢ α → α"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 0, "character": 21}}
|
||
{"rendered": "```lean\nα : Sort ?u\n⊢ α → α\n```",
|
||
"goals": ["α : Sort ?u\n⊢ α → α"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 3, "character": 2}}
|
||
{"rendered": "```lean\nα : Sort ?u\n⊢ α → α\n```",
|
||
"goals": ["α : Sort ?u\n⊢ α → α"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 3, "character": 3}}
|
||
{"rendered": "```lean\nα : Sort ?u\na : α\n⊢ α\n```",
|
||
"goals": ["α : Sort ?u\na : α\n⊢ α"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 7, "character": 3}}
|
||
{"rendered": "```lean\nα : Sort ?u\na : α\n⊢ α\n```",
|
||
"goals": ["α : Sort ?u\na : α\n⊢ α"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 10, "character": 20}}
|
||
{"rendered": "```lean\nα : Sort ?u\n⊢ α → α\n```",
|
||
"goals": ["α : Sort ?u\n⊢ α → α"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 15, "character": 9}}
|
||
{"rendered": "```lean\ncase zero\n⊢ 0 + 0 = 0\n```",
|
||
"goals": ["case zero\n⊢ 0 + 0 = 0"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 17, "character": 5}}
|
||
{"rendered":
|
||
"```lean\ncase succ\nn✝ : Nat\na✝ : 0 + n✝ = n✝\n⊢ 0 + (n✝ + 1) = n✝ + 1\n```",
|
||
"goals": ["case succ\nn✝ : Nat\na✝ : 0 + n✝ = n✝\n⊢ 0 + (n✝ + 1) = n✝ + 1"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 21, "character": 9}}
|
||
{"rendered": "```lean\nα : Sort ?u\na : α\n⊢ α\n```",
|
||
"goals": ["α : Sort ?u\na : α\n⊢ α"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 21, "character": 10}}
|
||
{"rendered": "```lean\nα : Sort ?u\na : α\n⊢ α\n```",
|
||
"goals": ["α : Sort ?u\na : α\n⊢ α"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 21, "character": 11}}
|
||
{"rendered": "```lean\nα : Sort ?u\na : α\n⊢ α\n```",
|
||
"goals": ["α : Sort ?u\na : α\n⊢ α"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 27, "character": 3}}
|
||
{"rendered": "```lean\nn m : Nat\nh1 : n = m\nh2 : m = 0\n⊢ 0 = n\n```",
|
||
"goals": ["n m : Nat\nh1 : n = m\nh2 : m = 0\n⊢ 0 = n"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 27, "character": 9}}
|
||
{"rendered": "```lean\nn m : Nat\nh1 : n = m\nh2 : m = 0\n⊢ 0 = m\n```",
|
||
"goals": ["n m : Nat\nh1 : n = m\nh2 : m = 0\n⊢ 0 = m"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 27, "character": 13}}
|
||
{"rendered": "no goals", "goals": []}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 34, "character": 3}}
|
||
{"rendered": "```lean\ncase zero\n⊢ 0 + 0 = 0\n```",
|
||
"goals": ["case zero\n⊢ 0 + 0 = 0"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 40, "character": 3}}
|
||
{"rendered":
|
||
"```lean\ncase zero\n⊢ 0 + 0 = 0\n```\n---\n```lean\ncase succ\nn✝ : Nat\na✝ : 0 + n✝ = n✝\n⊢ 0 + (n✝ + 1) = n✝ + 1\n```",
|
||
"goals":
|
||
["case zero\n⊢ 0 + 0 = 0",
|
||
"case succ\nn✝ : Nat\na✝ : 0 + n✝ = n✝\n⊢ 0 + (n✝ + 1) = n✝ + 1"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 44, "character": 3}}
|
||
{"rendered":
|
||
"```lean\ncase zero\n⊢ 0 + 0 = 0\n```\n---\n```lean\ncase succ\nn✝ : Nat\n⊢ 0 + (n✝ + 1) = n✝ + 1\n```",
|
||
"goals":
|
||
["case zero\n⊢ 0 + 0 = 0", "case succ\nn✝ : Nat\n⊢ 0 + (n✝ + 1) = n✝ + 1"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 48, "character": 3}}
|
||
{"rendered": "```lean\na : Nat\n⊢ ∀ (b : Nat), a = b\n```",
|
||
"goals": ["a : Nat\n⊢ ∀ (b : Nat), a = b"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 48, "character": 11}}
|
||
{"rendered": "```lean\na b : Nat\n⊢ a = b\n```",
|
||
"goals": ["a b : Nat\n⊢ a = b"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 52, "character": 20}}
|
||
{"rendered": "```lean\nα : Sort ?u\n⊢ α → α\n```",
|
||
"goals": ["α : Sort ?u\n⊢ α → α"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 56, "character": 3}}
|
||
{"rendered":
|
||
"```lean\nα : Sort u_1\np : α → Prop\na b : α\ninst✝ : DecidablePred p\nh : ∀ {p : α → Prop} [DecidablePred p], p a → p b\n⊢ p a\n```",
|
||
"goals":
|
||
["α : Sort u_1\np : α → Prop\na b : α\ninst✝ : DecidablePred p\nh : ∀ {p : α → Prop} [DecidablePred p], p a → p b\n⊢ p a"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 62, "character": 3}}
|
||
{"rendered": "```lean\ncase left\n⊢ True\n```", "goals": ["case left\n⊢ True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 64, "character": 3}}
|
||
{"rendered": "```lean\ncase right\n⊢ False\n```",
|
||
"goals": ["case right\n⊢ False"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 69, "character": 3}}
|
||
{"rendered": "```lean\ncase left\n⊢ True\n```", "goals": ["case left\n⊢ True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 71, "character": 3}}
|
||
{"rendered": "```lean\ncase right\n⊢ False\n```",
|
||
"goals": ["case right\n⊢ False"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 79, "character": 29}}
|
||
{"rendered":
|
||
"```lean\nt a n✝ : Nat\na✝ : t * (a + n✝) = t * a + t * n✝\n⊢ t * (a + n✝) + t = t * a + t * (n✝ + 1)\n```\n---\n```lean\nt a n✝ : Nat\na✝ : t * (a + n✝) = t * a + t * n✝\n⊢ t * (a + n✝) + t = t * a + (t * n✝ + t)\n```\n---\n```lean\nt a n✝ : Nat\na✝ : t * (a + n✝) = t * a + t * n✝\n⊢ t * (a + n✝) + t = t * a + (t * n✝ + t)\n```",
|
||
"goals":
|
||
["t a n✝ : Nat\na✝ : t * (a + n✝) = t * a + t * n✝\n⊢ t * (a + n✝) + t = t * a + t * (n✝ + 1)",
|
||
"t a n✝ : Nat\na✝ : t * (a + n✝) = t * a + t * n✝\n⊢ t * (a + n✝) + t = t * a + (t * n✝ + t)",
|
||
"t a n✝ : Nat\na✝ : t * (a + n✝) = t * a + t * n✝\n⊢ t * (a + n✝) + t = t * a + (t * n✝ + t)"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 83, "character": 53}}
|
||
{"rendered":
|
||
"```lean\ncase nil\nα : Type u_1\nbs cs : List α\n⊢ [] ++ bs ++ cs = [] ++ (bs ++ cs)\n```",
|
||
"goals":
|
||
["case nil\nα : Type u_1\nbs cs : List α\n⊢ [] ++ bs ++ cs = [] ++ (bs ++ cs)"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 83, "character": 54}}
|
||
{"rendered":
|
||
"```lean\ncase nil\nα : Type u_1\nbs cs : List α\n⊢ [] ++ bs ++ cs = [] ++ (bs ++ cs)\n```",
|
||
"goals":
|
||
["case nil\nα : Type u_1\nbs cs : List α\n⊢ [] ++ bs ++ cs = [] ++ (bs ++ cs)"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 87, "character": 38}}
|
||
{"rendered": "no goals", "goals": []}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 90, "character": 39}}
|
||
null
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 94, "character": 16}}
|
||
{"rendered":
|
||
"```lean\ncase left\n⊢ True\n```\n---\n```lean\ncase right\n⊢ False\n```",
|
||
"goals": ["case left\n⊢ True", "case right\n⊢ False"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 98, "character": 8}}
|
||
{"rendered": "```lean\n| True = True\n```", "goals": ["| True = True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 100, "character": 4}}
|
||
{"rendered": "```lean\n| True = True\n```", "goals": ["| True = True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 102, "character": 2}}
|
||
{"rendered": "no goals", "goals": []}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 107, "character": 4}}
|
||
{"rendered": "```lean\nthis : True\n⊢ True\n```",
|
||
"goals": ["this : True\n⊢ True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 109, "character": 2}}
|
||
{"rendered": "```lean\nthis : True\n⊢ True\n```",
|
||
"goals": ["this : True\n⊢ True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 114, "character": 4}}
|
||
{"rendered": "```lean\nthis : True\n⊢ True\n```",
|
||
"goals": ["this : True\n⊢ True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 116, "character": 2}}
|
||
{"rendered": "```lean\nthis : True\n⊢ True\n```",
|
||
"goals": ["this : True\n⊢ True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 120, "character": 2}}
|
||
{"rendered": "```lean\n⊢ False\n```", "goals": ["⊢ False"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 124, "character": 17}}
|
||
{"rendered": "```lean\np q : Prop\nhp : p\nhq : q\nthis : q ∧ p\n⊢ p ∧ q\n```",
|
||
"goals": ["p q : Prop\nhp : p\nhq : q\nthis : q ∧ p\n⊢ p ∧ q"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 128, "character": 18}}
|
||
{"rendered": "```lean\np q : Prop\nhp : p\nhq : q\n⊢ id (p ∧ q)\n```",
|
||
"goals": ["p q : Prop\nhp : p\nhq : q\n⊢ id (p ∧ q)"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 133, "character": 3}}
|
||
{"rendered": "```lean\ncase left\n⊢ True\n```", "goals": ["case left\n⊢ True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 133, "character": 4}}
|
||
{"rendered": "```lean\ncase left\n⊢ True\n```", "goals": ["case left\n⊢ True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 139, "character": 34}}
|
||
{"rendered":
|
||
"```lean\ncase zero\n⊢ True\n```\n---\n```lean\ncase succ\nn✝ : Nat\na✝ : True\n⊢ True\n```",
|
||
"goals": ["case zero\n⊢ True", "case succ\nn✝ : Nat\na✝ : True\n⊢ True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 142, "character": 34}}
|
||
{"rendered":
|
||
"```lean\ncase zero\n⊢ True\n```\n---\n```lean\ncase succ\nn✝ : Nat\na✝ : True\n⊢ True\n```",
|
||
"goals": ["case zero\n⊢ True", "case succ\nn✝ : Nat\na✝ : True\n⊢ True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 145, "character": 34}}
|
||
{"rendered": "```lean\nx✝ : Nat\n⊢ True\n```", "goals": ["x✝ : Nat\n⊢ True"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 153, "character": 2}}
|
||
{"rendered":
|
||
"```lean\nf : Nat → Nat\nn : Nat\nhf : ∀ (x : Nat), f x = x + 0 + 1\n⊢ f n + 0 = 1 + n\n```",
|
||
"goals":
|
||
["f : Nat → Nat\nn : Nat\nhf : ∀ (x : Nat), f x = x + 0 + 1\n⊢ f n + 0 = 1 + n"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 153, "character": 3}}
|
||
{"rendered":
|
||
"```lean\nf : Nat → Nat\nn : Nat\nhf : ∀ (x : Nat), f x = x + 0 + 1\n⊢ f n = n + 1\n```",
|
||
"goals":
|
||
["f : Nat → Nat\nn : Nat\nhf : ∀ (x : Nat), f x = x + 0 + 1\n⊢ f n = n + 1"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 153, "character": 41}}
|
||
{"rendered":
|
||
"```lean\nf : Nat → Nat\nn : Nat\nhf : ∀ (x : Nat), f x = x + 0 + 1\n⊢ f n = n + 1\n```",
|
||
"goals":
|
||
["f : Nat → Nat\nn : Nat\nhf : ∀ (x : Nat), f x = x + 0 + 1\n⊢ f n = n + 1"]}
|
||
{"textDocument": {"uri": "file:///plainGoal.lean"},
|
||
"position": {"line": 153, "character": 43}}
|
||
{"rendered": "no goals", "goals": []}
|