-- Useful parser combinators, similar to those provided by Parsec.
import Control.Applicative (many)
+import Data.Attoparsec.Internal.Types (Parser(..))
#if __GLASGOW_HASKELL__ >= 700
-import Data.Attoparsec.Internal.Types (Parser)
import qualified Data.Attoparsec.Zepto as Z
import Data.ByteString (ByteString)
+-- | Attempt a parse, and if it fails, rewind the input so that no
+-- input appears to have been consumed.
+-- This combinator is provided for compatibility with Parsec.
+-- Attoparsec parsers always backtrack on failure.
+try :: Parser t a -> Parser t a
+-- | Name the parser, in case failure occurs.
+ -> String -- ^ the name to use if parsing fails
+p <?> msg0 = Parser $ \i0 a0 m0 kf ks ->
+ let kf' i a m strs msg = kf i a m (msg0:strs) msg
+ in runParser p i0 a0 m0 kf' ks
-- | @choice ps@ tries to apply the actions in the list @ps@ in order,
-- until one of them succeeds. Returns the value of the succeeding