Commit Graph

150 Commits

Author SHA1 Message Date
mlugg
ccf314b0b9 Add Safe Haskell support
Remove dependence on GeneralizedNewtypeDeriving and add Safe Haskell
extensions to every file.
2020-10-17 18:53:15 +02:00
1computer1
34b34c3d93 Decouple the error reporting-related methods from ‘Stream’
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.
2020-09-02 19:50:45 +02:00
Mark Karpov
46f276a0cc Add ‘hspace’ and ‘hspace1’ functions
These functions are slightly more specific versions of the existing ‘space’
functions. They accept only “horizontal whitespace”.
2020-05-10 22:53:16 +02:00
Brian Wignall
90b46084bb Fix typos 2019-12-26 04:59:24 +01:00
mrkkrp
31b917b129 Allow registration of delayed parse errors
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.
2019-11-07 12:48:56 +01:00
mrkkrp
f8ef95c025 Re-organize error reporting functions
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.
2019-11-05 14:18:55 +01:00
Tobias Markus
9c9f7d4e08 Allow Stream to specify custom token width
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).
2019-10-27 14:58:46 +01:00
mrkkrp
61e69295b2
Merge the changelog entries of 7.1.0 and 8.0.0
It looks like I never got to releasing 7.1.0 so now we're going to just
merge these changes with other changes for 8.0.0.
2019-09-15 23:06:28 +02:00
mrkkrp
ffe596c6ce Drop some CPP, drop support for GHC 8.2.x
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.
2019-09-15 23:00:55 +02:00
mrkkrp
87d425759a Simplify type signatures of ‘reachOffset’ and ‘reachOffsetNoLine’
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.
2019-07-13 17:37:46 +02:00
mrkkrp
42af70a0a0 Drop support for GHC 8.0 2019-07-02 21:06:29 +02:00
mrkkrp
d391a98177 Generalize numeric parsers in lexer modules
It appears that we can relax constraints for ‘decimal’, ‘binary’, ‘octal’,
and ‘hexadecimal’ from ‘Integral’ to ‘Num’ keeping the same implementations.
2019-07-02 19:58:34 +02:00
mrkkrp
570a50e597 Put tests in a separatate package
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.
2019-05-01 19:46:04 +02:00
mrkkrp
48cd5aeaa5
Update the changelog for version 7.0.5
[skip ci]
2019-04-30 22:14:14 +02:00
mrkkrp
b200b09830
Numerous documentation corrections 2018-11-07 12:21:00 +07:00
mrkkrp
290dab4f61
Update the changelog for version 7.0.3
[skip ci]
2018-10-31 17:50:00 +07:00
mrkkrp
ddc6256f16
Update the changelog for version 7.0.2
[skip ci]
2018-10-21 17:29:26 +07:00
Mark Karpov
a6985ad98b
Fix a bug in ‘errorBundlePretty’ (#322)
Previously the question sign ‘?’ was erroneously inserted before offending
line in 2nd and later parse errors.
2018-09-15 16:06:02 +07:00
mrkkrp
dd9d7c43dd
Some adjustments to the changelog for version 7.0.0
[skip ci]
2018-09-04 22:26:28 +07:00
mrkkrp
736921b798
Mention the adjustment to the ‘label’ primitive in the changelog
[skip ci]
2018-09-04 22:22:25 +07:00
Mark Karpov
9698fe325c
Implement the ‘attachSourcePos’ function (#320) 2018-09-03 22:16:27 +07:00
Mark Karpov
573bacf721
Use offset in parse errors (#313)
The change allows to speed-up parsers in most cases and re-use the fact that
we're traversing input stream on pretty-printing ‘ParseError’s anyway.
2018-08-20 23:35:10 +07:00
mrkkrp
269ad9091f
Fix a typo in the changelog
[skip ci]
2018-08-16 19:57:58 +07:00
Mark Karpov
65adeb7574
Improve case-insensitive char matching (#310)
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.
2018-07-22 14:29:09 +07:00
Mark Karpov
4ea6a01896
Introduce parse error bundle (#306)
* Introduce parse error bundle

* Update the changelog (parse error bundle)
2018-07-15 20:01:35 +07:00
Mark Karpov
6a88c01eb2
Refactoring of stream-specific modules (#305)
Stream specific modules should not import form each other.
2018-07-08 22:11:31 +07:00
Vladislav Zavialov
b804acdf85 Add 'withParsecT' and 'mapParseError' (#303) 2018-07-05 11:00:17 +07:00
Gaith Hallak
f3e26a4223
Add ‘binDigitChar’ and ‘binary’ 2018-06-23 15:40:35 +07:00
mrkkrp
d11bd696d6
Add changelog entry for the ‘charLiteral’ fix and a new test
It appears that 9 is quite enough here.
2018-05-18 23:05:12 +07:00
Mark Karpov
90966cb379
Implement continuous highlighting in parse errors (#296) 2018-05-09 18:37:28 +07:00
Mark Karpov
517fbca634
Drop ‘Text.Megaparsec.Expr’ (#294) 2018-04-28 18:48:17 +07:00
Mark Karpov
8f21659822
Drop ‘Text.Megaparsec.Perm’ (#292)
In favor of ‘Control.Applicative.Premutations’, and so we add tests for that
module.
2018-04-27 17:13:27 +07:00
mrkkrp
7120bae9b2
Drop stacks of source positions 2018-04-20 19:24:05 +07:00
mrkkrp
cdbbe5c3d0
Move ‘dbg’ into a separate module 2018-04-20 14:20:43 +07:00
mrkkrp
2d175cd706
Drop support for GHC 7.8 2018-04-20 13:07:16 +07:00
Mark Karpov
e3ce90bd73 Add ‘Text.Megaparsec.Internal’ (#288) 2018-03-27 22:02:24 +07:00
Mark Karpov
adce847803 Fix backtracking of exponent and fractional parts in numeric helpers (#279)
‘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).
2018-03-04 20:34:48 +07:00
Mark Karpov
4fac009b48
Move general-enough combinators to ‘Text.Megaparsec’ (#267) 2018-01-08 22:39:39 +07:00
Mark Karpov
c776fc16fb Use parser combinators 0.4.0 (#269) 2017-12-31 16:02:03 +07:00
Mark Karpov
d3e29619cc
Simplify the type of the ‘token’ primitive (#266) 2017-12-17 22:03:03 +07:00
Mark Karpov
aee96cd519
Make ‘atEnd’ not produce hints (#264) 2017-12-17 13:03:56 +07:00
mrkkrp
cd14be5db1 A minor correction in the changelog
[skip ci]
2017-12-15 11:49:55 +07:00
mrkkrp
f4ded98663 There will be no ‘megaparsec-6.2.1’
[skip ci]
2017-12-14 12:06:53 +07:00
Vladislav Zavialov
58ab67759f Add the 'customFailure' combinator (#260) 2017-12-14 11:20:04 +07:00
Vladislav Zavialov
576c29aefd Add an IsString instance and tests for it (#259) 2017-12-13 22:14:22 +07:00
Mark Karpov
b99174d7f1 Make ‘sconcat’ more efficient on ‘ParsecT’ (#253)
* Make ‘sconcat’ more efficient on ‘ParsecT’

* Do the same thing for ‘mconcat’
2017-10-15 16:26:28 +07:00
mrkkrp
07160049a8 Make ‘float’ consume only floating point literals
Now it no longer accepts plain integers, which should be a better behavior.
2017-09-21 22:01:39 +07:00
Mark Karpov
e2abc9ee5d Use ‘eok’ continuation in ‘tokens’ when matching empty chunk (#246) 2017-08-14 17:46:59 +07:00
Mark Karpov
aac10c8bee Add hint erasing when try backtracks consuming (#243) 2017-08-08 16:36:47 +07:00
Mark Karpov
5b6f6f30cf Fix rendering of offending line with tabs (#241) 2017-08-08 14:59:24 +07:00