@@ -0,0 +1,31 @@
1+-- |
2+-- Module : Data.Attoparsec.Internal
3+-- Copyright : Bryan O'Sullivan 2012
4+-- License : BSD3
5+--
6+-- Maintainer : bos@serpentine.com
7+-- Stability : experimental
8+-- Portability : unknown
9+--
10+-- Simple, efficient parser combinators, loosely based on the Parsec
11+-- library.
12+
13+module Data.Attoparsec.Internal
14+ (
15+ compareResults
16+ ) where
17+
18+import Data.Attoparsec.Internal.Types (IResult(..))
19+
20+-- | Compare two 'IResult' values for equality.
21+--
22+-- If both 'IResult's are 'Partial', the result will be 'Nothing', as
23+-- they are incomplete and hence their equality cannot be known.
24+-- (This is why there is no 'Eq' instance for 'IResult'.)
25+compareResults :: (Eq t, Eq r) => IResult t r -> IResult t r -> Maybe Bool
26+compareResults (Fail i0 ctxs0 msg0) (Fail i1 ctxs1 msg1) =
27+ Just (i0 == i1 && ctxs0 == ctxs1 && msg0 == msg1)
28+compareResults (Done i0 r0) (Done i1 r1) =
29+ Just (i0 == i1 && r0 == r1)
30+compareResults (Partial _) (Partial _) = Nothing
31+compareResults _ _ = Just False