gdritter repos s-cargot / ac77756
Added `Data.SCargot.Atom` module for simplified atom parsing Getty Ritter 7 years ago
2 changed file(s) with 21 addition(s) and 0 deletion(s). Collapse all Expand all
1 module Data.SCargot.Atom
2 ( atom
3 , mkAtomParser
4 ) where
5
6 import Data.SCargot.Parse (SExprParser, mkParser)
7 import Data.SCargot.Repr (SExpr)
8 import Text.Parsec (choice)
9 import Text.Parsec.Text (Parser)
10
11 -- | A convenience function for defining an atom parser from a wrapper
12 -- function and a parser. This is identical to 'fmap' specialized to
13 -- operate over 'Parser' values, and is provided as sugar.
14 atom :: (t -> atom) -> Parser t -> Parser atom
15 atom = fmap
16
17 -- | A convenience function for defining a 'SExprSpec' from a list of
18 -- possible atom parsers, which will be tried in sequence before failing.
19 mkAtomParser :: [Parser atom] -> SExprParser atom (SExpr atom)
20 mkAtomParser = mkParser . choice
3535 Data.SCargot.Repr.WellFormed,
3636 Data.SCargot.Parse,
3737 Data.SCargot.Print,
38 Data.SCargot.Atom,
3839 Data.SCargot.Comments,
3940 Data.SCargot.Common,
4041 Data.SCargot.Language.Basic,