Pantograph/Pantograph/Protocol.lean

260 lines
7.4 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
-- 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
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 := .none
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
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
all: List String
ctors: List String
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
structure RecursorInfo where
all: List String
numParams: Nat
numIndices: Nat
numMotives: Nat
numMinors: Nat
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
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
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
abbrev OptionsPrintResult := Options
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
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
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
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
-- Remove goal states
structure GoalDelete where
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
-- How is this goal filled in relation to its children?
parent?: Option Expression := .none
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
abbrev CR α := Except InteractionError α
2023-05-17 21:58:03 -07:00
end Pantograph.Protocol