2023-03-05 08:55:04 -05:00
|
|
|
module Quox.Parser.Syntax
|
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
import public Quox.Loc
|
2023-03-05 08:55:04 -05:00
|
|
|
import public Quox.Syntax
|
2023-03-06 05:35:57 -05:00
|
|
|
import public Quox.Definition
|
2023-03-05 08:55:04 -05:00
|
|
|
|
|
|
|
import Derive.Prelude
|
|
|
|
%hide TT.Name
|
|
|
|
|
|
|
|
%default total
|
|
|
|
%language ElabReflection
|
|
|
|
|
|
|
|
|
|
|
|
public export
|
2023-04-25 20:47:42 -04:00
|
|
|
data PatVar = Unused Loc | PV PBaseName Loc
|
|
|
|
%name PatVar v
|
|
|
|
%runElab derive "PatVar" [Eq, Ord, Show]
|
|
|
|
|
|
|
|
export
|
|
|
|
Located PatVar where
|
|
|
|
(Unused loc).loc = loc
|
|
|
|
(PV _ loc).loc = loc
|
|
|
|
|
|
|
|
export
|
|
|
|
(.name) : PatVar -> Maybe PBaseName
|
|
|
|
(Unused _).name = Nothing
|
|
|
|
(PV nm _).name = Just nm
|
|
|
|
|
|
|
|
export
|
|
|
|
isUnused : PatVar -> Bool
|
|
|
|
isUnused (Unused {}) = True
|
|
|
|
isUnused _ = False
|
|
|
|
|
2023-03-05 08:55:04 -05:00
|
|
|
|
|
|
|
public export
|
2023-05-01 21:06:25 -04:00
|
|
|
record PQty where
|
|
|
|
constructor PQ
|
|
|
|
val : Qty
|
|
|
|
loc_ : Loc
|
2023-04-25 20:47:42 -04:00
|
|
|
%name PQty qty
|
|
|
|
%runElab derive "PQty" [Eq, Ord, Show]
|
|
|
|
|
2023-05-01 21:06:25 -04:00
|
|
|
export Located PQty where q.loc = q.loc_
|
2023-03-05 08:55:04 -05:00
|
|
|
|
|
|
|
namespace PDim
|
|
|
|
public export
|
2023-04-25 20:47:42 -04:00
|
|
|
data PDim = K DimConst Loc | V PBaseName Loc
|
2023-03-05 10:49:50 -05:00
|
|
|
%name PDim p, q
|
2023-03-05 08:55:04 -05:00
|
|
|
%runElab derive "PDim" [Eq, Ord, Show]
|
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
export
|
|
|
|
Located PDim where
|
|
|
|
(K _ loc).loc = loc
|
|
|
|
(V _ loc).loc = loc
|
|
|
|
|
|
|
|
public export
|
|
|
|
data PTagVal = PT TagVal Loc
|
|
|
|
%name PTagVal tag
|
|
|
|
%runElab derive "PTagVal" [Eq, Ord, Show]
|
|
|
|
|
|
|
|
|
2023-03-05 08:55:04 -05:00
|
|
|
namespace PTerm
|
|
|
|
mutual
|
|
|
|
||| terms out of the parser with BVs and bidirectionality still tangled up
|
|
|
|
public export
|
|
|
|
data PTerm =
|
2023-04-25 20:47:42 -04:00
|
|
|
TYPE Universe Loc
|
2023-03-05 08:55:04 -05:00
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
| Pi PQty PatVar PTerm PTerm Loc
|
|
|
|
| Lam PatVar PTerm Loc
|
|
|
|
| App PTerm PTerm Loc
|
2023-03-05 08:55:04 -05:00
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
| Sig PatVar PTerm PTerm Loc
|
|
|
|
| Pair PTerm PTerm Loc
|
|
|
|
| Case PQty PTerm (PatVar, PTerm) PCaseBody Loc
|
2023-09-18 15:52:51 -04:00
|
|
|
| Fst PTerm Loc | Snd PTerm Loc
|
2023-03-05 08:55:04 -05:00
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
| Enum (List TagVal) Loc
|
|
|
|
| Tag TagVal Loc
|
2023-03-05 08:55:04 -05:00
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
| Eq (PatVar, PTerm) PTerm PTerm Loc
|
|
|
|
| DLam PatVar PTerm Loc
|
|
|
|
| DApp PTerm PDim Loc
|
2023-03-05 08:55:04 -05:00
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
| Nat Loc
|
|
|
|
| Zero Loc | Succ PTerm Loc
|
2023-03-26 08:40:54 -04:00
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
| BOX PQty PTerm Loc
|
|
|
|
| Box PTerm Loc
|
2023-03-31 13:11:35 -04:00
|
|
|
|
2023-05-21 14:09:34 -04:00
|
|
|
| V PName (Maybe Universe) Loc
|
2023-04-25 20:47:42 -04:00
|
|
|
| Ann PTerm PTerm Loc
|
2023-04-15 09:13:01 -04:00
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
| Coe (PatVar, PTerm) PDim PDim PTerm Loc
|
|
|
|
| Comp (PatVar, PTerm) PDim PDim PTerm PDim
|
|
|
|
(PatVar, PTerm) (PatVar, PTerm) Loc
|
2023-03-05 10:49:50 -05:00
|
|
|
%name PTerm s, t
|
2023-03-05 08:55:04 -05:00
|
|
|
|
|
|
|
public export
|
|
|
|
data PCaseBody =
|
2023-04-25 20:47:42 -04:00
|
|
|
CasePair (PatVar, PatVar) PTerm Loc
|
|
|
|
| CaseEnum (List (PTagVal, PTerm)) Loc
|
|
|
|
| CaseNat PTerm (PatVar, PQty, PatVar, PTerm) Loc
|
|
|
|
| CaseBox PatVar PTerm Loc
|
2023-03-05 10:49:50 -05:00
|
|
|
%name PCaseBody body
|
2023-03-05 08:55:04 -05:00
|
|
|
|
|
|
|
%runElab deriveMutual ["PTerm", "PCaseBody"] [Eq, Ord, Show]
|
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
export
|
|
|
|
Located PTerm where
|
|
|
|
(TYPE _ loc).loc = loc
|
|
|
|
(Pi _ _ _ _ loc).loc = loc
|
|
|
|
(Lam _ _ loc).loc = loc
|
|
|
|
(App _ _ loc).loc = loc
|
|
|
|
(Sig _ _ _ loc).loc = loc
|
|
|
|
(Pair _ _ loc).loc = loc
|
2023-09-18 15:52:51 -04:00
|
|
|
(Fst _ loc).loc = loc
|
|
|
|
(Snd _ loc).loc = loc
|
2023-04-25 20:47:42 -04:00
|
|
|
(Case _ _ _ _ loc).loc = loc
|
|
|
|
(Enum _ loc).loc = loc
|
|
|
|
(Tag _ loc).loc = loc
|
|
|
|
(Eq _ _ _ loc).loc = loc
|
|
|
|
(DLam _ _ loc).loc = loc
|
|
|
|
(DApp _ _ loc).loc = loc
|
|
|
|
(Nat loc).loc = loc
|
|
|
|
(Zero loc).loc = loc
|
|
|
|
(Succ _ loc).loc = loc
|
|
|
|
(BOX _ _ loc).loc = loc
|
|
|
|
(Box _ loc).loc = loc
|
2023-05-21 14:09:34 -04:00
|
|
|
(V _ _ loc).loc = loc
|
2023-04-25 20:47:42 -04:00
|
|
|
(Ann _ _ loc).loc = loc
|
|
|
|
(Coe _ _ _ _ loc).loc = loc
|
|
|
|
(Comp _ _ _ _ _ _ _ loc).loc = loc
|
|
|
|
|
|
|
|
export
|
|
|
|
Located PCaseBody where
|
|
|
|
(CasePair _ _ loc).loc = loc
|
|
|
|
(CaseEnum _ loc).loc = loc
|
|
|
|
(CaseNat _ _ loc).loc = loc
|
|
|
|
(CaseBox _ _ loc).loc = loc
|
|
|
|
|
2023-03-05 08:55:04 -05:00
|
|
|
|
2023-03-06 05:35:57 -05:00
|
|
|
public export
|
|
|
|
record PDefinition where
|
|
|
|
constructor MkPDef
|
2023-04-25 20:47:42 -04:00
|
|
|
qty : PQty
|
2023-04-24 16:25:00 -04:00
|
|
|
name : PBaseName
|
2023-03-12 13:28:37 -04:00
|
|
|
type : Maybe PTerm
|
2023-03-06 05:35:57 -05:00
|
|
|
term : PTerm
|
2023-04-25 20:47:42 -04:00
|
|
|
loc_ : Loc
|
2023-03-06 05:35:57 -05:00
|
|
|
%name PDefinition def
|
|
|
|
%runElab derive "PDefinition" [Eq, Ord, Show]
|
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
export Located PDefinition where def.loc = def.loc_
|
|
|
|
|
2023-03-12 13:28:37 -04:00
|
|
|
mutual
|
|
|
|
public export
|
|
|
|
record PNamespace where
|
|
|
|
constructor MkPNamespace
|
|
|
|
name : Mods
|
|
|
|
decls : List PDecl
|
2023-04-25 20:47:42 -04:00
|
|
|
loc_ : Loc
|
2023-03-12 13:28:37 -04:00
|
|
|
%name PNamespace ns
|
|
|
|
|
|
|
|
public export
|
|
|
|
data PDecl =
|
|
|
|
PDef PDefinition
|
|
|
|
| PNs PNamespace
|
|
|
|
%name PDecl decl
|
|
|
|
%runElab deriveMutual ["PNamespace", "PDecl"] [Eq, Ord, Show]
|
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
export Located PNamespace where ns.loc = ns.loc_
|
|
|
|
|
|
|
|
export
|
|
|
|
Located PDecl where
|
|
|
|
(PDef def).loc = def.loc
|
|
|
|
(PNs ns).loc = ns.loc
|
|
|
|
|
2023-03-12 13:28:37 -04:00
|
|
|
public export
|
2023-04-25 20:47:42 -04:00
|
|
|
data PTopLevel = PD PDecl | PLoad String Loc
|
2023-03-12 13:28:37 -04:00
|
|
|
%name PTopLevel t
|
|
|
|
%runElab derive "PTopLevel" [Eq, Ord, Show]
|
|
|
|
|
2023-03-05 08:55:04 -05:00
|
|
|
export
|
2023-04-25 20:47:42 -04:00
|
|
|
Located PTopLevel where
|
|
|
|
(PD decl).loc = decl.loc
|
|
|
|
(PLoad _ loc).loc = loc
|
2023-03-05 08:55:04 -05:00
|
|
|
|
|
|
|
|
2023-04-03 11:46:23 -04:00
|
|
|
public export
|
2023-04-25 20:47:42 -04:00
|
|
|
fromNat : Nat -> Loc -> PTerm
|
|
|
|
fromNat 0 loc = Zero loc
|
|
|
|
fromNat (S k) loc = Succ (fromNat k loc) loc
|