Skip to content

Instantly share code, notes, and snippets.

@manpages
Created July 17, 2015 01:24
Show Gist options
  • Save manpages/484a36cb9b3bdedd8132 to your computer and use it in GitHub Desktop.
Save manpages/484a36cb9b3bdedd8132 to your computer and use it in GitHub Desktop.
Polymorphic eof
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