<div dir="ltr">Hi!<div><br></div><div>I want to test whether a sequence of the characters 'A' and 'B' can represent a sequence of the symbols x and y where x may be represented by one or more 'A's and y may be represented by one or more 'A's or one or more 'B's.</div><div><br></div><div>In code, I would like to see the following:</div><div><br></div><div>λ> "AABB" `represents` [x, y]</div><div>True</div><div>λ> "AA" `represents` [x, y]</div><div>True</div><div><br></div><div>But with my current implementation using attoparsec only the first example works as expected:</div><div><br></div><div><div>import Control.Applicative</div><div>import Data.Attoparsec.ByteString.Char8</div><div>import Data.ByteString</div><div>import Data.Either</div><div>import Data.Foldable</div><div>import Data.Word</div><div><br></div><div>type Symbol = Parser [Word8]</div><div><br></div><div>x :: Symbol</div><div>x = many1 (char8 'A')</div><div><br></div><div>y :: Symbol</div><div>y = many1 (char8 'A') <|> many1 (char8 'B')</div><div><br></div><div>represents :: ByteString -> [Symbol] -> Bool</div><div>bs `represents` symbols =</div><div>  isRight $ parseOnly ((sequenceA_ symbols) *> endOfInput) bs</div></div><div><br></div><div><br></div><div>It seems that in</div><div>   "AA" `represents` [x, y]</div><div>x consumes all the 'A's, leaving none for y.</div><div><br></div><div>Is it possible to solve this with attoparsec or are there other parsing libraries that I could use instead?</div><div><br></div><div>Cheers,</div><div>Simon</div></div>