[hs] Solve 2020_04

This commit is contained in:
Joscha 2020-12-04 13:09:49 +00:00
parent c48319423d
commit e2f1687798
3 changed files with 183 additions and 2 deletions

View file

@ -4,10 +4,13 @@ module Aoc.Parse
, module Text.Megaparsec.Char.Lexer
, Parser
, manyLines
, oneSpace
, untilSpace
, untilEol
, lineChar
) where
import Data.Char
import Data.Void
import qualified Data.Text as T
@ -22,8 +25,14 @@ type Parser = Parsec Void T.Text
manyLines :: Parser a -> Parser [a]
manyLines p = endBy (try p) newline
oneSpace :: Parser Char
oneSpace = label "whitespace character" $ satisfy isSpace
untilSpace :: Parser T.Text
untilSpace = takeWhileP (Just "non-whitespace character") (not . isSpace)
untilEol :: Parser T.Text
untilEol = takeWhileP Nothing (/= '\n')
untilEol = takeWhileP (Just "non-newline character") (/= '\n')
lineChar :: Parser Char
lineChar = satisfy (/= '\n')
lineChar = label "non-newline character" $ satisfy (/= '\n')