module Text.Syntax.Parser.ReadP (runAsReadP) where
import Data.List (find)
import Text.Syntax.Parser.Instances ()
import Text.Syntax.Poly.Class
(TryAlternative, Syntax(token))
import Text.Syntax.Poly.Type (RunAsParser, ErrorString, errorString)
import Text.ParserCombinators.ReadP (ReadP, get, readP_to_S)
instance TryAlternative ReadP
instance Syntax Char ReadP where
token = get
runAsReadP :: RunAsParser Char String a ErrorString
runAsReadP parser s =
case find ((== []) . snd) $ readP_to_S parser s of
Just (a, _) -> Right a
Nothing -> Left $ errorString "parse error"