0 | module TyRE.DisjointMatches
14 | data DisjointMatchesSnoc : Type -> Type where
15 | Prefix : SnocList Char -> DisjointMatchesSnoc a
16 | Snoc : DisjointMatchesSnoc a -> a -> SnocList Char -> DisjointMatchesSnoc a
19 | (:<) : DisjointMatchesSnoc a -> Char -> DisjointMatchesSnoc a
20 | (:<) (Prefix cs) c = Prefix (cs :< c)
21 | (:<) (Snoc dm parseTree cs) c = Snoc dm parseTree (cs :< c)
24 | (:+:) : DisjointMatchesSnoc a -> a -> DisjointMatchesSnoc a
25 | (:+:) dm parseTree = Snoc dm parseTree [<]
33 | data DisjointMatches : Type -> Type where
34 | Suffix : List Char -> DisjointMatches a
35 | Cons : List Char -> a -> DisjointMatches a -> DisjointMatches a
38 | (::) : DisjointMatches a -> Char -> DisjointMatches a
39 | (::) (Suffix cs) c = Suffix (c :: cs)
40 | (::) (Cons cs parse tail) c = Cons (c :: cs) parse tail
43 | (.+.) : a -> DisjointMatches a -> DisjointMatches a
44 | (.+.) parse dm = Cons [] parse dm
47 | (<>>) : DisjointMatchesSnoc a -> DisjointMatches a -> DisjointMatches a
48 | (<>>) (Prefix sc) (Suffix cs) = Suffix (sc <>> cs)
49 | (<>>) (Prefix sc) (Cons cs p tl) = Cons (sc <>> cs) p tl
50 | (<>>) (Snoc nck p sc) (Suffix cs) = nck <>> Cons [] p (Suffix (sc <>> cs))
51 | (<>>) (Snoc nck p sc) (Cons cs q tl) = nck <>> Cons [] p (Cons (sc <>> cs) q tl)
54 | (<><) : DisjointMatchesSnoc a -> DisjointMatches a -> DisjointMatchesSnoc a
55 | (<><) (Prefix sc) (Suffix cs) = Prefix (sc <>< cs)
56 | (<><) (Snoc nck p sc) (Suffix cs) = Snoc nck p (sc <>< cs)
57 | (<><) (Prefix sc) (Cons cs p tl) = Snoc (Prefix (sc <>< cs)) p [<] <>< tl
58 | (<><) (Snoc nck p sc) (Cons cs q tl) = Snoc (Snoc nck p (sc <>< cs)) q [<] <>< tl
61 | Cast (DisjointMatchesSnoc a) (DisjointMatches a) where
62 | cast sx = sx <>> (Suffix [])
65 | Cast (DisjointMatches a) (DisjointMatchesSnoc a) where
66 | cast xs = (Prefix [<]) <>< xs
69 | Functor DisjointMatches where
70 | map f (Suffix cs) = Suffix cs
71 | map f (Cons cs parse tail) = Cons cs (f parse) (map f tail)
74 | Functor DisjointMatchesSnoc where
75 | map f (Prefix sc) = Prefix sc
76 | map f (Snoc neck parse sc) = Snoc (map f neck) (f parse) sc
79 | toString : (a -> String) -> DisjointMatches a -> String
80 | toString f (Suffix cs) = fastPack cs
81 | toString f (Cons cs parse tail) = (fastPack cs) ++ (f parse) ++ (toString f tail)
84 | toStringSnoc : (a -> String) -> DisjointMatchesSnoc a -> String
85 | toStringSnoc f (Prefix sc) = fastPack (cast sc)
86 | toStringSnoc f (Snoc neck parse sc) = (toStringSnoc f neck) ++ (f parse) ++ fastPack (cast sc)
89 | Show a => Show (DisjointMatches a) where
90 | show (Suffix cs) = fastPack cs
91 | show (Cons cs pt tail) = fastPack cs ++ "~~" ++ show pt ++ "~~" ++ show tail
94 | Show a => Show (DisjointMatchesSnoc a) where
95 | show (Prefix cs) = fastPack $
toList cs
96 | show (Snoc neck pt cs) = show neck ++ "~~" ++ show pt ++ "~~" ++ fastPack (toList cs)
99 | length : DisjointMatches a -> Nat
100 | length (Suffix _) = Z
101 | length (Cons _ _ tail) = S (length tail)