Skip to content

Instantly share code, notes, and snippets.

@sw17ch
Created March 16, 2012 03:08
Show Gist options
  • Save sw17ch/2048304 to your computer and use it in GitHub Desktop.
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.
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