Skip to content

Instantly share code, notes, and snippets.

@mathfur
Created November 27, 2010 06:23
Show Gist options
  • Save mathfur/717633 to your computer and use it in GitHub Desktop.
Save mathfur/717633 to your computer and use it in GitHub Desktop.
【Parsecサンプル】stdinからscan(/\w+/)する
import Text.ParserCombinators.Parsec
inFix :: Parser a -> Parser a
inFix p = try (p) <|> try(anyChar >> inFix p)
q :: Parser String
q = do
string "foo(\""
cs <- many1 (letter <|> char '_' <|> char '.')
string "\")"
return cs
p :: Parser [String]
p = many ( inFix q )
main = do
cnt <- getContents
case ( parse p "" cnt ) of
Right e -> mapM_ putStrLn e
Left e -> print "<<error>>" >> print e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment