Idris2/samples/StringParser.idr

32 lines
801 B
Idris
Raw Normal View History

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