add PrettyVal stuff for parser AST
This commit is contained in:
parent
0c1df54d62
commit
52e54dcc3c
8 changed files with 51 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
||||||
package quox
|
package quox
|
||||||
version = 0
|
version = 0
|
||||||
|
|
||||||
depends = base, contrib, elab-util, sop, quox-lib
|
depends = base, contrib, elab-util, pretty-show, quox-lib
|
||||||
|
|
||||||
executable = quox
|
executable = quox
|
||||||
main = Main
|
main = Main
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
||| file locations
|
||| file locations
|
||||||
module Quox.Loc
|
module Quox.Loc
|
||||||
|
|
||||||
|
import Quox.PrettyValExtra
|
||||||
import public Text.Bounded
|
import public Text.Bounded
|
||||||
import Data.SortedMap
|
import Data.SortedMap
|
||||||
import Derive.Prelude
|
import Derive.Prelude
|
||||||
|
@ -12,12 +13,12 @@ public export
|
||||||
FileName : Type
|
FileName : Type
|
||||||
FileName = String
|
FileName = String
|
||||||
|
|
||||||
%runElab derive "Bounds" [Ord]
|
%runElab derive "Bounds" [Ord, PrettyVal]
|
||||||
|
|
||||||
public export
|
public export
|
||||||
data Loc_ = NoLoc | YesLoc FileName Bounds
|
data Loc_ = NoLoc | YesLoc FileName Bounds
|
||||||
%name Loc_ loc
|
%name Loc_ loc
|
||||||
%runElab derive "Loc_" [Eq, Ord, Show]
|
%runElab derive "Loc_" [Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
|
|
||||||
||| a wrapper for locations which are always considered equal
|
||| a wrapper for locations which are always considered equal
|
||||||
|
@ -39,6 +40,18 @@ public export %inline
|
||||||
makeLoc : FileName -> Bounds -> Loc
|
makeLoc : FileName -> Bounds -> Loc
|
||||||
makeLoc = L .: YesLoc
|
makeLoc = L .: YesLoc
|
||||||
|
|
||||||
|
public export %inline
|
||||||
|
loc : FileName -> (sl, sc, el, ec : Int) -> Loc
|
||||||
|
loc file sl sc el ec = makeLoc file $ MkBounds sl sc el ec
|
||||||
|
|
||||||
|
export
|
||||||
|
PrettyVal Loc where
|
||||||
|
prettyVal (L NoLoc) = Con "noLoc" []
|
||||||
|
prettyVal (L (YesLoc file (MkBounds sl sc el ec))) =
|
||||||
|
Con "loc" [prettyVal file,
|
||||||
|
prettyVal sl, prettyVal sc,
|
||||||
|
prettyVal el, prettyVal ec]
|
||||||
|
|
||||||
|
|
||||||
export
|
export
|
||||||
onlyStart_ : Loc_ -> Loc_
|
onlyStart_ : Loc_ -> Loc_
|
||||||
|
|
|
@ -2,6 +2,7 @@ module Quox.Name
|
||||||
|
|
||||||
import Quox.Loc
|
import Quox.Loc
|
||||||
import Quox.CharExtra
|
import Quox.CharExtra
|
||||||
|
import Quox.PrettyValExtra
|
||||||
import public Data.SnocList
|
import public Data.SnocList
|
||||||
import Data.List
|
import Data.List
|
||||||
import Control.Eff
|
import Control.Eff
|
||||||
|
@ -23,7 +24,7 @@ data BaseName
|
||||||
= UN String -- user-given name
|
= UN String -- user-given name
|
||||||
| MN String NameSuf -- machine-generated name
|
| MN String NameSuf -- machine-generated name
|
||||||
| Unused -- "_"
|
| Unused -- "_"
|
||||||
%runElab derive "BaseName" [Eq, Ord]
|
%runElab derive "BaseName" [Eq, Ord, PrettyVal]
|
||||||
|
|
||||||
export
|
export
|
||||||
baseStr : BaseName -> String
|
baseStr : BaseName -> String
|
||||||
|
@ -66,7 +67,7 @@ record PName where
|
||||||
constructor MakePName
|
constructor MakePName
|
||||||
mods : Mods
|
mods : Mods
|
||||||
base : PBaseName
|
base : PBaseName
|
||||||
%runElab derive "PName" [Eq, Ord]
|
%runElab derive "PName" [Eq, Ord, PrettyVal]
|
||||||
|
|
||||||
export %inline
|
export %inline
|
||||||
fromPName : PName -> Name
|
fromPName : PName -> Name
|
||||||
|
@ -97,7 +98,7 @@ record BindName where
|
||||||
constructor BN
|
constructor BN
|
||||||
val : BaseName
|
val : BaseName
|
||||||
loc_ : Loc
|
loc_ : Loc
|
||||||
%runElab derive "BindName" [Eq, Ord, Show]
|
%runElab derive "BindName" [Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
export Located BindName where n.loc = n.loc_
|
export Located BindName where n.loc = n.loc_
|
||||||
export Relocatable BindName where setLoc loc (BN x _) = BN x loc
|
export Relocatable BindName where setLoc loc (BN x _) = BN x loc
|
||||||
|
|
|
@ -3,6 +3,7 @@ module Quox.Parser.Syntax
|
||||||
import public Quox.Loc
|
import public Quox.Loc
|
||||||
import public Quox.Syntax
|
import public Quox.Syntax
|
||||||
import public Quox.Definition
|
import public Quox.Definition
|
||||||
|
import Quox.PrettyValExtra
|
||||||
|
|
||||||
import Derive.Prelude
|
import Derive.Prelude
|
||||||
%hide TT.Name
|
%hide TT.Name
|
||||||
|
@ -14,7 +15,7 @@ import Derive.Prelude
|
||||||
public export
|
public export
|
||||||
data PatVar = Unused Loc | PV PBaseName Loc
|
data PatVar = Unused Loc | PV PBaseName Loc
|
||||||
%name PatVar v
|
%name PatVar v
|
||||||
%runElab derive "PatVar" [Eq, Ord, Show]
|
%runElab derive "PatVar" [Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
export
|
export
|
||||||
Located PatVar where
|
Located PatVar where
|
||||||
|
@ -38,7 +39,7 @@ record PQty where
|
||||||
val : Qty
|
val : Qty
|
||||||
loc_ : Loc
|
loc_ : Loc
|
||||||
%name PQty qty
|
%name PQty qty
|
||||||
%runElab derive "PQty" [Eq, Ord, Show]
|
%runElab derive "PQty" [Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
export Located PQty where q.loc = q.loc_
|
export Located PQty where q.loc = q.loc_
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ namespace PDim
|
||||||
public export
|
public export
|
||||||
data PDim = K DimConst Loc | V PBaseName Loc
|
data PDim = K DimConst Loc | V PBaseName Loc
|
||||||
%name PDim p, q
|
%name PDim p, q
|
||||||
%runElab derive "PDim" [Eq, Ord, Show]
|
%runElab derive "PDim" [Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
export
|
export
|
||||||
Located PDim where
|
Located PDim where
|
||||||
|
@ -56,7 +57,7 @@ Located PDim where
|
||||||
public export
|
public export
|
||||||
data PTagVal = PT TagVal Loc
|
data PTagVal = PT TagVal Loc
|
||||||
%name PTagVal tag
|
%name PTagVal tag
|
||||||
%runElab derive "PTagVal" [Eq, Ord, Show]
|
%runElab derive "PTagVal" [Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
|
|
||||||
namespace PTerm
|
namespace PTerm
|
||||||
|
@ -104,7 +105,7 @@ namespace PTerm
|
||||||
| CaseBox PatVar PTerm Loc
|
| CaseBox PatVar PTerm Loc
|
||||||
%name PCaseBody body
|
%name PCaseBody body
|
||||||
|
|
||||||
%runElab deriveMutual ["PTerm", "PCaseBody"] [Eq, Ord, Show]
|
%runElab deriveMutual ["PTerm", "PCaseBody"] [Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
export
|
export
|
||||||
Located PTerm where
|
Located PTerm where
|
||||||
|
@ -149,7 +150,7 @@ record PDefinition where
|
||||||
term : PTerm
|
term : PTerm
|
||||||
loc_ : Loc
|
loc_ : Loc
|
||||||
%name PDefinition def
|
%name PDefinition def
|
||||||
%runElab derive "PDefinition" [Eq, Ord, Show]
|
%runElab derive "PDefinition" [Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
export Located PDefinition where def.loc = def.loc_
|
export Located PDefinition where def.loc = def.loc_
|
||||||
|
|
||||||
|
@ -157,7 +158,7 @@ public export
|
||||||
data PDeclMod =
|
data PDeclMod =
|
||||||
PFail (Maybe String) Loc
|
PFail (Maybe String) Loc
|
||||||
%name PDeclMod mod
|
%name PDeclMod mod
|
||||||
%runElab derive "PDeclMod" [Eq, Ord, Show]
|
%runElab derive "PDeclMod" [Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
mutual
|
mutual
|
||||||
public export
|
public export
|
||||||
|
@ -180,7 +181,8 @@ mutual
|
||||||
PDef PDefinition
|
PDef PDefinition
|
||||||
| PNs PNamespace
|
| PNs PNamespace
|
||||||
%name PDeclBody decl
|
%name PDeclBody decl
|
||||||
%runElab deriveMutual ["PNamespace", "PDecl", "PDeclBody"] [Eq, Ord, Show]
|
%runElab deriveMutual ["PNamespace", "PDecl", "PDeclBody"]
|
||||||
|
[Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
export Located PNamespace where ns.loc = ns.loc_
|
export Located PNamespace where ns.loc = ns.loc_
|
||||||
|
|
||||||
|
@ -194,7 +196,7 @@ Located PDeclBody where
|
||||||
public export
|
public export
|
||||||
data PTopLevel = PD PDecl | PLoad String Loc
|
data PTopLevel = PD PDecl | PLoad String Loc
|
||||||
%name PTopLevel t
|
%name PTopLevel t
|
||||||
%runElab derive "PTopLevel" [Eq, Ord, Show]
|
%runElab derive "PTopLevel" [Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
export
|
export
|
||||||
Located PTopLevel where
|
Located PTopLevel where
|
||||||
|
|
10
lib/Quox/PrettyValExtra.idr
Normal file
10
lib/Quox/PrettyValExtra.idr
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
module Quox.PrettyValExtra
|
||||||
|
|
||||||
|
import Derive.Prelude
|
||||||
|
import public Text.Show.Value
|
||||||
|
import public Text.Show.PrettyVal
|
||||||
|
import public Text.Show.PrettyVal.Derive
|
||||||
|
|
||||||
|
%language ElabReflection
|
||||||
|
|
||||||
|
%runElab derive "SnocList" [PrettyVal]
|
|
@ -6,6 +6,7 @@ import Quox.Var
|
||||||
import Quox.Syntax.Subst
|
import Quox.Syntax.Subst
|
||||||
import Quox.Pretty
|
import Quox.Pretty
|
||||||
import Quox.Context
|
import Quox.Context
|
||||||
|
import Quox.PrettyValExtra
|
||||||
|
|
||||||
import Decidable.Equality
|
import Decidable.Equality
|
||||||
import Control.Function
|
import Control.Function
|
||||||
|
@ -18,7 +19,7 @@ import Derive.Prelude
|
||||||
public export
|
public export
|
||||||
data DimConst = Zero | One
|
data DimConst = Zero | One
|
||||||
%name DimConst e
|
%name DimConst e
|
||||||
%runElab derive "DimConst" [Eq, Ord, Show]
|
%runElab derive "DimConst" [Eq, Ord, Show, PrettyVal]
|
||||||
|
|
||||||
||| `ends l r e` returns `l` if `e` is `Zero`, or `r` if it is `One`.
|
||| `ends l r e` returns `l` if `e` is `Zero`, or `r` if it is `One`.
|
||||||
public export
|
public export
|
||||||
|
|
|
@ -6,6 +6,7 @@ module Quox.Syntax.Qty
|
||||||
|
|
||||||
import Quox.Pretty
|
import Quox.Pretty
|
||||||
import Quox.Decidable
|
import Quox.Decidable
|
||||||
|
import Quox.PrettyValExtra
|
||||||
import Data.DPair
|
import Data.DPair
|
||||||
import Derive.Prelude
|
import Derive.Prelude
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ import Derive.Prelude
|
||||||
||| - ω (or #): don't care. an ω variable *can* also be used 0/1 time
|
||| - ω (or #): don't care. an ω variable *can* also be used 0/1 time
|
||||||
public export
|
public export
|
||||||
data Qty = Zero | One | Any
|
data Qty = Zero | One | Any
|
||||||
%runElab derive "Qty" [Eq, Ord, Show]
|
%runElab derive "Qty" [Eq, Ord, Show, PrettyVal]
|
||||||
%name Qty.Qty pi, rh
|
%name Qty.Qty pi, rh
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +80,7 @@ lub p q = if p == q then p else Any
|
||||||
||| for the subject of a typing judgment. see @qtt, §2.3 for more detail
|
||| for the subject of a typing judgment. see @qtt, §2.3 for more detail
|
||||||
public export
|
public export
|
||||||
data SQty = SZero | SOne
|
data SQty = SZero | SOne
|
||||||
%runElab derive "SQty" [Eq, Ord, Show]
|
%runElab derive "SQty" [Eq, Ord, Show, PrettyVal]
|
||||||
%name Qty.SQty sg
|
%name Qty.SQty sg
|
||||||
|
|
||||||
||| "σ ⨴ π"
|
||| "σ ⨴ π"
|
||||||
|
@ -96,7 +97,7 @@ subjMult sg _ = sg
|
||||||
||| at runtime at all or not
|
||| at runtime at all or not
|
||||||
public export
|
public export
|
||||||
data GQty = GZero | GAny
|
data GQty = GZero | GAny
|
||||||
%runElab derive "GQty" [Eq, Ord, Show]
|
%runElab derive "GQty" [Eq, Ord, Show, PrettyVal]
|
||||||
%name GQty rh
|
%name GQty rh
|
||||||
|
|
||||||
public export
|
public export
|
||||||
|
|
|
@ -5,7 +5,9 @@ authors = "rhiannon morris"
|
||||||
sourceloc = "https://git.rhiannon.website/rhi/quox"
|
sourceloc = "https://git.rhiannon.website/rhi/quox"
|
||||||
license = "acsl"
|
license = "acsl"
|
||||||
|
|
||||||
depends = base, contrib, elab-util, sop, snocvect, eff, prettier
|
depends =
|
||||||
|
base, contrib, elab-util, sop, snocvect, eff, prettier,
|
||||||
|
pretty-show, parser-show
|
||||||
|
|
||||||
modules =
|
modules =
|
||||||
Text.PrettyPrint.Bernardy.Core.Decorate,
|
Text.PrettyPrint.Bernardy.Core.Decorate,
|
||||||
|
@ -14,6 +16,7 @@ modules =
|
||||||
Quox.CharExtra,
|
Quox.CharExtra,
|
||||||
Quox.NatExtra,
|
Quox.NatExtra,
|
||||||
Quox.EffExtra,
|
Quox.EffExtra,
|
||||||
|
Quox.PrettyValExtra,
|
||||||
Quox.Decidable,
|
Quox.Decidable,
|
||||||
Quox.No,
|
Quox.No,
|
||||||
Quox.Loc,
|
Quox.Loc,
|
||||||
|
|
Loading…
Reference in a new issue