on master help sign in
Require SemiIsoMonad.
commitf187d4c3cf1c90713c5615c8137b00d9f41205bc authorPaweł Nowak <pawel834@gmail.com> dateThu 13 Nov 2014, 16:08 (12 years ago) parent262260e
2 files changed+8−1
Data/Syntax.hs+1 Data/Syntax/Char.hs+7−1
Data/Syntax.hs+1
@@ -74,6 +74,7 @@ packed = iso otoList fromList
7474--
7575-- Methods of this class try to mimic "Data.Attoparsec.Text" interface.
7676class ( SemiIsoAlternative syn
77+ , SemiIsoMonad syn
7778 , IsSequence seq
7879 , Eq seq
7980 , Eq (Element seq))
Data/Syntax/Char.hs+7−1
@@ -11,10 +11,10 @@ Stability : experimental
1111
1212Common combinators that work with sequences of chars.
1313
14−There are A LOT of combinators missing.
1514-}
1615module Data.Syntax.Char (
1716 SyntaxChar(..),
17+ signed,
1818 spaces,
1919 spaces_,
2020 spaces1,
@@ -44,6 +44,12 @@ class (Syntax syn seq, Element seq ~ Char) => SyntaxChar syn seq where
4444
4545 {-# MINIMAL decimal, scientific #-}
4646
47+-- | A number with an optional leading '+' or '-' sign character.
48+signed :: (Num a, SyntaxChar syn seq) => syn a -> syn a
49+signed n = _Negative /$/ S.char '-' */ n
50+ /|/ S.char '+' */ n
51+ /|/ n
52+
4753-- | Accepts zero or more spaces. Generates a single space.
4854spaces :: SyntaxChar syn seq => syn ()
4955spaces = constant (opoint ' ') /$/ S.takeWhile isSpace