0 | module Protocol.IDE.Result
4 | import Protocol.IDE.Holes
5 | import Protocol.IDE.FileContext
13 | data OptionType = BOOL | STRING | ATOM
16 | (.sem) : OptionType -> Type
18 | STRING .sem = String
21 | %unbound_implicits off
23 | record REPLOption where
24 | constructor MkOption
28 | %unbound_implicits on
30 | sexpOptionVal : {type : OptionType} -> type.sem -> SExp
31 | sexpOptionVal {type = BOOL } = toSExp
32 | sexpOptionVal {type = STRING} = toSExp
33 | sexpOptionVal {type = ATOM } = toSExp
36 | SExpable REPLOption where
37 | toSExp opt@(MkOption {}) = SExpList
38 | [ SymbolAtom opt.name
39 | , sexpOptionVal opt.val
43 | FromSExpable REPLOption where
48 | let Nothing = fromSExp val
49 | | Just val => Just $
MkOption {name, type = BOOL, val}
50 | let Nothing = fromSExp val
51 | | Just val => Just $
MkOption {name, type = STRING, val}
53 | Just $
MkOption {name, type = ATOM, val}
54 | fromSExp _ = Nothing
57 | record MetaVarLemma where
58 | constructor MkMetaVarLemma
59 | application, lemma : String
62 | SExpable MetaVarLemma where
63 | toSExp mvl = SExpList [ SymbolAtom "metavariable-lemma"
64 | , SExpList [ SymbolAtom "replace-metavariable", StringAtom mvl.application ]
65 | , SExpList [ SymbolAtom "definition-type", StringAtom mvl.lemma ]
69 | FromSExpable MetaVarLemma where
70 | fromSExp (SExpList [ SymbolAtom "metavariable-lemma"
71 | , SExpList [ SymbolAtom "replace-metavariable", StringAtom application ]
72 | , SExpList [ SymbolAtom "definition-type", StringAtom lemma ]
73 | ]) = Just $
MkMetaVarLemma {application, lemma}
74 | fromSExp _ = Nothing
77 | record IdrisVersion where
78 | constructor MkIdrisVersion
79 | major, minor, patch : Nat
83 | SExpable IdrisVersion where
84 | toSExp version = SExpList
85 | [ SExpList (map toSExp [version.major, version.minor, version.patch])
86 | , SExpList [StringAtom $
fromMaybe "" version.tag]
90 | FromSExpable IdrisVersion where
92 | [ SExpList [majorSExp, minorSExp, patchSExp]
93 | , SExpList [StringAtom tagSExp]
94 | ]) = do pure $
MkIdrisVersion
95 | { major = !(fromSExp majorSExp)
96 | , minor = !(fromSExp minorSExp)
97 | , patch = !(fromSExp patchSExp)
98 | , tag = case tagSExp of
101 | fromSExp _ = Nothing
107 | | AVersion IdrisVersion
108 | | AMetaVarLemma MetaVarLemma
109 | | ANameLocList (List (String, FileContext))
110 | | AHoleList (List HoleData)
111 | | ACompletionList (List String) String
112 | | ANameList (List String)
113 | | AnOptionList (List REPLOption)
114 | | AnIntroList (List1 String)
117 | SExpable Result where
118 | toSExp (AString s) = toSExp s
119 | toSExp (AUnit ) = toSExp (the (List Int) [])
120 | toSExp (AVersion version) = toSExp version
121 | toSExp (AMetaVarLemma mvl) = toSExp mvl
122 | toSExp (ANameLocList fcs) = toSExp fcs
123 | toSExp (AHoleList holes) = toSExp holes
124 | toSExp (ANameList names) = SExpList (map StringAtom names)
125 | toSExp (ACompletionList names str) = SExpList [SExpList (map StringAtom names), StringAtom str]
126 | toSExp (AnOptionList opts) = toSExp opts
127 | toSExp (AnIntroList iss) = toSExp iss
132 | FromSExpable Result where
133 | fromSExp (SExpList []) = Just AUnit
135 | let Nothing = fromSExp sexp
136 | | Just str => pure $
AString str
137 | let Nothing = fromSExp sexp
138 | | Just version => pure $
AVersion version
139 | let Nothing = fromSExp sexp
140 | | Just mvl => pure $
AMetaVarLemma mvl
141 | let Nothing = fromSExp sexp
142 | | Just nll => pure $
ANameLocList nll
143 | let Nothing = fromSExp sexp
144 | | Just hl => pure $
AHoleList hl
145 | let Nothing = fromSExp sexp
146 | | Just nl => pure $
ANameList nl
147 | let Nothing = fromSExp sexp
148 | | Just nlr => pure $
uncurry ACompletionList nlr
149 | let Nothing = fromSExp sexp
150 | | Just optl => pure $
AnOptionList optl
151 | let Nothing = fromSExp sexp
152 | | Just optl => pure $
AnIntroList optl