Idris2/samples/StringParser.idr
Niklas Larsson 39535bf11a Add lifting
2020-07-05 21:51:11 +02:00

32 lines
801 B
Idris

module Main
import Data.String.Parser
import Control.Monad.Identity
import Control.Monad.Trans
%default partial
-- Buld this program with '-p contrib'
parseStuff : ParseT IO ()
parseStuff = do a <- string "abc"
lift $ putStrLn "hiya"
b <- string "def"
pure ()
main : IO ()
main = do
res <- parseT parseStuff "abcdef"
res <- parseT (string "hi") "hideous"
case res of
Left err => putStrLn "NOOOOOOO!"
Right () => putStrLn "YEEEES!"
digs <- parseT (satisfy isDigit) "8878993"
case digs of
Left err => putStrLn "NOOOOOOO!"
Right ds => printLn ds
migs <- parseT (many (satisfy isDigit)) "766775"
case migs of
Left err => putStrLn "NOOOOOOO!"
Right ds => printLn ds
pure ()