Skip to content

Instantly share code, notes, and snippets.

@virtualsafety
Forked from sw17ch/simple_parser.hs
Created December 8, 2013 12:55
Show Gist options
  • Save virtualsafety/7857074 to your computer and use it in GitHub Desktop.
Save virtualsafety/7857074 to your computer and use it in GitHub Desktop.
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