Atom.hs 712 B

1234567891011121314151617181920
  1. module Data.SCargot.Atom
  2. ( atom
  3. , mkAtomParser
  4. ) where
  5. import Data.SCargot.Parse (SExprParser, mkParser)
  6. import Data.SCargot.Repr (SExpr)
  7. import Text.Parsec (choice)
  8. import Text.Parsec.Text (Parser)
  9. -- | A convenience function for defining an atom parser from a wrapper
  10. -- function and a parser. This is identical to 'fmap' specialized to
  11. -- operate over 'Parser' values, and is provided as sugar.
  12. atom :: (t -> atom) -> Parser t -> Parser atom
  13. atom = fmap
  14. -- | A convenience function for defining a 'SExprSpec' from a list of
  15. -- possible atom parsers, which will be tried in sequence before failing.
  16. mkAtomParser :: [Parser atom] -> SExprParser atom (SExpr atom)
  17. mkAtomParser = mkParser . choice