I am trying to parse a limited set of valid strings which have a common prefix with attoparsec. However, My attempts result in either a Partial
result or a premature Done
:
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import qualified Data.Attoparsec.Text as PT
data Thing = Foobar | Foobaz | Foobarz
thingParser1 = PT.string "foobarz" *> return Foobarz
<|> PT.string "foobaz" *> return Foobaz
<|> PT.string "foobar" *> return Foobar
thingParser2 = PT.string "foobar" *> return Foobar
<|> PT.string "foobaz" *> return Foobaz
<|> PT.string "foobarz" *> return Foobarz
What I want is for "foobar" to result in Foobar
, "foobarz" to result in Foobarz
and "foobaz" to result in Foobaz
. However
PT.parse thingParser1 "foobar"
results in a PT.Partial
and
PT.parse thingParser2 "foobarz"
results in a PT.Done "z" Foobar
.