Copyright | (c) Eric Mertens 2018-2021 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
When day is specified as 0
the quasiquoter returns a pure
parser function. Otherwise day uses command line arguments
to find the input file and parses it as an IO action.
A format string can optionally be specified across multiple
lines. In this case the day number goes on the first line and
the pattern starts on the second line. All common leading white
space from all the remaining lines is trimmed off and newlines
are discarded (use %n
for matching newlines)
The following are identical:
example1 = [format|1 %s%n %s%n|] example2 = [format|1 %s%n%s%n|]
Patterns:
%u
unsigned integer asInt
%d
signed integer asInt
%lu
unsigned integer asInteger
%ld
signed integer asInteger
%s
non-empty list of non-space characters asString
%c
single, non-newline character asChar
%a
single ASCII letter asChar
%n
single newline character- other characters match literally
- use
%
to escape literal matches of special characters @A
matches the names of the constructors of typeA
as anA
Structures:
p|q
combine alternativesp
andq
(pq)
group subpatternpq
p*
zero-to-many repititions ofp
as a '[]'p+
one-to-many repititions ofp
as a '[]'p&q
zero-to-many repititions ofp
separated byq
as a '[]'p!
returns the characters that matched patternp
as aString
Documentation
format :: QuasiQuoter Source #
Constructs an input parser. See Advent.Format
follows :: Format -> [Format] -> [Format] Source #
Prefix a list of format strings with a format string.
If the given list has all the topmost Follow
constructors
removed, the output list will as well. Any consecutive literals found
while flattening will be combined.
enumParser :: String -> ExpQ Source #