Created
March 16, 2012 03:08
-
-
Save sw17ch/2048304 to your computer and use it in GitHub Desktop.
An example of a simple parser for my blog post about Text.Parsec.Indent.
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 Main where | |
import Text.Parsec | |
import Text.Parsec.String | |
input_text :: String | |
input_text = "foo123:" | |
main :: IO () | |
main = do | |
case parse aParser "example" input_text of | |
Left err -> print err | |
Right res -> putStrLn $ "I parsed: '" ++ res ++ "'" | |
aParser :: Parser String | |
aParser = do | |
s <- many1 alphaNum | |
_ <- char ':' | |
return s | |
{- | |
- Output: | |
- > runhaskell -Wall parsec_example.hs | |
- I parsed: 'foo123' | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment