on master help sign in
Require SemiIsoMonad.
f187d4cPaweł Nowak
Data/Syntax.hs+1
@@ -74,6 +74,7 @@ packed = iso otoList fromList
74--
74--
75-- Methods of this class try to mimic "Data.Attoparsec.Text" interface.
75-- Methods of this class try to mimic "Data.Attoparsec.Text" interface.
76class ( SemiIsoAlternative syn
76class ( SemiIsoAlternative syn
77+ , SemiIsoMonad syn
77 , IsSequence seq
78 , IsSequence seq
78 , Eq seq
79 , Eq seq
79 , Eq (Element seq))
80 , Eq (Element seq))
Data/Syntax/Char.hs+7−1
@@ -11,10 +11,10 @@ Stability : experimental
11
11
12Common combinators that work with sequences of chars.
12Common combinators that work with sequences of chars.
13
13
14−There are A LOT of combinators missing.
15-}
14-}
16module Data.Syntax.Char (
15module Data.Syntax.Char (
17 SyntaxChar(..),
16 SyntaxChar(..),
17+ signed,
18 spaces,
18 spaces,
19 spaces_,
19 spaces_,
20 spaces1,
20 spaces1,
@@ -44,6 +44,12 @@ class (Syntax syn seq, Element seq ~ Char) => SyntaxChar syn seq where
44
44
45 {-# MINIMAL decimal, scientific #-}
45 {-# MINIMAL decimal, scientific #-}
46
46
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+
47-- | Accepts zero or more spaces. Generates a single space.
53-- | Accepts zero or more spaces. Generates a single space.
48spaces :: SyntaxChar syn seq => syn ()
54spaces :: SyntaxChar syn seq => syn ()
49spaces = constant (opoint ' ') /$/ S.takeWhile isSpace
55spaces = constant (opoint ' ') /$/ S.takeWhile isSpace