mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-23 18:02:54 -06:00
Expose GF.Grammar.Canonical + some refactoring
to make it available in other tools by depending on the gf package and importing it
This commit is contained in:
2
gf.cabal
2
gf.cabal
@@ -151,6 +151,7 @@ Library
|
|||||||
GF.Support
|
GF.Support
|
||||||
GF.Text.Pretty
|
GF.Text.Pretty
|
||||||
GF.Text.Lexing
|
GF.Text.Lexing
|
||||||
|
GF.Grammar.Canonical
|
||||||
|
|
||||||
other-modules:
|
other-modules:
|
||||||
GF.Main GF.Compiler GF.Interactive
|
GF.Main GF.Compiler GF.Interactive
|
||||||
@@ -190,7 +191,6 @@ Library
|
|||||||
GF.Haskell
|
GF.Haskell
|
||||||
GF.Compile.ConcreteToHaskell
|
GF.Compile.ConcreteToHaskell
|
||||||
GF.Compile.GrammarToCanonical
|
GF.Compile.GrammarToCanonical
|
||||||
GF.Grammar.Canonical
|
|
||||||
GF.Grammar.CanonicalJSON
|
GF.Grammar.CanonicalJSON
|
||||||
GF.Compile.PGFtoJS
|
GF.Compile.PGFtoJS
|
||||||
GF.Compile.PGFtoProlog
|
GF.Compile.PGFtoProlog
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ module GF(
|
|||||||
module GF.Grammar.Printer,
|
module GF.Grammar.Printer,
|
||||||
module GF.Infra.Ident,
|
module GF.Infra.Ident,
|
||||||
-- ** Binary serialisation
|
-- ** Binary serialisation
|
||||||
module GF.Grammar.Binary
|
module GF.Grammar.Binary,
|
||||||
|
-- * Canonical GF
|
||||||
|
module GF.Compile.GrammarToCanonical
|
||||||
) where
|
) where
|
||||||
import GF.Main
|
import GF.Main
|
||||||
import GF.Compiler
|
import GF.Compiler
|
||||||
@@ -36,3 +38,5 @@ import GF.Grammar.Macros
|
|||||||
import GF.Grammar.Printer
|
import GF.Grammar.Printer
|
||||||
import GF.Infra.Ident
|
import GF.Infra.Ident
|
||||||
import GF.Grammar.Binary
|
import GF.Grammar.Binary
|
||||||
|
|
||||||
|
import GF.Compile.GrammarToCanonical
|
||||||
|
|||||||
@@ -142,8 +142,8 @@ concrete2haskell opts
|
|||||||
rhs = lets (zipWith letlin args absctx)
|
rhs = lets (zipWith letlin args absctx)
|
||||||
(convert vs (coerce env lincat rhs0))
|
(convert vs (coerce env lincat rhs0))
|
||||||
where
|
where
|
||||||
vs = [(VarValueId x,a)|(VarId x,a)<-zip xs args]
|
vs = [(VarValueId (Unqual x),a)|(VarId x,a)<-zip xs args]
|
||||||
env= [(VarValueId x,lc)|(VarId x,lc)<-zip xs (map arglincat absctx)]
|
env= [(VarValueId (Unqual x),lc)|(VarId x,lc)<-zip xs (map arglincat absctx)]
|
||||||
|
|
||||||
letlin a (TypeBinding _ (C.Type _ (TypeApp acat _))) =
|
letlin a (TypeBinding _ (C.Type _ (TypeApp acat _))) =
|
||||||
(a,Ap (Var (linfunName acat)) (Var (abs_arg a)))
|
(a,Ap (Var (linfunName acat)) (Var (abs_arg a)))
|
||||||
@@ -173,15 +173,20 @@ concrete2haskell opts
|
|||||||
VariantValue [] -> empty
|
VariantValue [] -> empty
|
||||||
VariantValue ts@(_:_) -> variants ts
|
VariantValue ts@(_:_) -> variants ts
|
||||||
VarValue x -> maybe (Var (gId x)) (pure . Var) $ lookup x vs
|
VarValue x -> maybe (Var (gId x)) (pure . Var) $ lookup x vs
|
||||||
IntConstant n -> pure (lit n)
|
|
||||||
StrConstant s -> pure (token s)
|
|
||||||
PreValue vs t' -> pure (alts t' vs)
|
PreValue vs t' -> pure (alts t' vs)
|
||||||
ParamConstant (Param c vs) -> aps (Var (pId c)) (map ppT vs)
|
ParamConstant (Param c vs) -> aps (Var (pId c)) (map ppT vs)
|
||||||
ErrorValue s -> ap (Const "error") (Const (show s)) -- !!
|
ErrorValue s -> ap (Const "error") (Const (show s)) -- !!
|
||||||
|
LiteralValue l -> ppL l
|
||||||
_ -> error ("convert "++show t)
|
_ -> error ("convert "++show t)
|
||||||
|
|
||||||
|
ppL l =
|
||||||
|
case l of
|
||||||
|
FloatConstant x -> pure (lit x)
|
||||||
|
IntConstant n -> pure (lit n)
|
||||||
|
StrConstant s -> pure (token s)
|
||||||
|
|
||||||
pId p@(ParamId s) =
|
pId p@(ParamId s) =
|
||||||
if "to_R_" `isPrefixOf` s then toIdent p else gId p -- !! a hack
|
if "to_R_" `isPrefixOf` unqual s then toIdent p else gId p -- !! a hack
|
||||||
|
|
||||||
table cs =
|
table cs =
|
||||||
if all (null.patVars) ps
|
if all (null.patVars) ps
|
||||||
@@ -329,7 +334,7 @@ coerce env ty t =
|
|||||||
_ -> t
|
_ -> t
|
||||||
where
|
where
|
||||||
app f ts = ParamConstant (Param f ts) -- !! a hack
|
app f ts = ParamConstant (Param f ts) -- !! a hack
|
||||||
to_rcon = ParamId . to_rcon' . labels
|
to_rcon = ParamId . Unqual . to_rcon' . labels
|
||||||
|
|
||||||
patVars p = []
|
patVars p = []
|
||||||
|
|
||||||
@@ -395,11 +400,16 @@ linfunName c = prefixIdent "lin" (toIdent c)
|
|||||||
|
|
||||||
class ToIdent i where toIdent :: i -> Ident
|
class ToIdent i where toIdent :: i -> Ident
|
||||||
|
|
||||||
instance ToIdent ParamId where toIdent (ParamId s) = identS s
|
instance ToIdent ParamId where toIdent (ParamId q) = qIdentS q
|
||||||
instance ToIdent PredefId where toIdent (PredefId s) = identS s
|
instance ToIdent PredefId where toIdent (PredefId s) = identS s
|
||||||
instance ToIdent CatId where toIdent (CatId s) = identS s
|
instance ToIdent CatId where toIdent (CatId s) = identS s
|
||||||
instance ToIdent C.FunId where toIdent (FunId s) = identS s
|
instance ToIdent C.FunId where toIdent (FunId s) = identS s
|
||||||
instance ToIdent VarValueId where toIdent (VarValueId s) = identS s
|
instance ToIdent VarValueId where toIdent (VarValueId q) = qIdentS q
|
||||||
|
|
||||||
|
qIdentS = identS . unqual
|
||||||
|
|
||||||
|
unqual (Qual (ModId m) n) = m++"_"++n
|
||||||
|
unqual (Unqual n) = n
|
||||||
|
|
||||||
instance ToIdent VarId where
|
instance ToIdent VarId where
|
||||||
toIdent Anonymous = identW
|
toIdent Anonymous = identW
|
||||||
|
|||||||
@@ -165,11 +165,11 @@ convert' gr vs = ppT
|
|||||||
Cn x -> VarValue (gId x) -- hmm
|
Cn x -> VarValue (gId x) -- hmm
|
||||||
Con c -> ParamConstant (Param (gId c) [])
|
Con c -> ParamConstant (Param (gId c) [])
|
||||||
Sort k -> VarValue (gId k)
|
Sort k -> VarValue (gId k)
|
||||||
EInt n -> IntConstant n
|
EInt n -> LiteralValue (IntConstant n)
|
||||||
Q (m,n) -> if m==cPredef then ppPredef n else VarValue (gId (qual m n))
|
Q (m,n) -> if m==cPredef then ppPredef n else VarValue ((gQId m n))
|
||||||
QC (m,n) -> ParamConstant (Param (gId (qual m n)) [])
|
QC (m,n) -> ParamConstant (Param ((gQId m n)) [])
|
||||||
K s -> StrConstant s
|
K s -> LiteralValue (StrConstant s)
|
||||||
Empty -> StrConstant ""
|
Empty -> LiteralValue (StrConstant "")
|
||||||
FV ts -> VariantValue (map ppT ts)
|
FV ts -> VariantValue (map ppT ts)
|
||||||
Alts t' vs -> alts vs (ppT t')
|
Alts t' vs -> alts vs (ppT t')
|
||||||
_ -> error $ "convert' "++show t
|
_ -> error $ "convert' "++show t
|
||||||
@@ -183,14 +183,14 @@ convert' gr vs = ppT
|
|||||||
Ok SOFT_SPACE -> p "SOFT_SPACE"
|
Ok SOFT_SPACE -> p "SOFT_SPACE"
|
||||||
Ok CAPIT -> p "CAPIT"
|
Ok CAPIT -> p "CAPIT"
|
||||||
Ok ALL_CAPIT -> p "ALL_CAPIT"
|
Ok ALL_CAPIT -> p "ALL_CAPIT"
|
||||||
_ -> VarValue (gId n)
|
_ -> VarValue (gQId cPredef n) -- hmm
|
||||||
where
|
where
|
||||||
p = PredefValue . PredefId
|
p = PredefValue . PredefId
|
||||||
|
|
||||||
ppP p =
|
ppP p =
|
||||||
case p of
|
case p of
|
||||||
PC c ps -> ParamPattern (Param (gId c) (map ppP ps))
|
PC c ps -> ParamPattern (Param (gId c) (map ppP ps))
|
||||||
PP (m,c) ps -> ParamPattern (Param (gId (qual m c)) (map ppP ps))
|
PP (m,c) ps -> ParamPattern (Param ((gQId m c)) (map ppP ps))
|
||||||
PR r -> RecordPattern (fields r) {-
|
PR r -> RecordPattern (fields r) {-
|
||||||
PW -> WildPattern
|
PW -> WildPattern
|
||||||
PV x -> VarP x
|
PV x -> VarP x
|
||||||
@@ -233,8 +233,8 @@ convert' gr vs = ppT
|
|||||||
|
|
||||||
concatValue v1 v2 =
|
concatValue v1 v2 =
|
||||||
case (v1,v2) of
|
case (v1,v2) of
|
||||||
(StrConstant "",_) -> v2
|
(LiteralValue (StrConstant ""),_) -> v2
|
||||||
(_,StrConstant "") -> v1
|
(_,LiteralValue (StrConstant "")) -> v1
|
||||||
_ -> ConcatValue v1 v2
|
_ -> ConcatValue v1 v2
|
||||||
|
|
||||||
projection r l = maybe (Projection r l) id (proj r l)
|
projection r l = maybe (Projection r l) id (proj r l)
|
||||||
@@ -298,8 +298,8 @@ convType = ppT
|
|||||||
Sort k -> convSort k
|
Sort k -> convSort k
|
||||||
-- EInt n -> tcon0 (identS ("({-"++show n++"-})")) -- type level numeric literal
|
-- EInt n -> tcon0 (identS ("({-"++show n++"-})")) -- type level numeric literal
|
||||||
FV (t:ts) -> ppT t -- !!
|
FV (t:ts) -> ppT t -- !!
|
||||||
QC (m,n) -> ParamType (ParamTypeId (gId (qual m n)))
|
QC (m,n) -> ParamType (ParamTypeId ((gQId m n)))
|
||||||
Q (m,n) -> ParamType (ParamTypeId (gId (qual m n)))
|
Q (m,n) -> ParamType (ParamTypeId ((gQId m n)))
|
||||||
_ -> error $ "Missing case in convType for: "++show t
|
_ -> error $ "Missing case in convType for: "++show t
|
||||||
|
|
||||||
convFields = map convField . filter (not.isLockLabel.fst)
|
convFields = map convField . filter (not.isLockLabel.fst)
|
||||||
@@ -325,25 +325,21 @@ paramType gr q@(_,n) =
|
|||||||
((S.singleton (m,n),argTypes ps),
|
((S.singleton (m,n),argTypes ps),
|
||||||
[ParamDef name (map (param m) ps)]
|
[ParamDef name (map (param m) ps)]
|
||||||
)
|
)
|
||||||
where name = gId (qual m n)
|
where name = (gQId m n)
|
||||||
Ok (m,ResOper _ (Just (L _ t)))
|
Ok (m,ResOper _ (Just (L _ t)))
|
||||||
| m==cPredef && n==cInts ->
|
| m==cPredef && n==cInts ->
|
||||||
((S.empty,S.empty),[]) {-
|
((S.empty,S.empty),[]) {-
|
||||||
((S.singleton (m,n),S.empty),
|
((S.singleton (m,n),S.empty),
|
||||||
[Type (ConAp (gId (qual m n)) [identS "n"]) (TId (identS "Int"))])-}
|
[Type (ConAp ((gQId m n)) [identS "n"]) (TId (identS "Int"))])-}
|
||||||
| otherwise ->
|
| otherwise ->
|
||||||
((S.singleton (m,n),paramTypes gr t),
|
((S.singleton (m,n),paramTypes gr t),
|
||||||
[ParamAliasDef (gId (qual m n)) (convType t)])
|
[ParamAliasDef ((gQId m n)) (convType t)])
|
||||||
_ -> ((S.empty,S.empty),[])
|
_ -> ((S.empty,S.empty),[])
|
||||||
where
|
where
|
||||||
param m (n,ctx) = Param (gId (qual m n)) [toParamId t|(_,_,t)<-ctx]
|
param m (n,ctx) = Param ((gQId m n)) [toParamId t|(_,_,t)<-ctx]
|
||||||
argTypes = S.unions . map argTypes1
|
argTypes = S.unions . map argTypes1
|
||||||
argTypes1 (n,ctx) = S.unions [paramTypes gr t|(_,_,t)<-ctx]
|
argTypes1 (n,ctx) = S.unions [paramTypes gr t|(_,_,t)<-ctx]
|
||||||
|
|
||||||
qual :: ModuleName -> Ident -> Ident
|
|
||||||
qual m = prefixIdent (render m++"_")
|
|
||||||
|
|
||||||
|
|
||||||
lblId = LabelId . render -- hmm
|
lblId = LabelId . render -- hmm
|
||||||
modId (MN m) = ModId (showIdent m)
|
modId (MN m) = ModId (showIdent m)
|
||||||
|
|
||||||
@@ -354,8 +350,16 @@ instance FromIdent VarId where
|
|||||||
|
|
||||||
instance FromIdent C.FunId where gId = C.FunId . showIdent
|
instance FromIdent C.FunId where gId = C.FunId . showIdent
|
||||||
instance FromIdent CatId where gId = CatId . showIdent
|
instance FromIdent CatId where gId = CatId . showIdent
|
||||||
instance FromIdent ParamId where gId = ParamId . showIdent
|
instance FromIdent ParamId where gId = ParamId . unqual
|
||||||
instance FromIdent VarValueId where gId = VarValueId . showIdent
|
instance FromIdent VarValueId where gId = VarValueId . unqual
|
||||||
|
|
||||||
|
class FromIdent i => QualIdent i where gQId :: ModuleName -> Ident -> i
|
||||||
|
|
||||||
|
instance QualIdent ParamId where gQId m n = ParamId (qual m n)
|
||||||
|
instance QualIdent VarValueId where gQId m n = VarValueId (qual m n)
|
||||||
|
|
||||||
|
qual m n = Qual (modId m) (showIdent n)
|
||||||
|
unqual n = Unqual (showIdent n)
|
||||||
|
|
||||||
convFlags gr mn =
|
convFlags gr mn =
|
||||||
Flags [(n,convLit v) |
|
Flags [(n,convLit v) |
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
-- | Abstract syntax for canonical GF grammars, i.e. what's left after
|
-- |
|
||||||
|
-- Module : GF.Grammar.Canonical
|
||||||
|
-- Stability : provisional
|
||||||
|
--
|
||||||
|
-- Abstract syntax for canonical GF grammars, i.e. what's left after
|
||||||
-- high-level constructions such as functors and opers have been eliminated
|
-- high-level constructions such as functors and opers have been eliminated
|
||||||
-- by partial evaluation. This is intended as a common intermediate
|
-- by partial evaluation. This is intended as a common intermediate
|
||||||
-- representation to simplify export to other formats.
|
-- representation to simplify export to other formats.
|
||||||
|
|
||||||
module GF.Grammar.Canonical where
|
module GF.Grammar.Canonical where
|
||||||
import Prelude hiding ((<>))
|
import Prelude hiding ((<>))
|
||||||
import GF.Text.Pretty
|
import GF.Text.Pretty
|
||||||
@@ -51,13 +56,11 @@ newtype ParamType = ParamTypeId ParamId deriving (Eq,Ord,Show)
|
|||||||
|
|
||||||
-- | Linearization value, RHS of @lin@
|
-- | Linearization value, RHS of @lin@
|
||||||
data LinValue = ConcatValue LinValue LinValue
|
data LinValue = ConcatValue LinValue LinValue
|
||||||
|
| LiteralValue LinLiteral
|
||||||
| ErrorValue String
|
| ErrorValue String
|
||||||
| FloatConstant Float
|
|
||||||
| IntConstant Int
|
|
||||||
| ParamConstant ParamValue
|
| ParamConstant ParamValue
|
||||||
| PredefValue PredefId
|
| PredefValue PredefId
|
||||||
| RecordValue [RecordRowValue]
|
| RecordValue [RecordRowValue]
|
||||||
| StrConstant String
|
|
||||||
| TableValue LinType [TableRowValue]
|
| TableValue LinType [TableRowValue]
|
||||||
--- | VTableValue LinType [LinValue]
|
--- | VTableValue LinType [LinValue]
|
||||||
| TupleValue [LinValue]
|
| TupleValue [LinValue]
|
||||||
@@ -68,6 +71,11 @@ data LinValue = ConcatValue LinValue LinValue
|
|||||||
| Selection LinValue LinValue
|
| Selection LinValue LinValue
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
|
data LinLiteral = FloatConstant Float
|
||||||
|
| IntConstant Int
|
||||||
|
| StrConstant String
|
||||||
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
data LinPattern = ParamPattern ParamPattern
|
data LinPattern = ParamPattern ParamPattern
|
||||||
| RecordPattern [RecordRow LinPattern]
|
| RecordPattern [RecordRow LinPattern]
|
||||||
| WildPattern
|
| WildPattern
|
||||||
@@ -87,27 +95,33 @@ data TableRowValue = TableRowValue LinPattern LinValue deriving (Eq,Ord,Show)
|
|||||||
|
|
||||||
-- *** Identifiers in Concrete Syntax
|
-- *** Identifiers in Concrete Syntax
|
||||||
|
|
||||||
newtype PredefId = PredefId String deriving (Eq,Ord,Show)
|
newtype PredefId = PredefId Id deriving (Eq,Ord,Show)
|
||||||
newtype LabelId = LabelId String deriving (Eq,Ord,Show)
|
newtype LabelId = LabelId Id deriving (Eq,Ord,Show)
|
||||||
data VarValueId = VarValueId String deriving (Eq,Ord,Show)
|
data VarValueId = VarValueId QualId deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
-- | Name of param type or param value
|
-- | Name of param type or param value
|
||||||
newtype ParamId = ParamId String deriving (Eq,Ord,Show)
|
newtype ParamId = ParamId QualId deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- ** Used in both Abstract and Concrete Syntax
|
-- ** Used in both Abstract and Concrete Syntax
|
||||||
|
|
||||||
newtype ModId = ModId String deriving (Eq,Show)
|
newtype ModId = ModId Id deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
newtype CatId = CatId String deriving (Eq,Ord,Show)
|
newtype CatId = CatId Id deriving (Eq,Ord,Show)
|
||||||
newtype FunId = FunId String deriving (Eq,Show)
|
newtype FunId = FunId Id deriving (Eq,Show)
|
||||||
|
|
||||||
data VarId = Anonymous | VarId String deriving Show
|
data VarId = Anonymous | VarId Id deriving Show
|
||||||
|
|
||||||
newtype Flags = Flags [(FlagName,FlagValue)] deriving Show
|
newtype Flags = Flags [(FlagName,FlagValue)] deriving Show
|
||||||
type FlagName = String
|
type FlagName = Id
|
||||||
data FlagValue = Str String | Int Int | Flt Double deriving Show
|
data FlagValue = Str String | Int Int | Flt Double deriving Show
|
||||||
|
|
||||||
|
|
||||||
|
-- *** Identifiers
|
||||||
|
|
||||||
|
type Id = String
|
||||||
|
data QualId = Qual ModId Id | Unqual Id deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- ** Pretty printing
|
-- ** Pretty printing
|
||||||
|
|
||||||
@@ -203,8 +217,7 @@ instance Pretty LinValue where
|
|||||||
|
|
||||||
instance PPA LinValue where
|
instance PPA LinValue where
|
||||||
ppA lv = case lv of
|
ppA lv = case lv of
|
||||||
FloatConstant f -> pp f
|
LiteralValue l -> ppA l
|
||||||
IntConstant n -> pp n
|
|
||||||
ParamConstant pv -> ppA pv
|
ParamConstant pv -> ppA pv
|
||||||
PredefValue p -> ppA p
|
PredefValue p -> ppA p
|
||||||
RecordValue [] -> pp "<>"
|
RecordValue [] -> pp "<>"
|
||||||
@@ -214,13 +227,20 @@ instance PPA LinValue where
|
|||||||
where
|
where
|
||||||
alt (ss,lv) = hang (hcat (punctuate "|" (map doubleQuotes ss)))
|
alt (ss,lv) = hang (hcat (punctuate "|" (map doubleQuotes ss)))
|
||||||
2 ("=>"<+>lv)
|
2 ("=>"<+>lv)
|
||||||
StrConstant s -> doubleQuotes s -- hmm
|
|
||||||
TableValue _ tvs -> "table"<+>block tvs
|
TableValue _ tvs -> "table"<+>block tvs
|
||||||
-- VTableValue t ts -> "table"<+>t<+>brackets (semiSep ts)
|
-- VTableValue t ts -> "table"<+>t<+>brackets (semiSep ts)
|
||||||
TupleValue lvs -> "<"<>punctuate "," lvs<>">"
|
TupleValue lvs -> "<"<>punctuate "," lvs<>">"
|
||||||
VarValue v -> pp v
|
VarValue v -> pp v
|
||||||
_ -> parens lv
|
_ -> parens lv
|
||||||
|
|
||||||
|
instance Pretty LinLiteral where pp = ppA
|
||||||
|
|
||||||
|
instance PPA LinLiteral where
|
||||||
|
ppA l = case l of
|
||||||
|
FloatConstant f -> pp f
|
||||||
|
IntConstant n -> pp n
|
||||||
|
StrConstant s -> doubleQuotes s -- hmm
|
||||||
|
|
||||||
instance RhsSeparator LinValue where rhsSep _ = pp "="
|
instance RhsSeparator LinValue where rhsSep _ = pp "="
|
||||||
|
|
||||||
instance Pretty LinPattern where
|
instance Pretty LinPattern where
|
||||||
@@ -250,11 +270,17 @@ instance Pretty CatId where pp (CatId s) = pp s
|
|||||||
instance Pretty FunId where pp (FunId s) = pp s
|
instance Pretty FunId where pp (FunId s) = pp s
|
||||||
instance Pretty LabelId where pp (LabelId s) = pp s
|
instance Pretty LabelId where pp (LabelId s) = pp s
|
||||||
instance Pretty PredefId where pp = ppA
|
instance Pretty PredefId where pp = ppA
|
||||||
instance PPA PredefId where ppA (PredefId s) = pp s
|
instance PPA PredefId where ppA (PredefId s) = "Predef."<>s
|
||||||
instance Pretty ParamId where pp = ppA
|
instance Pretty ParamId where pp = ppA
|
||||||
instance PPA ParamId where ppA (ParamId s) = pp s
|
instance PPA ParamId where ppA (ParamId s) = pp s
|
||||||
instance Pretty VarValueId where pp (VarValueId s) = pp s
|
instance Pretty VarValueId where pp (VarValueId s) = pp s
|
||||||
|
|
||||||
|
instance Pretty QualId where pp = ppA
|
||||||
|
|
||||||
|
instance PPA QualId where
|
||||||
|
ppA (Qual m n) = m<>"_"<>n -- hmm
|
||||||
|
ppA (Unqual n) = pp n
|
||||||
|
|
||||||
instance Pretty Flags where
|
instance Pretty Flags where
|
||||||
pp (Flags []) = empty
|
pp (Flags []) = empty
|
||||||
pp (Flags flags) = "flags" <+> vcat (map ppFlag flags)
|
pp (Flags flags) = "flags" <+> vcat (map ppFlag flags)
|
||||||
|
|||||||
@@ -95,10 +95,7 @@ instance JSON LinType where
|
|||||||
|
|
||||||
instance JSON LinValue where
|
instance JSON LinValue where
|
||||||
showJSON lv = case lv of
|
showJSON lv = case lv of
|
||||||
-- basic values (Str, Float, Int) are encoded as JSON strings/numbers:
|
LiteralValue l -> showJSON l
|
||||||
StrConstant s -> showJSON s
|
|
||||||
FloatConstant f -> showJSON f
|
|
||||||
IntConstant n -> showJSON n
|
|
||||||
-- concatenation is encoded as a JSON array:
|
-- concatenation is encoded as a JSON array:
|
||||||
ConcatValue v v' -> showJSON [showJSON v, showJSON v']
|
ConcatValue v v' -> showJSON [showJSON v, showJSON v']
|
||||||
-- most values are encoded as JSON objects:
|
-- most values are encoded as JSON objects:
|
||||||
@@ -115,6 +112,13 @@ instance JSON LinValue where
|
|||||||
-- records are encoded directly as JSON records:
|
-- records are encoded directly as JSON records:
|
||||||
RecordValue rows -> showJSON rows
|
RecordValue rows -> showJSON rows
|
||||||
|
|
||||||
|
instance JSON LinLiteral where
|
||||||
|
showJSON l = case l of
|
||||||
|
-- basic values (Str, Float, Int) are encoded as JSON strings/numbers:
|
||||||
|
StrConstant s -> showJSON s
|
||||||
|
FloatConstant f -> showJSON f
|
||||||
|
IntConstant n -> showJSON n
|
||||||
|
|
||||||
instance JSON LinPattern where
|
instance JSON LinPattern where
|
||||||
showJSON linpat = case linpat of
|
showJSON linpat = case linpat of
|
||||||
-- wildcards and patterns without arguments are encoded as strings:
|
-- wildcards and patterns without arguments are encoded as strings:
|
||||||
@@ -161,6 +165,10 @@ instance JSON VarId where
|
|||||||
showJSON Anonymous = showJSON "_"
|
showJSON Anonymous = showJSON "_"
|
||||||
showJSON (VarId x) = showJSON x
|
showJSON (VarId x) = showJSON x
|
||||||
|
|
||||||
|
instance JSON QualId where
|
||||||
|
showJSON (Qual (ModId m) n) = showJSON (m++"_"++n)
|
||||||
|
showJSON (Unqual n) = showJSON n
|
||||||
|
|
||||||
instance JSON Flags where
|
instance JSON Flags where
|
||||||
-- flags are encoded directly as JSON records (i.e., objects):
|
-- flags are encoded directly as JSON records (i.e., objects):
|
||||||
showJSON (Flags fs) = makeObj [(f,showJSON v) | (f, v) <- fs]
|
showJSON (Flags fs) = makeObj [(f,showJSON v) | (f, v) <- fs]
|
||||||
|
|||||||
Reference in New Issue
Block a user