Last active
April 14, 2018 06:45
-
-
Save naoto-ogawa/79439609c90e7fc5eca447da28a00435 to your computer and use it in GitHub Desktop.
Lifting PolyPerse Text.Parse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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