2023-05-24 22:33:10 -07:00
|
|
|
|
/-
|
|
|
|
|
All the command input/output structures are stored here
|
|
|
|
|
|
|
|
|
|
Note that no command other than `InteractionError` may have `error` as one of
|
|
|
|
|
its field names to avoid confusion with error messages generated by the REPL.
|
|
|
|
|
-/
|
2023-05-09 18:01:09 -07:00
|
|
|
|
import Lean.Data.Json
|
|
|
|
|
|
2023-10-15 17:15:23 -07:00
|
|
|
|
namespace Pantograph.Protocol
|
2023-05-09 18:01:09 -07:00
|
|
|
|
|
2023-08-14 17:07:53 -07:00
|
|
|
|
|
|
|
|
|
/-- Main Option structure, placed here to avoid name collision -/
|
|
|
|
|
structure Options where
|
2023-08-16 19:25:32 -07:00
|
|
|
|
-- When false, suppress newlines in Json objects. Useful for machine-to-machine interaction.
|
|
|
|
|
-- This should be false` by default to avoid any surprises with parsing.
|
|
|
|
|
printJsonPretty: Bool := false
|
2023-08-14 17:07:53 -07:00
|
|
|
|
-- When enabled, pretty print every expression
|
|
|
|
|
printExprPretty: Bool := true
|
|
|
|
|
-- When enabled, print the raw AST of expressions
|
|
|
|
|
printExprAST: Bool := false
|
2023-10-26 22:47:42 -07:00
|
|
|
|
-- When enabled, the types and values of persistent variables in a goal
|
|
|
|
|
-- are not shown unless they are new to the proof step. Reduces overhead.
|
|
|
|
|
-- NOTE: that this assumes the type and assignment of variables can never change.
|
|
|
|
|
noRepeat: Bool := false
|
2023-08-15 15:40:54 -07:00
|
|
|
|
-- See `pp.auxDecls`
|
|
|
|
|
printAuxDecls: Bool := false
|
|
|
|
|
-- See `pp.implementationDetailHyps`
|
|
|
|
|
printImplementationDetailHyps: Bool := false
|
2023-08-14 17:07:53 -07:00
|
|
|
|
deriving Lean.ToJson
|
|
|
|
|
|
2023-08-14 21:43:40 -07:00
|
|
|
|
abbrev OptionsT := ReaderT Options
|
|
|
|
|
|
2023-08-14 17:07:53 -07:00
|
|
|
|
--- Expression Objects ---
|
|
|
|
|
|
|
|
|
|
structure BoundExpression where
|
|
|
|
|
binders: Array (String × String)
|
|
|
|
|
target: String
|
|
|
|
|
deriving Lean.ToJson
|
|
|
|
|
structure Expression where
|
|
|
|
|
-- Pretty printed expression
|
|
|
|
|
pp?: Option String := .none
|
|
|
|
|
-- AST structure
|
|
|
|
|
sexp?: Option String := .none
|
|
|
|
|
deriving Lean.ToJson
|
|
|
|
|
|
|
|
|
|
structure Variable where
|
2023-10-25 22:18:59 -07:00
|
|
|
|
/-- The internal name used in raw expressions -/
|
|
|
|
|
name: String := ""
|
|
|
|
|
/-- The name displayed to the user -/
|
|
|
|
|
userName: String
|
2023-08-14 17:07:53 -07:00
|
|
|
|
/-- Does the name contain a dagger -/
|
2023-08-15 15:40:54 -07:00
|
|
|
|
isInaccessible?: Option Bool := .none
|
|
|
|
|
type?: Option Expression := .none
|
2023-08-14 17:07:53 -07:00
|
|
|
|
value?: Option Expression := .none
|
|
|
|
|
deriving Lean.ToJson
|
|
|
|
|
structure Goal where
|
2023-10-30 14:44:06 -07:00
|
|
|
|
name: String := ""
|
|
|
|
|
/-- Name of the metavariable -/
|
|
|
|
|
userName?: Option String := .none
|
2023-08-14 17:07:53 -07:00
|
|
|
|
/-- Is the goal in conversion mode -/
|
|
|
|
|
isConversion: Bool := false
|
|
|
|
|
/-- target expression type -/
|
|
|
|
|
target: Expression
|
|
|
|
|
/-- Variables -/
|
|
|
|
|
vars: Array Variable := #[]
|
|
|
|
|
deriving Lean.ToJson
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--- Individual Commands and return types ---
|
|
|
|
|
|
2023-05-20 15:58:38 -07:00
|
|
|
|
structure Command where
|
|
|
|
|
cmd: String
|
|
|
|
|
payload: Lean.Json
|
|
|
|
|
deriving Lean.FromJson
|
|
|
|
|
|
|
|
|
|
structure InteractionError where
|
|
|
|
|
error: String
|
|
|
|
|
desc: String
|
|
|
|
|
deriving Lean.ToJson
|
|
|
|
|
|
2023-12-15 10:37:55 -08:00
|
|
|
|
def errorIndex (desc: String): InteractionError := { error := "index", desc }
|
|
|
|
|
def errorExpr (desc: String): InteractionError := { error := "expr", desc }
|
|
|
|
|
|
2023-05-20 15:58:38 -07:00
|
|
|
|
|
2023-08-13 21:19:06 -07:00
|
|
|
|
--- Individual command and return types ---
|
|
|
|
|
|
2023-08-16 19:25:32 -07:00
|
|
|
|
|
|
|
|
|
structure Reset where
|
2023-08-13 21:19:06 -07:00
|
|
|
|
deriving Lean.FromJson
|
2023-08-27 19:58:52 -07:00
|
|
|
|
structure Stat where
|
|
|
|
|
deriving Lean.FromJson
|
|
|
|
|
structure StatResult where
|
|
|
|
|
-- Number of goals states
|
|
|
|
|
nGoals: Nat
|
2023-08-13 21:19:06 -07:00
|
|
|
|
deriving Lean.ToJson
|
2023-05-20 15:58:38 -07:00
|
|
|
|
|
2023-08-16 19:25:32 -07:00
|
|
|
|
-- Return the type of an expression
|
|
|
|
|
structure ExprEcho where
|
|
|
|
|
expr: String
|
2023-08-14 17:07:53 -07:00
|
|
|
|
deriving Lean.FromJson
|
2023-08-16 19:25:32 -07:00
|
|
|
|
structure ExprEchoResult where
|
|
|
|
|
expr: Expression
|
|
|
|
|
type: Expression
|
|
|
|
|
deriving Lean.ToJson
|
2023-05-17 21:58:03 -07:00
|
|
|
|
|
2023-05-20 15:58:38 -07:00
|
|
|
|
-- Print all symbols in environment
|
2023-12-12 18:56:25 -08:00
|
|
|
|
structure EnvCatalog where
|
2023-05-17 21:58:03 -07:00
|
|
|
|
deriving Lean.FromJson
|
2023-12-12 18:56:25 -08:00
|
|
|
|
structure EnvCatalogResult where
|
2023-05-27 23:10:39 -07:00
|
|
|
|
symbols: Array String
|
2023-05-09 22:51:19 -07:00
|
|
|
|
deriving Lean.ToJson
|
2024-01-16 13:29:30 -08:00
|
|
|
|
|
2023-05-20 15:58:38 -07:00
|
|
|
|
-- Print the type of a symbol
|
2023-12-12 18:56:25 -08:00
|
|
|
|
structure EnvInspect where
|
2023-05-22 19:45:08 -07:00
|
|
|
|
name: String
|
2023-08-14 17:07:53 -07:00
|
|
|
|
-- If true/false, show/hide the value expressions; By default definitions
|
|
|
|
|
-- values are shown and theorem values are hidden.
|
|
|
|
|
value?: Option Bool := .some false
|
2023-11-25 15:07:56 -08:00
|
|
|
|
-- If true, show the type and value dependencies
|
|
|
|
|
dependency?: Option Bool := .some false
|
2023-05-20 14:04:09 -07:00
|
|
|
|
deriving Lean.FromJson
|
2024-01-16 13:29:30 -08:00
|
|
|
|
-- See `InductiveVal`
|
|
|
|
|
structure InductInfo where
|
|
|
|
|
numParams: Nat
|
|
|
|
|
numIndices: Nat
|
|
|
|
|
all: List String
|
|
|
|
|
ctors: List String
|
|
|
|
|
isRec: Bool := false
|
|
|
|
|
isReflexive: Bool := false
|
|
|
|
|
isNested: Bool := false
|
|
|
|
|
deriving Lean.ToJson
|
2024-01-16 14:11:52 -08:00
|
|
|
|
-- See `ConstructorVal`
|
|
|
|
|
structure ConstructorInfo where
|
|
|
|
|
induct: String
|
|
|
|
|
cidx: Nat
|
|
|
|
|
numParams: Nat
|
|
|
|
|
numFields: Nat
|
|
|
|
|
deriving Lean.ToJson
|
|
|
|
|
structure RecursorInfo where
|
|
|
|
|
all: List String
|
|
|
|
|
numParams: Nat
|
|
|
|
|
numIndices: Nat
|
|
|
|
|
numMotives: Nat
|
|
|
|
|
numMinors: Nat
|
|
|
|
|
k: Bool
|
|
|
|
|
deriving Lean.ToJson
|
2023-12-12 18:56:25 -08:00
|
|
|
|
structure EnvInspectResult where
|
2023-08-14 17:07:53 -07:00
|
|
|
|
type: Expression
|
2024-01-16 14:11:52 -08:00
|
|
|
|
isUnsafe: Bool := false
|
2023-08-14 17:07:53 -07:00
|
|
|
|
value?: Option Expression := .none
|
2023-12-05 22:45:59 -08:00
|
|
|
|
module?: Option String := .none
|
2023-12-05 20:20:08 -08:00
|
|
|
|
-- If the name is private, displays the public facing name
|
|
|
|
|
publicName?: Option String := .none
|
2023-11-25 15:07:56 -08:00
|
|
|
|
typeDependency?: Option (Array String) := .none
|
|
|
|
|
valueDependency?: Option (Array String) := .none
|
2024-01-16 14:11:52 -08:00
|
|
|
|
inductInfo?: Option InductInfo := .none
|
|
|
|
|
constructorInfo?: Option ConstructorInfo := .none
|
|
|
|
|
recursorInfo?: Option RecursorInfo := .none
|
2023-05-25 13:40:03 -07:00
|
|
|
|
deriving Lean.ToJson
|
2024-01-16 13:29:30 -08:00
|
|
|
|
|
2023-12-13 19:35:32 -08:00
|
|
|
|
structure EnvAdd where
|
|
|
|
|
name: String
|
|
|
|
|
type: String
|
|
|
|
|
value: String
|
|
|
|
|
isTheorem?: Bool
|
|
|
|
|
deriving Lean.FromJson
|
|
|
|
|
structure EnvAddResult where
|
|
|
|
|
deriving Lean.ToJson
|
2023-05-25 13:40:03 -07:00
|
|
|
|
|
2023-08-16 19:25:32 -07:00
|
|
|
|
/-- Set options; See `Options` struct above for meanings -/
|
|
|
|
|
structure OptionsSet where
|
|
|
|
|
printJsonPretty?: Option Bool
|
|
|
|
|
printExprPretty?: Option Bool
|
|
|
|
|
printExprAST?: Option Bool
|
2023-10-26 22:47:42 -07:00
|
|
|
|
noRepeat?: Option Bool
|
2023-08-16 19:25:32 -07:00
|
|
|
|
printAuxDecls?: Option Bool
|
|
|
|
|
printImplementationDetailHyps?: Option Bool
|
2023-08-15 15:40:54 -07:00
|
|
|
|
deriving Lean.FromJson
|
2023-08-16 19:25:32 -07:00
|
|
|
|
structure OptionsSetResult where
|
2023-05-26 16:55:33 -07:00
|
|
|
|
deriving Lean.ToJson
|
2023-08-16 19:25:32 -07:00
|
|
|
|
structure OptionsPrint where
|
2023-05-25 13:40:03 -07:00
|
|
|
|
deriving Lean.FromJson
|
2023-08-16 19:25:32 -07:00
|
|
|
|
abbrev OptionsPrintResult := Options
|
2023-05-20 14:04:09 -07:00
|
|
|
|
|
2023-08-30 19:16:33 -07:00
|
|
|
|
structure GoalStart where
|
2023-05-21 17:41:39 -07:00
|
|
|
|
-- Only one of the fields below may be populated.
|
2023-10-15 17:15:23 -07:00
|
|
|
|
expr: Option String -- Directly parse in an expression
|
|
|
|
|
copyFrom: Option String -- Copy the type from a theorem in the environment
|
2023-05-17 21:58:03 -07:00
|
|
|
|
deriving Lean.FromJson
|
2023-08-30 19:16:33 -07:00
|
|
|
|
structure GoalStartResult where
|
2023-10-15 17:15:23 -07:00
|
|
|
|
stateId: Nat := 0
|
2023-11-06 11:51:31 -08:00
|
|
|
|
-- Name of the root metavariable
|
|
|
|
|
root: String
|
2023-05-21 17:41:39 -07:00
|
|
|
|
deriving Lean.ToJson
|
2023-08-30 19:16:33 -07:00
|
|
|
|
structure GoalTactic where
|
2023-05-22 19:45:08 -07:00
|
|
|
|
-- Identifiers for tree, state, and goal
|
2023-10-15 17:15:23 -07:00
|
|
|
|
stateId: Nat
|
|
|
|
|
goalId: Nat := 0
|
2023-10-27 15:32:59 -07:00
|
|
|
|
-- One of the fields here must be filled
|
|
|
|
|
tactic?: Option String := .none
|
|
|
|
|
expr?: Option String := .none
|
2023-05-21 17:41:39 -07:00
|
|
|
|
deriving Lean.FromJson
|
2023-08-30 19:16:33 -07:00
|
|
|
|
structure GoalTacticResult where
|
2023-10-15 17:15:23 -07:00
|
|
|
|
-- The next goal state id. Existence of this field shows success
|
|
|
|
|
nextStateId?: Option Nat := .none
|
|
|
|
|
-- If the array is empty, it shows the goals have been fully resolved.
|
2023-08-15 15:40:54 -07:00
|
|
|
|
goals?: Option (Array Goal) := .none
|
2023-10-15 17:15:23 -07:00
|
|
|
|
|
|
|
|
|
-- Existence of this field shows tactic execution failure
|
2023-08-15 15:40:54 -07:00
|
|
|
|
tacticErrors?: Option (Array String) := .none
|
2023-10-15 17:15:23 -07:00
|
|
|
|
|
|
|
|
|
-- Existence of this field shows the tactic parsing has failed
|
|
|
|
|
parseError?: Option String := .none
|
2023-05-21 17:41:39 -07:00
|
|
|
|
deriving Lean.ToJson
|
2023-11-04 15:51:09 -07:00
|
|
|
|
structure GoalContinue where
|
|
|
|
|
-- State from which the continuation acquires the context
|
|
|
|
|
target: Nat
|
|
|
|
|
|
|
|
|
|
-- One of the following must be supplied
|
|
|
|
|
-- The state which is an ancestor of `target` where goals will be extracted from
|
|
|
|
|
branch?: Option Nat := .none
|
|
|
|
|
-- Or, the particular goals that should be brought back into scope
|
|
|
|
|
goals?: Option (List String) := .none
|
|
|
|
|
deriving Lean.FromJson
|
|
|
|
|
structure GoalContinueResult where
|
2023-11-09 22:24:17 -08:00
|
|
|
|
nextStateId: Nat
|
|
|
|
|
goals: (Array Goal)
|
2023-11-04 15:51:09 -07:00
|
|
|
|
deriving Lean.ToJson
|
2023-08-27 19:53:09 -07:00
|
|
|
|
|
2023-10-15 17:15:23 -07:00
|
|
|
|
-- Remove goal states
|
2023-08-30 19:16:33 -07:00
|
|
|
|
structure GoalDelete where
|
2023-10-15 17:15:23 -07:00
|
|
|
|
stateIds: List Nat
|
2023-08-30 19:16:33 -07:00
|
|
|
|
deriving Lean.FromJson
|
|
|
|
|
structure GoalDeleteResult where
|
|
|
|
|
deriving Lean.ToJson
|
|
|
|
|
|
2023-10-15 17:15:23 -07:00
|
|
|
|
structure GoalPrint where
|
2023-10-27 15:41:12 -07:00
|
|
|
|
stateId: Nat
|
|
|
|
|
deriving Lean.FromJson
|
|
|
|
|
structure GoalPrintResult where
|
|
|
|
|
-- The root expression
|
2024-01-24 18:19:04 -08:00
|
|
|
|
root?: Option Expression := .none
|
2024-01-30 16:37:35 -08:00
|
|
|
|
-- The filling expression of the parent goal
|
2024-01-24 18:19:04 -08:00
|
|
|
|
parent?: Option Expression := .none
|
2023-10-27 15:41:12 -07:00
|
|
|
|
deriving Lean.ToJson
|
|
|
|
|
|
|
|
|
|
-- Diagnostic Options, not available in REPL
|
|
|
|
|
structure GoalDiag where
|
2023-10-15 17:15:23 -07:00
|
|
|
|
printContext: Bool := true
|
|
|
|
|
printValue: Bool := true
|
2023-10-25 16:03:45 -07:00
|
|
|
|
printNewMVars: Bool := false
|
2023-10-27 15:15:22 -07:00
|
|
|
|
-- Print all mvars
|
|
|
|
|
printAll: Bool := false
|
2024-01-16 16:44:54 -08:00
|
|
|
|
instantiate: Bool := true
|
2023-10-15 17:15:23 -07:00
|
|
|
|
|
2024-01-24 18:19:04 -08:00
|
|
|
|
abbrev CR α := Except InteractionError α
|
2023-05-17 21:58:03 -07:00
|
|
|
|
|
2023-10-15 17:15:23 -07:00
|
|
|
|
end Pantograph.Protocol
|