[hs] Solve 2020_02

This commit is contained in:
Joscha 2020-12-03 11:12:27 +00:00
parent 6ad7c5108d
commit 7183f49a6b
4 changed files with 57 additions and 2 deletions

View file

@ -4,9 +4,12 @@ module Aoc.Parse
, module Text.Megaparsec.Char.Lexer
, Parser
, manyLines
, word
, untilEol
) where
import Data.Void
import Data.Char
import qualified Data.Text as T
import Text.Megaparsec
@ -18,4 +21,10 @@ import Text.Megaparsec.Char.Lexer (binary, decimal, float,
type Parser = Parsec Void T.Text
manyLines :: Parser a -> Parser [a]
manyLines p = sepBy p newline <* optional newline <* eof
manyLines p = sepEndBy (try p) newline
word :: Parser T.Text
word = takeWhileP Nothing (not . isSeparator)
untilEol :: Parser T.Text
untilEol = takeWhileP Nothing (/= '\n')