Added `Data.SCargot.Atom` module for simplified atom parsing
Getty Ritter
9 years ago
| 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 |