[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36
John Goerzen
jgoerzen at complete.org
Fri Apr 23 14:47:48 UTC 2010
The following commit has been merged in the master branch:
commit 91e769830d1b7f74e113b9901c0241d78b45ccfc
Author: John Goerzen <jgoerzen at complete.org>
Date: Fri Nov 19 08:20:05 2004 +0100
Added new Parsec stuff
Keywords:
(jgoerzen at complete.org--projects/missingh--head--0.5--patch-92)
diff --git a/ChangeLog b/ChangeLog
index c402b0f..b8f78f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,18 @@
# arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
#
+2004-11-19 01:20:05 GMT John Goerzen <jgoerzen at complete.org> patch-92
+
+ Summary:
+ Added new Parsec stuff
+ Revision:
+ missingh--head--0.5--patch-92
+
+
+ modified files:
+ ChangeLog TODO libsrc/MissingH/Parsec.hs
+
+
2004-11-18 22:53:04 GMT John Goerzen <jgoerzen at complete.org> patch-91
Summary:
diff --git a/TODO b/TODO
index 09b6085..2582131 100644
--- a/TODO
+++ b/TODO
@@ -3,3 +3,4 @@ arch-tag: TODO file
Printf:
make %H work
+tests for new Parsec stuff
diff --git a/libsrc/MissingH/Parsec.hs b/libsrc/MissingH/Parsec.hs
index 8d64b55..5f6709b 100644
--- a/libsrc/MissingH/Parsec.hs
+++ b/libsrc/MissingH/Parsec.hs
@@ -30,11 +30,64 @@ Written by John Goerzen, jgoerzen\@complete.org
-}
-module MissingH.Parsec(notMatching)
+module MissingH.Parsec(-- * Generalized Utilities
+ -- | These functions are generalized versions of
+ -- ones you might see in the Char parser.
+ GeneralizedToken, GeneralizedTokenParser,
+ retgtok, tokeng, satisfyg, oneOfg, noneOfg,
+ specificg,
+ -- * Other Utilities
+ notMatching)
where
import Text.ParserCombinators.Parsec
+type GeneralizedToken a = (SourcePos, a)
+type GeneralizedTokenParser a st b = GenParser (GeneralizedToken a) st b
+
+{- | Generate (return) a 'GeneralizedToken'. -}
+retgtok :: a -> GenParser b st (GeneralizedToken a)
+retgtok tok = do
+ x <- getPosition
+ return (x, tok)
+
+{- | Retrieve the next token from a 'GeneralizedToken' stream.
+ The given function should return the value to use, or Nothing
+ to cause an error. -}
+tokeng :: (a -> Maybe b) -> GeneralizedTokenParser a st b
+tokeng test =
+ token (show . fst) (fst) (test . snd)
+
+{- | A shortcut to 'tokeng'; the test here is just a function that returns
+a Bool. If the result is true; return that value -- otherwise, an error.
+-}
+satisfyg :: (a -> Bool) -> GeneralizedTokenParser a st a
+satisfyg test = tokeng (\t -> if test t then Just t else Nothing)
+
+{- | Matches one item in a list and returns it. -}
+oneOfg :: (Eq a) => [a] -> GeneralizedTokenParser a st a
+oneOfg i = satisfyg (\x -> elem x i)
+
+{- | Matches one item not in a list and returns it. -}
+noneOfg :: (Eq a) => [a] -> GeneralizedTokenParser a st a
+noneOfg l = satisfyg (\x -> not (elem x l))
+
+{- | Matches one specific token and returns it. -}
+specificg :: (Eq a, Show a) => a -> GeneralizedTokenParser a st a
+specificg i = satisfyg (== i) <?> show i
+
+{- Matches a list of tokens and returns it. -}
+{-
+listg :: (Eq a, Show a) => [GeneralizedToken a] -> GeneralizedTokenParser a st [GeneralizedToken a]
+listg l = tokens (show . map fst) nextpos l
+ where
+ tokpos = fst
+ nextpos
+ nextposs _ _ (tok:toks) = tokpos tok
+ nextposs _ tok [] = tokpos tok
+ nextpos pos x = nextposs pos [x]
+-}
+
{- | Running @notMatching p msg@ will try to apply parser p.
If it fails, returns (). If it succeds, cause a failure and raise
the given error message. It will not consume input in either case. -}
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list