tree-features: a46ead5330b77461b0a0e901535bb2fb57ba9337
1: module SexprHelper where
2:
3: import qualified Data.AttoLisp as L
4: import qualified Data.Attoparsec.ByteString as AB
5: import qualified Data.ByteString.Char8 as C
6: import qualified Data.Stringable as S
7: import Features
8: import Text.ParserCombinators.Parsec
9:
10: parseLisp = AB.maybeResult . AB.parse L.lisp
11:
12: parseSexpr :: String -> TreeOf String
13: parseSexpr s = case parseLisp (S.fromString s) of
14: Nothing -> error ("Failed to parse: " ++ s)
15: Just x -> lispToTree x
16:
17: lispToTree (L.List xs) = Node (map lispToTree xs)
18: lispToTree (L.String s) = Leaf (S.toString s)
19:
20: treeToLisp (Leaf x) = L.String (S.fromString x)
21: treeToLisp (Node xs) = L.List (map treeToLisp xs)
22:
23: treeToSexpr :: TreeOf String -> String
24: treeToSexpr = S.toString . L.encode . treeToLisp
Generated by git2html.