Created
November 27, 2010 06:23
-
-
Save mathfur/717633 to your computer and use it in GitHub Desktop.
【Parsecサンプル】stdinからscan(/\w+/)する
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
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