0 | module Language.XML.CharData
2 | import public Data.List
3 | import public Data.String
4 | import Data.String.Extra
5 | import Data.String.Parser
8 | record CharData where
9 | constructor MkCharData
17 | maybeSpace : Bool -> String
18 | maybeSpace False = ""
19 | maybeSpace True = " "
23 | show (MkCharData preSpace c postSpace) = maybeSpace preSpace ++ c ++ maybeSpace postSpace
26 | fromString : String -> CharData
27 | fromString str = case unpack str of
28 | [] => MkCharData False "" False
31 | MkCharData (isSpace $
head cs) s ((not $
null s) && (isSpace $
last cs))
34 | (++) : CharData -> CharData -> CharData
35 | (MkCharData preSpace "" midLeftSpace) ++ (MkCharData midRightSpace d postSpace) =
36 | MkCharData (preSpace || midLeftSpace || midRightSpace) d postSpace
37 | (MkCharData preSpace c midLeftSpace) ++ (MkCharData midRightSpace "" postSpace) =
38 | MkCharData preSpace c (midLeftSpace || midRightSpace || postSpace)
39 | (MkCharData preSpace c midLeftSpace) ++ (MkCharData midRightSpace d postSpace) =
40 | MkCharData preSpace (c ++ maybeSpace (midLeftSpace || midRightSpace) ++ d) postSpace
43 | Semigroup CharData where
47 | Monoid CharData where
51 | charData : Parser CharData
53 | let word = map pack $
some $
satisfy $
\c => not (isSpace c) && c /= '<'
55 | preSpace <- succeeds spaces1
56 | words <- (many $
spaces *> word)
57 | postSpace <- succeeds spaces1
59 | pure $
MkCharData preSpace (join " " words) postSpace