Added basic serialization + fixed silly bug in WellFormed serialization
Getty Ritter
9 years ago
30 | 30 | import Data.Char (isAlpha, isDigit, isAlphaNum) |
31 | 31 | import Data.Map.Strict (Map) |
32 | 32 | import qualified Data.Map.Strict as M |
33 | import Data.Monoid ((<>)) | |
33 | 34 | import Data.Text (Text, pack, unpack) |
34 | 35 | |
35 | 36 | import Prelude hiding (takeWhile) |
238 | 239 | parseOnly (many1 parser <* endOfInput) >=> mapM postparse |
239 | 240 | where parser = parseGenericSExpr sesPAtom readerMap (buildSkip comment) |
240 | 241 | |
241 |
-- | E |
|
242 | -- | Encode (without newlines) a single S-expression. | |
243 | encodeSExpr :: SExpr atom -> (atom -> Text) -> Text | |
244 | encodeSExpr SNil _ = "()" | |
245 | encodeSExpr (SAtom s) t = t s | |
246 | encodeSExpr (SCons x xs) t = go xs (encodeSExpr x t) | |
247 | where go (SAtom s) rs = "(" <> rs <> " . " <> t s <> ")" | |
248 | go SNil rs = "(" <> rs <> ")" | |
249 | go (SCons x xs) rs = go xs (rs <> " " <> encodeSExpr x t) | |
250 | ||
251 | -- | Emit an S-Expression in a machine-readable way. This does no | |
252 | -- pretty-printing or indentation, and produces no comments. | |
242 | 253 | encode :: SExprSpec atom carrier -> carrier -> Text |
243 |
encode SExprSpec { .. } |
|
254 | encode SExprSpec { .. } c = encodeSExpr (preserial c) sesSAtom |