module NeSyPatterns.Print where
import Common.Doc
import Common.DocUtils
import NeSyPatterns.AS
instance Pretty BASIC_SPEC where
pretty :: BASIC_SPEC -> Doc
pretty = BASIC_SPEC -> Doc
printBasicSpec
instance Pretty SYMB where
pretty :: SYMB -> Doc
pretty = SYMB -> Doc
printSymbol
instance Pretty SYMB_ITEMS where
pretty :: SYMB_ITEMS -> Doc
pretty = SYMB_ITEMS -> Doc
printSymbItems
instance Pretty SYMB_MAP_ITEMS where
pretty :: SYMB_MAP_ITEMS -> Doc
pretty = SYMB_MAP_ITEMS -> Doc
printSymbMapItems
instance Pretty BASIC_ITEM where
pretty :: BASIC_ITEM -> Doc
pretty = BASIC_ITEM -> Doc
printBasicItem
instance Pretty SYMB_OR_MAP where
pretty :: SYMB_OR_MAP -> Doc
pretty = SYMB_OR_MAP -> Doc
printSymbOrMap
instance Pretty Node where
pretty :: Node -> Doc
pretty = Node -> Doc
printNode
printNode :: Node -> Doc
printNode :: Node -> Doc
printNode (Node ot :: IRI
ot mni :: Maybe IRI
mni _) = Doc -> (IRI -> Doc) -> Maybe IRI -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
empty (\ni :: IRI
ni -> IRI -> Doc
forall a. Pretty a => a -> Doc
pretty IRI
ni Doc -> Doc -> Doc
<+> Doc
colon) Maybe IRI
mni Doc -> Doc -> Doc
<+> IRI -> Doc
forall a. Pretty a => a -> Doc
pretty IRI
ot
printBasicSpec :: BASIC_SPEC -> Doc
printBasicSpec :: BASIC_SPEC -> Doc
printBasicSpec (Basic_spec l :: [Annoted BASIC_ITEM]
l) = [Doc] -> Doc
vsep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Annoted BASIC_ITEM -> Doc) -> [Annoted BASIC_ITEM] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ((BASIC_ITEM -> Doc) -> Annoted BASIC_ITEM -> Doc
forall a. (a -> Doc) -> Annoted a -> Doc
printAnnoted BASIC_ITEM -> Doc
forall a. Pretty a => a -> Doc
pretty) [Annoted BASIC_ITEM]
l
printBasicItem :: BASIC_ITEM -> Doc
printBasicItem :: BASIC_ITEM -> Doc
printBasicItem (Path nodes :: [Node]
nodes) =
[Doc] -> Doc
fsep ([Doc] -> Doc) -> ([Doc] -> [Doc]) -> [Doc] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
punctuate (String -> Doc
text "->") ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Node -> Doc) -> [Node] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Node -> Doc
forall a. Pretty a => a -> Doc
pretty [Node]
nodes
printSymbol :: SYMB -> Doc
printSymbol :: SYMB -> Doc
printSymbol (Symb_id id' :: Node
id') = Node -> Doc
forall a. Pretty a => a -> Doc
pretty Node
id'
printSymbItems :: SYMB_ITEMS -> Doc
printSymbItems :: SYMB_ITEMS -> Doc
printSymbItems (Symb_items symbs :: [SYMB]
symbs _) =
[Doc] -> Doc
fsep ([Doc] -> Doc) -> ([Doc] -> [Doc]) -> [Doc] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
punctuate (String -> Doc
text ",") ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (SYMB -> Doc) -> [SYMB] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map SYMB -> Doc
forall a. Pretty a => a -> Doc
pretty [SYMB]
symbs
printSymbOrMap :: SYMB_OR_MAP -> Doc
printSymbOrMap :: SYMB_OR_MAP -> Doc
printSymbOrMap (Symb s :: SYMB
s) = SYMB -> Doc
forall a. Pretty a => a -> Doc
pretty SYMB
s
printSymbOrMap (Symb_map s1 :: SYMB
s1 s2 :: SYMB
s2 _) =
SYMB -> Doc
forall a. Pretty a => a -> Doc
pretty SYMB
s1 Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text " |-> " Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> SYMB -> Doc
forall a. Pretty a => a -> Doc
pretty SYMB
s2
printSymbMapItems :: SYMB_MAP_ITEMS -> Doc
printSymbMapItems :: SYMB_MAP_ITEMS -> Doc
printSymbMapItems (Symb_map_items l :: [SYMB_OR_MAP]
l _) =
[Doc] -> Doc
fsep ([Doc] -> Doc) -> ([Doc] -> [Doc]) -> [Doc] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
punctuate (String -> Doc
text ",") ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (SYMB_OR_MAP -> Doc) -> [SYMB_OR_MAP] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map SYMB_OR_MAP -> Doc
forall a. Pretty a => a -> Doc
pretty [SYMB_OR_MAP]
l