Compare commits
1 Commits
dev
...
repl/elab-
Author | SHA1 | Date |
---|---|---|
|
14b74b612d |
18
Main.lean
18
Main.lean
|
@ -8,12 +8,6 @@ import Repl
|
||||||
open Pantograph.Repl
|
open Pantograph.Repl
|
||||||
open Pantograph.Protocol
|
open Pantograph.Protocol
|
||||||
|
|
||||||
/-- Print a string to stdout without buffering -/
|
|
||||||
def printImmediate (s : String) : IO Unit := do
|
|
||||||
let stdout ← IO.getStdout
|
|
||||||
stdout.putStr (s ++ "\n")
|
|
||||||
stdout.flush
|
|
||||||
|
|
||||||
/-- Parse a command either in `{ "cmd": ..., "payload": ... }` form or `cmd { ... }` form. -/
|
/-- Parse a command either in `{ "cmd": ..., "payload": ... }` form or `cmd { ... }` form. -/
|
||||||
def parseCommand (s: String): Except String Command := do
|
def parseCommand (s: String): Except String Command := do
|
||||||
match s.trim.get? 0 with
|
match s.trim.get? 0 with
|
||||||
|
@ -40,26 +34,26 @@ partial def loop : MainM Unit := do repeat do
|
||||||
| .error error =>
|
| .error error =>
|
||||||
let error := Lean.toJson ({ error := "command", desc := error }: InteractionError)
|
let error := Lean.toJson ({ error := "command", desc := error }: InteractionError)
|
||||||
-- Using `Lean.Json.compress` here to prevent newline
|
-- Using `Lean.Json.compress` here to prevent newline
|
||||||
printImmediate error.compress
|
IO.println error.compress
|
||||||
| .ok command =>
|
| .ok command =>
|
||||||
try
|
try
|
||||||
let ret ← execute command
|
let ret ← execute command
|
||||||
let str := match state.options.printJsonPretty with
|
let str := match state.options.printJsonPretty with
|
||||||
| true => ret.pretty
|
| true => ret.pretty
|
||||||
| false => ret.compress
|
| false => ret.compress
|
||||||
printImmediate str
|
IO.println str
|
||||||
catch e =>
|
catch e =>
|
||||||
let message := e.toString
|
let message := e.toString
|
||||||
let error := Lean.toJson ({ error := "main", desc := message }: InteractionError)
|
let error := Lean.toJson ({ error := "main", desc := message }: InteractionError)
|
||||||
printImmediate error.compress
|
IO.println error.compress
|
||||||
|
|
||||||
def main (args: List String): IO Unit := do
|
|
||||||
|
unsafe def main (args: List String): IO Unit := do
|
||||||
-- NOTE: A more sophisticated scheme of command line argument handling is needed.
|
-- NOTE: A more sophisticated scheme of command line argument handling is needed.
|
||||||
if args == ["--version"] then do
|
if args == ["--version"] then do
|
||||||
IO.println s!"{Pantograph.version}"
|
IO.println s!"{Pantograph.version}"
|
||||||
return
|
return
|
||||||
|
|
||||||
unsafe do
|
|
||||||
Pantograph.initSearch ""
|
Pantograph.initSearch ""
|
||||||
|
|
||||||
-- Separate imports and options
|
-- Separate imports and options
|
||||||
|
@ -68,7 +62,7 @@ def main (args: List String): IO Unit := do
|
||||||
let coreState ← Pantograph.createCoreState imports.toArray
|
let coreState ← Pantograph.createCoreState imports.toArray
|
||||||
try
|
try
|
||||||
let mainM := loop.run { coreContext } |>.run' { env := coreState.env }
|
let mainM := loop.run { coreContext } |>.run' { env := coreState.env }
|
||||||
printImmediate "ready."
|
IO.println "ready."
|
||||||
mainM
|
mainM
|
||||||
catch ex =>
|
catch ex =>
|
||||||
let message := ex.toString
|
let message := ex.toString
|
||||||
|
|
|
@ -164,7 +164,7 @@ partial def instantiateDelayedMVars (expr : Expr) : MetaM Expr :=
|
||||||
self e := instantiateDelayedMVars e
|
self e := instantiateDelayedMVars e
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Convert an expression to an equivalent form with
|
Convert an expression to an equiavlent form with
|
||||||
1. No nested delayed assigned mvars
|
1. No nested delayed assigned mvars
|
||||||
2. No aux lemmas or matchers
|
2. No aux lemmas or matchers
|
||||||
3. No assigned mvars
|
3. No assigned mvars
|
||||||
|
|
|
@ -81,7 +81,7 @@ the environment might be setup like this:
|
||||||
``` sh
|
``` sh
|
||||||
LIB="../lib"
|
LIB="../lib"
|
||||||
LIB_MATHLIB="$LIB/mathlib4/.lake"
|
LIB_MATHLIB="$LIB/mathlib4/.lake"
|
||||||
export LEAN_PATH="$LIB_MATHLIB:$LIB_MATHLIB/aesop/build/lib:$LIB_MATHLIB/Qq/build/lib:$LIB_MATHLIB/std/build/lib"
|
export LEAN_PATH="$LIB/mathlib4/build/lib:$LIB_MATHLIB/aesop/build/lib:$LIB_MATHLIB/Qq/build/lib:$LIB_MATHLIB/std/build/lib"
|
||||||
|
|
||||||
LEAN_PATH=$LEAN_PATH build/bin/pantograph $@
|
LEAN_PATH=$LEAN_PATH build/bin/pantograph $@
|
||||||
```
|
```
|
||||||
|
|
|
@ -81,6 +81,7 @@ def liftTermElabM { α } (termElabM: Elab.TermElabM α) (levelNames : List Name
|
||||||
: EMainM α := do
|
: EMainM α := do
|
||||||
let scope := (← get).scope
|
let scope := (← get).scope
|
||||||
let context := {
|
let context := {
|
||||||
|
errToSorry := false,
|
||||||
isNoncomputableSection := scope.isNoncomputable,
|
isNoncomputableSection := scope.isNoncomputable,
|
||||||
}
|
}
|
||||||
let state := {
|
let state := {
|
||||||
|
|
|
@ -47,12 +47,12 @@ include:
|
||||||
|
|
||||||
- If a tactic loses track of metavariables, it will not be caught until the end
|
- If a tactic loses track of metavariables, it will not be caught until the end
|
||||||
of the proof search. This is a bug in the tactic itself.
|
of the proof search. This is a bug in the tactic itself.
|
||||||
- Although a timeout feature exists in Pantograph, it relies on the coöperative
|
- Timeouts for executing tactics is not available. Maybe this will change in the
|
||||||
multitasking from the tactic implementation. There is nothing preventing a
|
future.
|
||||||
buggy tactic from stalling Lean if it does not check for cancellation often.
|
|
||||||
- Interceptions of parsing errors generally cannot be turned into goals (e.g.
|
- Interceptions of parsing errors generally cannot be turned into goals (e.g.
|
||||||
`def mystery : Nat := :=`) due to Lean's parsing system.
|
`def mystery : Nat := :=`) due to Lean's parsing system.
|
||||||
|
|
||||||
|
|
||||||
## References
|
## References
|
||||||
|
|
||||||
* [Pantograph Paper](https://arxiv.org/abs/2410.16429)
|
* [Pantograph Paper](https://arxiv.org/abs/2410.16429)
|
||||||
|
|
Loading…
Reference in New Issue