Skip to content

Instantly share code, notes, and snippets.

@naoto-ogawa
Last active April 14, 2018 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naoto-ogawa/79439609c90e7fc5eca447da28a00435 to your computer and use it in GitHub Desktop.
Save naoto-ogawa/79439609c90e7fc5eca447da28a00435 to your computer and use it in GitHub Desktop.
Lifting PolyPerse Text.Parse
module Test01 where
import Text.Parse
import qualified Text.ParserCombinators.Poly.State as PS
main :: IO ()
main = putStrLn "Test01"
liftP :: Parser t a -> PS.Parser s t a
liftP (P func) = PS.P $ \s tx -> pareResult s (func tx)
where
pareResult :: s -> Result z a -> Result (z, s) a
pareResult s (Success z a) = Success (z, s) a
pareResult s (Failure z e) = Failure (z, s) e
pareResult s (Committed r) = pareResult s r
{-
> PS.runParser (liftP (parens True $ literal "aaa bbb") >> stUpdate (*2) >> (liftP word)) 5 "(aaa bbb) ccc"
(Right "ccc",10,"")
> PS.runParser (liftP (parens True $ literal "aaa bbb") >> stUpdate (*2)) 5 "(aaa bbb) ccc"
(Right (),10," ccc")
PS.runParser (liftP (parens True $ literal "aaa bbb")) 5 "(aaa bbb) ccc"
(Right "aaa bbb",5," ccc")
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment