Pantograph/Pantograph/Protocol.lean

304 lines
8.7 KiB
Plaintext
Raw Normal View History

/-
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
namespace Pantograph.Protocol
2023-05-09 18:01:09 -07:00
/-- Main Option structure, placed here to avoid name collision -/
structure Options where
-- 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
-- When enabled, pretty print every expression
printExprPretty: Bool := true
-- When enabled, print the raw AST of expressions
printExprAST: Bool := false
2024-04-12 20:51:54 -07:00
printDependentMVars: Bool := false
-- 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
-- See `pp.auxDecls`
printAuxDecls: Bool := false
-- See `pp.implementationDetailHyps`
printImplementationDetailHyps: Bool := false
deriving Lean.ToJson
2023-08-14 21:43:40 -07:00
abbrev OptionsT := ReaderT Options
--- 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
2024-04-12 20:51:54 -07:00
dependentMVars?: Option (Array String) := .none
deriving Lean.ToJson
structure Variable where
/-- The internal name used in raw expressions -/
name: String := ""
/-- The name displayed to the user -/
userName: String
/-- Does the name contain a dagger -/
isInaccessible?: Option Bool := .some false
type?: Option Expression := .none
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
/-- 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 ---
structure Command where
cmd: String
payload: Lean.Json
deriving Lean.FromJson
structure InteractionError where
error: String
desc: String
deriving Lean.ToJson
def errorIndex (desc: String): InteractionError := { error := "index", desc }
def errorExpr (desc: String): InteractionError := { error := "expr", desc }
2023-08-13 21:19:06 -07:00
--- Individual command and return types ---
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
-- Return the type of an expression
structure ExprEcho where
expr: String
2024-03-31 16:43:30 -07:00
type?: Option String
-- universe levels
levels: Option (Array String) := .none
deriving Lean.FromJson
structure ExprEchoResult where
expr: Expression
type: Expression
deriving Lean.ToJson
2023-05-17 21:58:03 -07:00
-- Print all symbols in environment
structure EnvCatalog where
2023-05-17 21:58:03 -07:00
deriving Lean.FromJson
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
-- Print the type of a symbol
structure EnvInspect where
2023-05-22 19:45:08 -07:00
name: String
-- If true/false, show/hide the value expressions; By default definitions
-- values are shown and theorem values are hidden.
value?: Option Bool := .some false
-- If true, show the type and value dependencies
dependency?: Option Bool := .some false
deriving Lean.FromJson
2024-01-16 13:29:30 -08:00
-- See `InductiveVal`
structure InductInfo where
numParams: Nat
numIndices: Nat
2024-03-14 22:40:14 -07:00
all: Array String
ctors: Array String
2024-01-16 13:29:30 -08:00
isRec: Bool := false
isReflexive: Bool := false
isNested: Bool := false
deriving Lean.ToJson
-- See `ConstructorVal`
structure ConstructorInfo where
induct: String
cidx: Nat
numParams: Nat
numFields: Nat
deriving Lean.ToJson
2024-04-09 21:24:08 -07:00
/-- See `Lean/Declaration.lean` -/
structure RecursorRule where
ctor: String
nFields: Nat
rhs: Expression
deriving Lean.ToJson
structure RecursorInfo where
2024-03-14 22:40:14 -07:00
all: Array String
numParams: Nat
numIndices: Nat
numMotives: Nat
numMinors: Nat
2024-04-09 21:24:08 -07:00
rules: Array RecursorRule
k: Bool
deriving Lean.ToJson
structure EnvInspectResult where
type: Expression
isUnsafe: Bool := false
value?: Option Expression := .none
module?: Option String := .none
-- If the name is private, displays the public facing name
publicName?: Option String := .none
typeDependency?: Option (Array String) := .none
valueDependency?: Option (Array String) := .none
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
2023-12-13 19:35:32 -08:00
deriving Lean.FromJson
structure EnvAddResult where
deriving Lean.ToJson
2023-05-25 13:40:03 -07:00
/-- Set options; See `Options` struct above for meanings -/
structure OptionsSet where
printJsonPretty?: Option Bool
printExprPretty?: Option Bool
printExprAST?: Option Bool
2024-04-12 20:51:54 -07:00
printDependentMVars?: Option Bool
noRepeat?: Option Bool
printAuxDecls?: Option Bool
printImplementationDetailHyps?: Option Bool
deriving Lean.FromJson
structure OptionsSetResult where
deriving Lean.ToJson
structure OptionsPrint where
2023-05-25 13:40:03 -07:00
deriving Lean.FromJson
structure GoalStart where
2023-05-21 17:41:39 -07:00
-- Only one of the fields below may be populated.
expr: Option String -- Directly parse in an expression
-- universe levels
levels: Option (Array String) := .none
copyFrom: Option String -- Copy the type from a theorem in the environment
2023-05-17 21:58:03 -07:00
deriving Lean.FromJson
structure GoalStartResult where
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
structure GoalTactic where
2023-05-22 19:45:08 -07:00
-- Identifiers for tree, state, and goal
stateId: Nat
goalId: Nat := 0
-- One of the fields here must be filled
tactic?: Option String := .none
expr?: Option String := .none
2024-04-06 16:40:22 -07:00
have?: Option String := .none
2024-04-11 15:11:10 -07:00
calc?: Option String := .none
-- true to enter `conv`, `false` to exit. In case of exit the `goalId` is ignored.
conv?: Option Bool := .none
2024-04-06 16:40:22 -07:00
2024-04-11 15:11:10 -07:00
-- In case of the `have` tactic, the new free variable name is provided here
2024-04-06 16:40:22 -07:00
binderName?: Option String := .none
2023-05-21 17:41:39 -07:00
deriving Lean.FromJson
structure GoalTacticResult where
-- 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.
goals?: Option (Array Goal) := .none
-- Existence of this field shows tactic execution failure
tacticErrors?: Option (Array String) := .none
-- 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
2024-03-10 08:13:10 -07:00
goals?: Option (Array String) := .none
2023-11-04 15:51:09 -07:00
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
-- Remove goal states
structure GoalDelete where
2024-03-14 22:40:14 -07:00
-- This is ok being a List because it doesn't show up in the ABI
stateIds: List Nat
deriving Lean.FromJson
structure GoalDeleteResult where
deriving Lean.ToJson
structure GoalPrint where
stateId: Nat
deriving Lean.FromJson
structure GoalPrintResult where
-- The root expression
root?: Option Expression := .none
-- The filling expression of the parent goal
2024-03-06 15:14:08 -08:00
parent?: Option Expression
deriving Lean.ToJson
-- Diagnostic Options, not available in REPL
structure GoalDiag where
printContext: Bool := true
printValue: Bool := true
printNewMVars: Bool := false
-- Print all mvars
printAll: Bool := false
instantiate: Bool := true
2024-06-05 15:56:20 -07:00
printSexp: Bool := false
/-- Executes the Lean compiler on a single file -/
structure CompileUnit where
module: String
-- If set to true, query the string boundaries of compilation units
compilationUnits: Bool := false
-- If set to true, collect tactic invocations
invocations: Bool := false
deriving Lean.FromJson
structure InvokedTactic where
goalBefore: String
goalAfter: String
tactic: String
deriving Lean.ToJson
structure CompileUnitResult where
units?: Option $ List (Nat × Nat)
invocations?: Option $ List InvokedTactic
deriving Lean.ToJson
abbrev CR α := Except InteractionError α
2023-05-17 21:58:03 -07:00
end Pantograph.Protocol