Explorar el Código

Added `Data.SCargot.Atom` module for simplified atom parsing

Getty Ritter hace 7 años
padre
commit
ac77756427
Se han modificado 2 ficheros con 21 adiciones y 0 borrados
  1. 20 0
      Data/SCargot/Atom.hs
  2. 1 0
      s-cargot.cabal

+ 20 - 0
Data/SCargot/Atom.hs

@@ -0,0 +1,20 @@
+module Data.SCargot.Atom
+  ( atom
+  , mkAtomParser
+  ) where
+
+import Data.SCargot.Parse (SExprParser, mkParser)
+import Data.SCargot.Repr (SExpr)
+import Text.Parsec (choice)
+import Text.Parsec.Text (Parser)
+
+-- | A convenience function for defining an atom parser from a wrapper
+--   function and a parser. This is identical to 'fmap' specialized to
+--   operate over 'Parser' values, and is provided as sugar.
+atom :: (t -> atom) -> Parser t -> Parser atom
+atom = fmap
+
+-- | A convenience function for defining a 'SExprSpec' from a list of
+--   possible atom parsers, which will be tried in sequence before failing.
+mkAtomParser :: [Parser atom] -> SExprParser atom (SExpr atom)
+mkAtomParser = mkParser . choice

+ 1 - 0
s-cargot.cabal

@@ -35,6 +35,7 @@ library
                        Data.SCargot.Repr.WellFormed,
                        Data.SCargot.Parse,
                        Data.SCargot.Print,
+                       Data.SCargot.Atom,
                        Data.SCargot.Comments,
                        Data.SCargot.Common,
                        Data.SCargot.Language.Basic,