Add default arguments for Json
This commit is contained in:
parent
147079816d
commit
2772a394cc
13
Main.lean
13
Main.lean
|
@ -144,13 +144,13 @@ unsafe def execute (command: Command): Subroutine Lean.Json := do
|
||||||
| .error error => throw <| Lean.toJson <| errorIndex error
|
| .error error => throw <| Lean.toJson <| errorIndex error
|
||||||
| .ok env => pure env
|
| .ok env => pure env
|
||||||
let tree := Meta.createProofTree
|
let tree := Meta.createProofTree
|
||||||
(name := args.name)
|
(name := args.name.getD "Untitled")
|
||||||
(env := env)
|
(env := env)
|
||||||
(coreContext := context.coreContext)
|
(coreContext := context.coreContext)
|
||||||
let expr: Lean.Expr ← match args.expr, args.copyFrom with
|
let expr: Lean.Expr ← match args.expr, args.copyFrom with
|
||||||
| "", "" =>
|
| .none, .none =>
|
||||||
throw <| Lean.toJson ({ error := "arguments", desc := "At least one of {expr, copyFrom} must be supplied" }: InteractionError)
|
throw <| Lean.toJson ({ error := "arguments", desc := "At least one of {expr, copyFrom} must be supplied" }: InteractionError)
|
||||||
| expr, "" =>
|
| .some expr, .none =>
|
||||||
let syn ← match Serial.syntax_from_str env expr with
|
let syn ← match Serial.syntax_from_str env expr with
|
||||||
| .error str => throw <| Lean.toJson ({ error := "parsing", desc := str }: InteractionError)
|
| .error str => throw <| Lean.toJson ({ error := "parsing", desc := str }: InteractionError)
|
||||||
| .ok syn => pure syn
|
| .ok syn => pure syn
|
||||||
|
@ -158,7 +158,7 @@ unsafe def execute (command: Command): Subroutine Lean.Json := do
|
||||||
| .error str => throw <| Lean.toJson ({ error := "elab", desc := str }: InteractionError)
|
| .error str => throw <| Lean.toJson ({ error := "elab", desc := str }: InteractionError)
|
||||||
| .ok expr => pure expr
|
| .ok expr => pure expr
|
||||||
pure expr
|
pure expr
|
||||||
| "", copyFrom =>
|
| .none, .some copyFrom =>
|
||||||
match Serial.expr_from_const env (name := str_to_name copyFrom) with
|
match Serial.expr_from_const env (name := str_to_name copyFrom) with
|
||||||
| .error str =>
|
| .error str =>
|
||||||
IO.println "Symbol not found"
|
IO.println "Symbol not found"
|
||||||
|
@ -180,7 +180,10 @@ unsafe def execute (command: Command): Subroutine Lean.Json := do
|
||||||
match state.proofTrees.get? args.treeId with
|
match state.proofTrees.get? args.treeId with
|
||||||
| .none => return Lean.toJson <| errorIndex "Invalid tree index {args.treeId}"
|
| .none => return Lean.toJson <| errorIndex "Invalid tree index {args.treeId}"
|
||||||
| .some tree =>
|
| .some tree =>
|
||||||
let (result, nextTree) ← Meta.ProofM.execute args.stateId args.goalId args.tactic |>.run tree
|
let (result, nextTree) ← Meta.ProofM.execute
|
||||||
|
(stateId := args.stateId)
|
||||||
|
(goalId := args.goalId.getD 0)
|
||||||
|
(tactic := args.tactic) |>.run tree
|
||||||
match result with
|
match result with
|
||||||
| .invalid message => return Lean.toJson <| errorIndex message
|
| .invalid message => return Lean.toJson <| errorIndex message
|
||||||
| .success nextId goals =>
|
| .success nextId goals =>
|
||||||
|
|
|
@ -50,10 +50,10 @@ structure InspectResult where
|
||||||
|
|
||||||
structure ProofStart where
|
structure ProofStart where
|
||||||
id: Nat -- Environment id
|
id: Nat -- Environment id
|
||||||
name: String := "Untitled" -- Identifier of the proof
|
name: Option String -- Identifier of the proof
|
||||||
-- Only one of the fields below may be populated.
|
-- Only one of the fields below may be populated.
|
||||||
expr: String := "" -- Proof expression
|
expr: Option String -- Proof expression
|
||||||
copyFrom: String := "" -- Theorem name
|
copyFrom: Option String -- Theorem name
|
||||||
deriving Lean.FromJson
|
deriving Lean.FromJson
|
||||||
structure ProofStartResult where
|
structure ProofStartResult where
|
||||||
error: String := ""
|
error: String := ""
|
||||||
|
@ -63,7 +63,7 @@ structure ProofStartResult where
|
||||||
structure ProofTactic where
|
structure ProofTactic where
|
||||||
treeId: Nat
|
treeId: Nat
|
||||||
stateId: Nat
|
stateId: Nat
|
||||||
goalId: Nat := 0
|
goalId: Option Nat -- defaults to 0
|
||||||
tactic: String
|
tactic: String
|
||||||
deriving Lean.FromJson
|
deriving Lean.FromJson
|
||||||
structure ProofTacticResultSuccess where
|
structure ProofTacticResultSuccess where
|
||||||
|
|
|
@ -48,7 +48,7 @@ Example proving a theorem: (alternatively use `proof.start {"id": 0, "name": "aa
|
||||||
```
|
```
|
||||||
$ lake env build/bin/Pantograph
|
$ lake env build/bin/Pantograph
|
||||||
create {"imports": ["Init"]}
|
create {"imports": ["Init"]}
|
||||||
proof.start {"id": 0, "name": "aa", "copyFrom": "", "expr": "∀ (n m : Nat), n + m = m + n"}
|
proof.start {"id": 0, "expr": "∀ (n m : Nat), n + m = m + n"}
|
||||||
proof.tactic {"treeId": 0, "stateId": 0, "goalId": 0, "tactic": "intro n m"}
|
proof.tactic {"treeId": 0, "stateId": 0, "goalId": 0, "tactic": "intro n m"}
|
||||||
proof.tactic {"treeId": 0, "stateId": 1, "goalId": 0, "tactic": "assumption"}
|
proof.tactic {"treeId": 0, "stateId": 1, "goalId": 0, "tactic": "assumption"}
|
||||||
proof.printTree {"treeId": 0}
|
proof.printTree {"treeId": 0}
|
||||||
|
|
Loading…
Reference in New Issue