Skip to content

Commit

Permalink
feat: catch syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-em committed Oct 13, 2023
1 parent d12c4e6 commit 6c081d4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
10 changes: 6 additions & 4 deletions REPL/Main.lean
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,16 @@ def runCommand (s : Command) : M m (CommandResponse ⊕ Error) := do
/--
Run a single tactic, returning the id of the new proof statement, and the new goals.
-/
-- TODO return messages?
-- TODO detect sorries?
def runProofStep (s : ProofStep) : M m (ProofStepResponse ⊕ Error) := do
def runProofStep (s : ProofStep) : M IO (ProofStepResponse ⊕ Error) := do
match (← get).proofStates[s.proofState]? with
| none => return .inr ⟨"Unknown proof state."
| some proofState =>
let proofState' ← proofState.runString s.tactic
return .inl (← createProofStepReponse proofState' proofState)
try
let proofState' ← proofState.runString s.tactic
return .inl (← createProofStepReponse proofState' proofState)
catch ex =>
return .inr ⟨ex.toString⟩

end REPL

Expand Down
20 changes: 20 additions & 0 deletions test/invalid_tactic.expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{"sorries":
[{"proofState": 0,
"pos": {"line": 1, "column": 43},
"goal": "x : Nat ⊢ x = x",
"endPos": {"line": 1, "column": 48}}],
"messages":
[{"severity": "warning",
"pos": {"line": 1, "column": 8},
"endPos": {"line": 1, "column": 18},
"data": "declaration uses 'sorry'"}],
"env": 0}

{"proofState": 1,
"messages":
[{"severity": "error",
"pos": {"line": 0, "column": 0},
"endPos": {"line": 0, "column": 0},
"data": "unknown identifier 'my_fake_premise'"}],
"goals": []}

3 changes: 3 additions & 0 deletions test/invalid_tactic.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"cmd": "theorem my_theorem (x : Nat) : x = x := by sorry"}

{"tactic": "exact my_fake_premise", "proofState": 0}
3 changes: 2 additions & 1 deletion test/unknown_tactic.expected.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
"data": "declaration uses 'sorry'"}],
"env": 0}

uncaught exception: <input>:1:1: unknown tactic
{"message": "<input>:1:1: unknown tactic"}

0 comments on commit 6c081d4

Please sign in to comment.