gdritter repos s-cargot / 0e8895e
Got rid of small uses of RecordWildCards Getty Ritter 10 years ago
1 changed file(s) with 12 addition(s) and 7 deletion(s). Collapse all Expand all
1 {-# LANGUAGE RecordWildCards #-}
21 {-# LANGUAGE ViewPatterns #-}
32 {-# LANGUAGE OverloadedStrings #-}
43
229228 -- will fail: for those cases, use 'decode', which returns a list of
230229 -- all the S-expressions found at the top level.
231230 decodeOne :: SExprSpec atom carrier -> Text -> Either String carrier
232 decodeOne SExprSpec { .. } = parseOnly (parser <* endOfInput) >=> postparse
233 where parser = parseGenericSExpr sesPAtom readerMap (buildSkip comment)
231 decodeOne spec = parseOnly (parser <* endOfInput) >=> (postparse spec)
232 where parser = parseGenericSExpr
233 (sesPAtom spec)
234 (readerMap spec)
235 (buildSkip (comment spec))
234236
235237 -- | Decode several S-expressions according to a given 'SExprSpec'. This
236238 -- will return a list of every S-expression that appears at the top-level
237239 -- of the document.
238240 decode :: SExprSpec atom carrier -> Text -> Either String [carrier]
239 decode SExprSpec { .. } =
240 parseOnly (many1 parser <* endOfInput) >=> mapM postparse
241 where parser = parseGenericSExpr sesPAtom readerMap (buildSkip comment)
241 decode spec =
242 parseOnly (many1 parser <* endOfInput) >=> mapM (postparse spec)
243 where parser = parseGenericSExpr
244 (sesPAtom spec)
245 (readerMap spec)
246 (buildSkip (comment spec))
242247
243248 -- | Encode (without newlines) a single S-expression.
244249 encodeSExpr :: SExpr atom -> (atom -> Text) -> Text
252257 -- | Emit an S-Expression in a machine-readable way. This does no
253258 -- pretty-printing or indentation, and produces no comments.
254259 encodeOne :: SExprSpec atom carrier -> carrier -> Text
255 encodeOne SExprSpec { .. } c = encodeSExpr (preserial c) sesSAtom
260 encodeOne spec c = encodeSExpr (preserial spec c) (sesSAtom spec)
256261
257262 encode :: SExprSpec atom carrier -> [carrier] -> Text
258263 encode spec cs = T.concat (map (encodeOne spec) cs)