Compare commits
No commits in common. "8063039f7e70cb234812ec1babb43e3586484cfd" and "896475848b55c98d205134eb965adf611ce1187a" have entirely different histories.
8063039f7e
...
896475848b
|
@ -40,7 +40,6 @@ def stxByteRange (stx : Syntax) : String.Pos × String.Pos :=
|
||||||
abbrev FrontendM := Elab.Frontend.FrontendM
|
abbrev FrontendM := Elab.Frontend.FrontendM
|
||||||
|
|
||||||
structure CompilationStep where
|
structure CompilationStep where
|
||||||
scope : Elab.Command.Scope
|
|
||||||
fileName : String
|
fileName : String
|
||||||
fileMap : FileMap
|
fileMap : FileMap
|
||||||
src : Substring
|
src : Substring
|
||||||
|
@ -75,7 +74,7 @@ def processOneCommand: FrontendM (CompilationStep × Bool) := do
|
||||||
let msgs := s'.messages.toList.drop s.messages.toList.length
|
let msgs := s'.messages.toList.drop s.messages.toList.length
|
||||||
let trees := s'.infoState.trees.drop s.infoState.trees.size
|
let trees := s'.infoState.trees.drop s.infoState.trees.size
|
||||||
let ⟨_, fileName, fileMap⟩ := (← read).inputCtx
|
let ⟨_, fileName, fileMap⟩ := (← read).inputCtx
|
||||||
return ({ scope := s.scopes.head!, fileName, fileMap, src, stx, before, after, msgs, trees }, done)
|
return ({ fileName, fileMap, src, stx, before, after, msgs, trees }, done)
|
||||||
|
|
||||||
partial def mapCompilationSteps { α } (f: CompilationStep → IO α) : FrontendM (List α) := do
|
partial def mapCompilationSteps { α } (f: CompilationStep → IO α) : FrontendM (List α) := do
|
||||||
let (cmd, done) ← processOneCommand
|
let (cmd, done) ← processOneCommand
|
||||||
|
|
|
@ -346,11 +346,6 @@ structure FrontendProcess where
|
||||||
-- One of these two must be supplied: Either supply the file name or the content.
|
-- One of these two must be supplied: Either supply the file name or the content.
|
||||||
fileName?: Option String := .none
|
fileName?: Option String := .none
|
||||||
file?: Option String := .none
|
file?: Option String := .none
|
||||||
-- If set to true, read the header (otherwise discards the header)
|
|
||||||
readHeader : Bool := false
|
|
||||||
-- If set to true, Pantograph's environment will be altered to whatever is
|
|
||||||
-- after the compilation units.
|
|
||||||
inheritEnv : Bool := false
|
|
||||||
-- collect tactic invocations
|
-- collect tactic invocations
|
||||||
invocations: Bool := false
|
invocations: Bool := false
|
||||||
-- collect `sorry`s
|
-- collect `sorry`s
|
||||||
|
|
11
Repl.lean
11
Repl.lean
|
@ -53,10 +53,11 @@ def frontend_process_inner (args: Protocol.FrontendProcess): MainM (CR Protocol.
|
||||||
| .none, .some file =>
|
| .none, .some file =>
|
||||||
pure ("<anonymous>", file)
|
pure ("<anonymous>", file)
|
||||||
| _, _ => return .error <| errorI "arguments" "Exactly one of {fileName, file} must be supplied"
|
| _, _ => return .error <| errorI "arguments" "Exactly one of {fileName, file} must be supplied"
|
||||||
let env?: Option Environment ← if args.readHeader then
|
let env?: Option Environment ← if args.fileName?.isSome then
|
||||||
pure .none
|
pure .none
|
||||||
else do
|
else do
|
||||||
.some <$> getEnv
|
let env ← getEnv
|
||||||
|
pure <| .some env
|
||||||
let (context, state) ← do Frontend.createContextStateFromFile file fileName env? {}
|
let (context, state) ← do Frontend.createContextStateFromFile file fileName env? {}
|
||||||
let frontendM: Elab.Frontend.FrontendM (List CompilationUnit) :=
|
let frontendM: Elab.Frontend.FrontendM (List CompilationUnit) :=
|
||||||
Frontend.mapCompilationSteps λ step => do
|
Frontend.mapCompilationSteps λ step => do
|
||||||
|
@ -82,9 +83,7 @@ def frontend_process_inner (args: Protocol.FrontendProcess): MainM (CR Protocol.
|
||||||
messages,
|
messages,
|
||||||
newConstants
|
newConstants
|
||||||
}
|
}
|
||||||
let (li, state') ← frontendM.run context |>.run state
|
let li ← frontendM.run context |>.run' state
|
||||||
if args.inheritEnv then
|
|
||||||
setEnv state'.commandState.env
|
|
||||||
let units ← li.mapM λ step => withEnv step.env do
|
let units ← li.mapM λ step => withEnv step.env do
|
||||||
let newConstants? := if args.newConstants then
|
let newConstants? := if args.newConstants then
|
||||||
.some $ step.newConstants.toArray.map λ name => name.toString
|
.some $ step.newConstants.toArray.map λ name => name.toString
|
||||||
|
@ -142,7 +141,7 @@ def execute (command: Protocol.Command): MainM Json := do
|
||||||
| "goal.print" => run goal_print
|
| "goal.print" => run goal_print
|
||||||
| "goal.save" => run goal_save
|
| "goal.save" => run goal_save
|
||||||
| "goal.load" => run goal_load
|
| "goal.load" => run goal_load
|
||||||
| "frontend.process" => run frontend_process
|
| "frontend.process" => run frontend_process
|
||||||
| cmd =>
|
| cmd =>
|
||||||
let error: Protocol.InteractionError :=
|
let error: Protocol.InteractionError :=
|
||||||
errorCommand s!"Unknown command {cmd}"
|
errorCommand s!"Unknown command {cmd}"
|
||||||
|
|
|
@ -1,28 +1,11 @@
|
||||||
|
import LSpec
|
||||||
import Pantograph
|
import Pantograph
|
||||||
import Repl
|
import Repl
|
||||||
import Test.Common
|
import Test.Common
|
||||||
|
|
||||||
import LSpec
|
|
||||||
|
|
||||||
open Lean Pantograph
|
open Lean Pantograph
|
||||||
namespace Pantograph.Test.Frontend
|
namespace Pantograph.Test.Frontend
|
||||||
|
|
||||||
def runFrontend { α } (source: String) (f : Frontend.CompilationStep → IO α) : MetaM (List α) := do
|
|
||||||
let filename := "<anonymous>"
|
|
||||||
let (context, state) ← do Frontend.createContextStateFromFile source filename (← getEnv) {}
|
|
||||||
let m := Frontend.mapCompilationSteps f
|
|
||||||
m.run context |>.run' state
|
|
||||||
|
|
||||||
def test_open : TestT MetaM Unit := do
|
|
||||||
let sketch := "
|
|
||||||
open Nat
|
|
||||||
example : ∀ (n : Nat), n + 1 = Nat.succ n := by
|
|
||||||
intro
|
|
||||||
apply add_one
|
|
||||||
"
|
|
||||||
let errors ← runFrontend sketch λ step => step.msgs.mapM (·.toString)
|
|
||||||
checkEq "errors" errors [[], []]
|
|
||||||
|
|
||||||
def collectSorrysFromSource (source: String) (options : Frontend.GoalCollectionOptions := {})
|
def collectSorrysFromSource (source: String) (options : Frontend.GoalCollectionOptions := {})
|
||||||
: MetaM (List GoalState) := do
|
: MetaM (List GoalState) := do
|
||||||
let filename := "<anonymous>"
|
let filename := "<anonymous>"
|
||||||
|
@ -250,7 +233,6 @@ theorem mystery [SizeOf α] (as : List α) (i : Fin as.length) : sizeOf (as.get
|
||||||
|
|
||||||
def suite (env : Environment): List (String × IO LSpec.TestSeq) :=
|
def suite (env : Environment): List (String × IO LSpec.TestSeq) :=
|
||||||
let tests := [
|
let tests := [
|
||||||
("open", test_open),
|
|
||||||
("multiple_sorrys_in_proof", test_multiple_sorrys_in_proof),
|
("multiple_sorrys_in_proof", test_multiple_sorrys_in_proof),
|
||||||
("sorry_in_middle", test_sorry_in_middle),
|
("sorry_in_middle", test_sorry_in_middle),
|
||||||
("sorry_in_induction", test_sorry_in_induction),
|
("sorry_in_induction", test_sorry_in_induction),
|
||||||
|
|
|
@ -173,8 +173,6 @@ def test_frontend_process : Test :=
|
||||||
[
|
[
|
||||||
("file", .str file),
|
("file", .str file),
|
||||||
("invocations", .bool true),
|
("invocations", .bool true),
|
||||||
("readHeader", .bool false),
|
|
||||||
("inheritEnv", .bool false),
|
|
||||||
("sorrys", .bool false),
|
("sorrys", .bool false),
|
||||||
("typeErrorsAsGoals", .bool false),
|
("typeErrorsAsGoals", .bool false),
|
||||||
("newConstants", .bool false),
|
("newConstants", .bool false),
|
||||||
|
@ -216,8 +214,6 @@ def test_frontend_process_sorry : Test :=
|
||||||
step "frontend.process"
|
step "frontend.process"
|
||||||
[
|
[
|
||||||
("file", .str file),
|
("file", .str file),
|
||||||
("readHeader", .bool false),
|
|
||||||
("inheritEnv", .bool false),
|
|
||||||
("invocations", .bool false),
|
("invocations", .bool false),
|
||||||
("sorrys", .bool true),
|
("sorrys", .bool true),
|
||||||
("typeErrorsAsGoals", .bool false),
|
("typeErrorsAsGoals", .bool false),
|
||||||
|
|
Loading…
Reference in New Issue