Created
July 17, 2015 01:24
-
-
Save manpages/484a36cb9b3bdedd8132 to your computer and use it in GitHub Desktop.
Polymorphic eof
This file contains hidden or 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
type PE a = Either ParseError a | |
raw :: IO String | |
raw = readFile "real.data" | |
date :: Parsec String a String | |
date = extract | |
where | |
extract = string "Date: " *> many1 (noneOf "\n") <* newline | |
model :: Parsec String a [String] | |
model = many1 $ date <* stuff | |
where | |
stuff = (manyTill anyChar $ try (lookAhead $ string "Date: ")) <|> eof' "" | |
eof' x = do | |
eof | |
return x | |
runModel :: String -> PE [String] | |
runModel x = runIdentity $ runParserT model () "" x | |
main :: IO () | |
main = do | |
r <- raw | |
putStrLn $ show $ runModel r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment