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.
Separate the test suite into its own package. The reason is that we can
avoid circular dependency on ‘hspec-megaparsec’ and thus avoid keeping
copies of its source files in our test suite, as we had to do before.
Another benefit is that we can export some auxiliary functions in
‘megaparsec-tests’ which can be used by other test suites, for example in
the ‘parser-combinators-tests’ package.
Version of ‘megaparsec-tests’ will be kept in sync with versions of
‘megaparsec’ from now on.
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.
‘scientific’ now correctly backtracks after attempting to parse fractional
and exponent parts of a number. ‘float’ correctly backtracks after
attempting to parse optional exponent part (when it comes after fractional
part, otherwise it's obligatory).