Split the ‘Stream’ type class. The methods ‘showTokens’ and ‘tokensLength’
have been put into a separate type class ‘VisualStream’, while ‘reachOffset’
and ‘reachOffsetNoLine’ are now in ‘TraversableStream’. This should make
defining ‘Stream’ instances for custom streams easier.
Defined ‘Stream’ instances for lists and ‘Seq’s.
Megaparsec now supports registration of “delayed” parse errors. On lower
level we added a new field called ‘stateParseErrors’ to the ‘State’ record.
The type also had to change from ‘State s’ to ‘State s e’. This field
contains the list of registered ‘ParseErrors’ that do not end parsing
immediately but still will cause failure in the end if the list is not
empty. Users are expected to register parse errors using the three
functions: ‘registerParseError’, ‘registerFailure’, and
‘registerFancyFailure’. These functions are analogous to those without the
‘register’ prefix, except that they have “delayed” effect.
The methods ‘failure’ and ‘fancyFailure’ of ‘MonadParsec’ are now ordinary
functions and live in ‘Text.Megaparsec’. They are defined in terms of the
new ‘parseError’ method of ‘MonadParsec’. This method allows us to signal
parse errors at a given offset without manipulating parser state manually.
Currently, the errorItemLength function implicitly assumes that every token
spans exactly one character. That assumption is correct for the Stream
instances for the basic string types (String/Text/ByteString) included in
Megaparsec. It does not necessarily hold for custom token types however,
in particular if using a separate lexer pass.
This commit adds a new tokensLength function that allows the Stream instance
to give a custom width for a non-empty token stream.
In practice, parse errors concerning a token with a width greater than 1
are currently rendered incorrectly (only one caret is displayed below
the offending token).
Since there are currently blockers preventing compilation of ‘cirterion’
with GHC 8.8.1, I've decided not to add this version of GHC to the build
matrix and add it later instead.
Changed type signatures of ‘reachOffset’ and ‘reachOffsetNoLine’ methods of
the ‘Stream’ type class. Instead of three-tuple ‘reachOffset’ now returns
two-tuple because ‘SourcePos’ is already contained in the returned
‘PosState’ record.
It appears that we can relax constraints for ‘decimal’, ‘binary’, ‘octal’,
and ‘hexadecimal’ from ‘Integral’ to ‘Num’ keeping the same implementations.
Base 4.13 will remove the fail method from the Monad class
so we no longer have to/can define it.
So we remove the the definitions from the Monad instances
using CPP for versions of base >= 4.13
Commit 56c89cba24 removed a CPP
conditional. mtl Control.Monad.Identity only exports
Control.Monad.Trans.Identity as of v2.2.2. Therefore IdentityT is
not in scope with mtl < v2.2.2. and the build fails.
Restore the CPP block to fix building with mtl < v2.2.2.
Improved case-insensitive character matching in the cases when e.g.
‘isLower’ and ‘isUpper’ both return ‘False’. Functions affected:
‘Text.Megaparsec.Char.char'’.
Also re-implemented ‘Text.Megaparsec.Byte.char'’ without semantic changes.