Commit Graph

314 Commits

Author SHA1 Message Date
mrkkrp
df3b3016d5 Make ‘pToken’ lazier (position updating)
Evaluation of ‘npos’ is not necessary when we are going to report an
error. Similarly, evaluation of current position is not necessary when
we just need to get incremented position. This seemingly minor change
has profound impact on performance because call to ‘token’ function is
at the base of significant part of parsing process.
2016-05-02 00:53:42 +07:00
mrkkrp
1094408b96 Add ‘pushPosition’ and ‘popPosition’
Close #83.
2016-04-27 00:04:56 +07:00
mrkkrp
8e095bab8c A correction to ‘getPosition’ and ‘setPosition’
Make ‘getPosition’ and ‘setPosition’ work with current file, not with
the whole stack.
2016-04-26 23:01:09 +07:00
mrkkrp
f22cd69ff7 Cosmetic polishing 2016-04-26 00:37:06 +07:00
mrkkrp
13578590da Adjustments for compatibility 2016-04-25 19:51:13 +07:00
mrkkrp
be3c1fe987 Derive ‘Read’ instance for ‘Dec’ 2016-04-24 20:19:48 +07:00
mrkkrp
495aa1bb87 Add ‘incorrectIndent’, improve indentation errors
Close #90.
2016-04-24 15:09:52 +07:00
mrkkrp
1ba128521f Make ‘tokens’ use “canonicalized” token streams
And introduce the notion in docs of ‘MessageItem’.
2016-04-23 22:31:09 +07:00
mrkkrp
dd0cf0fe4a Add one more argument to ‘token’
The new argument allows to specify what to report as expected token when
input stream happens to be empty.
2016-04-22 19:51:14 +07:00
mrkkrp
c0c9b836dd Fix a bug (hints assymetry with ‘<|>’) 2016-04-22 19:48:55 +07:00
mrkkrp
17a6bb2baa Remove ‘MonadThrow’ instance, add ‘Dec’
‘Dec’ stands for “default error component”. We need this because
‘String’ looses information and thus we cannot write good enough tests
with it.
2016-04-22 19:48:34 +07:00
mrkkrp
eedf69761e Remove redundant constraints from lexer module 2016-04-18 21:52:45 +07:00
mrkkrp
84038a4fab Export ‘parseErrorPretty’ from ‘Text.Megaparsec’ 2016-04-18 20:48:31 +07:00
mrkkrp
f3f0aef44e Improve docs of ‘Text.Megaparsec.Prim’ 2016-04-18 19:49:52 +07:00
mrkkrp
006900e257 Add missing ‘@since’ labels to new functions 2016-04-18 19:49:20 +07:00
mrkkrp
fee19134e8 Improve new version of ‘Text.Megaparsec.Error’
Compatibility and documentation improvements.
2016-04-18 19:05:34 +07:00
mrkkrp
641114a442 Improve new version of ‘Text.Megaparsec.Pos’
Documentation improvements. The commit also makes it compile with all
supported GHC versions.
2016-04-18 17:59:32 +07:00
mrkkrp
acbae63a21 First attempt to outline Megaparsec 5.0.0
This is rather a sketch, we need to work on documentation, tests, and
perhaps on performance, but it should show the direction Megaparsec
5.0.0 is taking.
2016-04-17 20:08:13 +07:00
mrkkrp
a3254f5371 Move language extensions to files
This turns out that it's easier for readers to lookup the list of
extensions in current file than go to Cabal file.
2016-04-10 19:26:54 +07:00
mrkkrp
747993e0bb Add ‘skipBlockCommentNested’ function
Close #96.
2016-03-30 14:50:35 +06:00
mrkkrp
18d192ba70 Use ‘Scientific’ as target type for floats
Close #95.

Here we introduce ‘scientific’ parser that can parse arbitrary big
numbers without error or memory overflow. ‘float’ still returns
‘Double’, but it's defined in terms of ‘scientific’ now. Since
‘Scientific’ type can reliably represent integer values as well as
floating point values, ‘number’ now returns ‘Scientific’ instead of
‘Either Integer Double’ (‘Integer’ or ‘Double’ can be extracted from
‘Scientific’ value anyway). This in turn makes ‘signed’ parser more
natural and general, because we do not need ad-hoc ‘Signed’ type class
anymore.
2016-03-29 16:42:51 +06:00
mrkkrp
39b9ffb083 Add “since 5.0.0” to haddocks of new functions 2016-03-28 21:10:00 +06:00
mrkkrp
0f7a2c180c Improve efficiency of the library 2016-03-28 15:43:03 +06:00
mrkkrp
ac99fc0fac More flexible position-advancing function
This should improve experience of users who use Megaparsec with Alex and
Happy. The commit also introduces some minor changes in
‘Text.Megaparsec.Pos’ module (improving argument order).
2016-03-24 18:12:25 +06:00
recursion-ninja
dccfc82152 Replace ‘String’ with ‘Foldable f => f Char’
The commit also deals with GHC 8 warnings about redundant constraints.
2016-03-11 15:52:55 +06:00
mrkkrp
b0124d1ea2 Remove ‘parseFromFile’ and ‘StorableStream’
Removed ‘parseFromFile’ and ‘StorableStream’ type-class that was
necessary for it. The reason for removal is that reading from file and
then parsing its contents is trivial for every instance of ‘Stream’ and
this function provides no way to use newer methods for running a parser,
such as ‘runParser'’. So, simply put, it adds little value and was
included in 4.x versions for compatibility purposes.
2016-02-22 19:52:57 +06:00
mrkkrp
750adb7c70 A minor improvement in docs of ‘makeExprParser’ 2016-02-20 14:36:15 +06:00
mrkkrp
30fcbb64ef Fix the build for older GHCs 2016-02-19 17:01:08 +06:00
mrkkrp
eef1fa7ea9 Further improve coverage 2016-02-19 16:15:32 +06:00
mrkkrp
5a68665a90 Change collection of constraints for ‘MonadParsec’
Collection of constraints changed from ‘Alternative m, Monad m, Stream s
t’ to ‘MonadPlus m, Stream s t’. This is done to make it easier to write
more abstract code with older GHC where such primitives as ‘guard’ are
defined for instances of ‘MonadPlus’, not ‘Alternative’.
2016-02-19 16:02:52 +06:00
mrkkrp
4c34c488cc Remove ‘Enum’ instance of ‘Message’
This was Parsec's legacy that we should eliminate now. ‘Message’ does
not constitute enumeration, ‘toEnum’ was never properly defined for
it. The idea to use ‘fromEnum’ to determine type of ‘Message’ is also
ugly, for this purpose new functions ‘isUnexpected’, ‘isExpected’, and
‘isMessage’ are defined in ‘Text.Megaparsec.Error’.
2016-02-18 16:26:29 +06:00
mrkkrp
0987c55b2b Cosmetic whims 2016-02-18 15:59:58 +06:00
mrkkrp
52b41d4992 Add the ‘eitherP’ combinator
Close #85.
2016-02-18 14:46:55 +06:00
mrkkrp
e9df1ba30a Correct ‘withRecovery’ so that it passes the tests 2016-02-18 13:09:19 +06:00
mrkkrp
3baa263eab Auto-backtracking for ‘tokens’ and friends 2016-02-17 23:32:48 +06:00
mrkkrp
3edbe9f54a Implement the recovery feature
Close #80.
2016-02-09 13:59:21 +06:00
Herbert Valerio Riedel
ba9bd6a25e Define MonadFail & Semigroup instances
This also enables the respective warnings flags in dev mode
to help megaparsec remain forward compatible.

The dependencies on `semigroup` and `fail` are conditional on
`impl(ghc >= 8)` and avoid CPP and conditionally defined instances
(which would result in an conditional API).
2016-02-08 11:38:10 +01:00
mrkkrp
e1be100bd6 Cosmetic whims
Can't help it…
2016-02-08 13:36:39 +06:00
mrkkrp
c2c33045cc Fix the build for older GHCs 2016-02-07 20:50:27 +06:00
mrkkrp
7727821c2a Make some combinators more efficient 2016-02-07 19:42:11 +06:00
mrkkrp
4bde699b84 Support getting actual parser state on failure
Close #81.

This solution is mostly OK as it passes tests and almost all benchmarks
show that there is no performance degradation.

The only function that bothers me is ‘pPlus’ (or ‘mplus’, or
‘<|>’). Benchmarks ‘choice/match’, ‘choice/nomatch’, and ‘manyTill’ show
about 44 % worse performance with current implementation of the feature
— this is not acceptable. All these functions are defined via ‘mplus’,
so it's necessary to find a way to improve that function.

Also, ‘mplus’ is tricky in that it combines different branches of
parsing. Previously, all logic describing how to combine failing
branches into one ‘ParseError’ were in ‘mergeError’ function. Now we
have to have ‘longestMatch’ function to choose right state as well,
because it's natural to expect that state on failure would correspond to
‘ParseError’. This should be done elegantly.
2016-02-06 17:59:50 +06:00
mrkkrp
9918dd5ad9 Add missing per-argument descriptions 2016-01-22 20:20:36 +06:00
mrkkrp
24b8e41af0 Remove non-informative phrases from docs
Parsec's legacy.
2016-01-22 13:00:58 +06:00
mrkkrp
c2f5504725 Fix a typo ‘ParserT’ → ‘ParsecT’ 2016-01-22 12:47:15 +06:00
mrkkrp
611f2a4e7e Minor improvements for new combinators
In particular, if input has no newline at the end, we need to treat it
specially, because otherwise we will get confusing “incorrect
indentation” message.
2016-01-10 23:23:26 +06:00
mrkkrp
6f102ce1fe Fix signature of ‘indentBlock’ 2016-01-09 23:21:04 +06:00
mrkkrp
e9bf0e1773 Specify in which version some functions were added 2016-01-09 19:12:22 +06:00
mrkkrp
e5508941c8 Add year 2016 to copyright notices 2016-01-09 18:56:33 +06:00
mrkkrp
bd85deb38c Finish new indentation-sensitive combinators 2016-01-09 17:38:31 +06:00
mrkkrp
8984f5823a Improved indentation-sensitive combinators
Close #54.

These should be good enough (according to manual testing). We'll need to
add automated testing to make sure, though.
2016-01-02 20:30:36 +06:00
mrkkrp
718b0f358a Don't use hints with custom error messages
Close #75.

Now accumulated hints are not used with ‘ParseError’ records that have
only custom messages in them (created with ‘Message’ constructor, as
opposed to ‘Unexpected’ or ‘Expected’). This strips “expected” line from
custom error messages where it's unlikely to be relevant anyway.
2016-01-02 20:19:40 +06:00
mrkkrp
028b775885 Use ‘const’ 2016-01-02 20:18:55 +06:00
mrkkrp
c73a2239b9 ‘readFromFile’ → ‘parseFromFile’ 2016-01-02 20:18:18 +06:00
mrkkrp
e94b39fc0d Initial design of new indentation-sensitive helpers 2016-01-01 23:00:38 +06:00
mrkkrp
f317936613 Cosmetic whims in ‘Text.Megaparsec.Lexer’ 2016-01-01 23:00:38 +06:00
mrkkrp
8ea4ebe606 improve rendering of ‘Message’s
Arbitrary messages created with ‘Message’ constructor should not be
rendered as “or”-separated list. This commit makes every such message be
displayed on new line.
2015-12-11 12:18:11 +06:00
Herbert Valerio Riedel
bc54b46d07 Canonicalise Applicative/Monad instances
This avoids subtle performance issues and makes the code more
future proof.
2015-11-22 19:03:46 +01:00
mrkkrp
c202151150 minor documentation improvements 2015-11-10 14:28:28 +06:00
mrkkrp
3bc781d270 minor improvements in ‘Text.Megaparsec.Combinator’ 2015-11-09 13:19:34 +06:00
mrkkrp
3d66a02eaf make source name in ‘SourcePos’ strict 2015-11-07 18:36:44 +06:00
mrkkrp
ac62addce8 cosmetic improvements 2015-11-07 16:24:45 +06:00
mrkkrp
60910b520f don't parse row of prefix/postfix operators
After some thinking I decided that this may be not desirable in some
cases, so we should not enable it by default. I've edited documentation
of ‘makeExprParser’ to explain why this doesn't work by default and how
to make it work.
2015-11-03 16:09:35 +06:00
mrkkrp
73042c28f3 fix build once again for older GHCs 2015-11-03 01:59:30 +06:00
mrkkrp
d595562e88 allow to parse rows of prefix/postfix operators
Close #64.

‘makeExprParser’ now generates parser that can handle several
occurrences of the same prefix or postfix operator in a row. This allows
to parse something like C pointers (for example ‘**i’) without resorting
to hacks.

The feature is experimental, I'm not entirely sure it's not
buggy. Upcoming additional tests for ‘Text.Megaparsec.Expr’ will show
whether it behaves correctly in all cases and doesn't have adverse
effects. For now, I've edited existing test to generate data with
repeating prefix negations and postfix factorials. Current code-base
passes the test.
2015-11-03 01:55:18 +06:00
mrkkrp
9f6fc4844c correct error message signalled by ‘many’
Close #69.

Although previously used syntax is correct Haskell syntax for multi-line
string literals, CPP extension that we need to use for compatibility
reasons obviously makes ‘\’ symbol escape following newline character
that leads to ‘\t’ being interpreted as tab character.

The proposed solution just concatenates result error message from list
of strings — the most lightweight and reliable solution in our case.
2015-10-31 18:03:33 +06:00
mrkkrp
8c7de12ab7 rather fail loudly instead of silent correction 2015-10-30 21:40:22 +06:00
mrkkrp
c7ed5fe909 after some consulting, it should be “FreeBSD”
What Parsec used is called “FreeBSD” or “BSD 2 clause”. Addition of the
third clause may require contacting all the authors. To hell with it,
let it be “FreeBSD” (which is anyway better than “BSD-like”), I'm a
hacker, not a lawyer (tm).
2015-10-30 17:26:45 +06:00
mrkkrp
503a1db4be clarify used license and add missing clause
This commit clarifies license of the software replacing “BSD3” with more
conventional “BSD 3 clause”.

Another change is addition of the third clause originally missing in
license of Parsec (which is licensed under BSD 2 clause license). The
addition of the third clause in form:

* Neither the names of the copyright holders nor the names of
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

does not violate original BSD 2 clause license effectively making it BSD
3 clause license (which I find preferable).
2015-10-30 13:52:30 +06:00
mrkkrp
92d28bb7e8 allow ‘number’ be used with ‘signed’
Close #67.
2015-10-28 13:46:32 +06:00
mrkkrp
6aedfdbc79 removed deprecated combinators
Expression parser should be improved a bit now before 4.2.0 is released,
see #64.
2015-10-26 18:54:02 +06:00
mrkkrp
4e6dffd785 fix build for older GHCs 2015-10-26 14:06:15 +06:00
mrkkrp
354760202e introduced ‘failure’ method of ‘MonadParsec’
Close #43.

The method allows to fail with arbitrary collection of
messages. ‘unexpected’ is not defined in terms of ‘failure’. One
consequence of this design decision is that ‘failure’ is now method of
‘MonadParsec’, while ‘unexpected’ is not.
2015-10-26 13:52:21 +06:00
mrkkrp
c548226a1c map monad with ‘liftM’ for older GHCs 2015-10-26 02:20:25 +06:00
mrkkrp
a5819c6d00 allow to supply and extract parser state
Close #47, close #57.

This commit introduces ‘runParser'’ and ‘runParserT'’ functions that
take and return parser state. This makes it possible to partially parse
input, resume parsing, specify non-standard initial textual position,
etc.

Internal changes involve some refactoring to make ‘Reply’ more
readable and facilitate extraction of complete parser state on failure
as well as success.

The commit adds basic tests for the new functionality as well.
2015-10-26 02:13:39 +06:00
mrkkrp
ec6098c7ac various whims 2015-10-25 22:20:05 +06:00
mrkkrp
05177a6c3c make ‘ParseError’ instance of ‘Exception’
Close #66.
2015-10-24 11:24:13 +06:00
mrkkrp
258dd2a0d4 add documentation for ‘StorableStream’ type class 2015-10-22 16:56:51 +06:00
mrkkrp
7043a6fbc0 move ‘parseFromFile’ to ‘Text.Megaparsec.Prim’
Close #65.

Previously we had 5 nearly identical definitions of the function,
varying only in type-specific ‘readFile’ function. Now the problem is
solved by introduction of ‘StorableStream’ type class. All supported
stream types are instances of the class out of box and thus we have
polymorphic version of ‘parseFromFile’.
2015-10-22 15:32:33 +06:00
mrkkrp
aad1702589 use ‘if’ instead of ‘bool’
This should make maintenance a bit easier. After all ‘if’ looks even
better than ‘bool’ in many cases.
2015-10-22 14:34:25 +06:00
mrkkrp
6cf7e918ce fix build for older versions of ‘base’ 2015-10-21 19:57:23 +06:00
mrkkrp
48528af655 various changes in ‘Text.Megaparsec.Error’
Close #62.

Apart from some refactoring, the following important changes were
introduced:

* ‘ParseError’ is now a monoid.

* Added functions ‘addErrorMessages’ and ‘newErrorMessages’.
2015-10-21 19:36:43 +06:00
mrkkrp
8356a05919 made interface of ‘Text.Megaparsec.Pos’ smarter
Now it's impossible to create ‘SourcePos’ with non-positive line number
or column number. Unfortunately we cannot use ‘Numeric.Natural’ because
we need to support older versions of ‘base’.
2015-10-21 17:33:29 +06:00
mrkkrp
bedad01d98 cosmetic improvements 2015-10-20 22:10:52 +06:00
mrkkrp
f3be336ebe fix implementation of ‘sepEndBy’ and ‘sepEndBy1’
Fixes #63.

Deprecation notes were removed and new tests written.
2015-10-20 16:37:24 +06:00
mrkkrp
3e5dc6d5a4 improve wording in doc-string for ‘charLiteral’ 2015-10-16 16:31:22 +06:00
mrkkrp
81b0081028 add missing ‘L.’ in doc-string of ‘signed’ 2015-10-16 15:57:46 +06:00
mrkkrp
9e1cac87b8 removed redundant labels in ‘Text.Megaparsec.Char’
This is handled by ‘showToken’ in ‘char’ anyway, so there is no need to
label these things manually.
2015-10-16 15:01:35 +06:00
mrkkrp
79ceb7962f eliminate indentation in error messages
Indented text returned by ‘showMessages’ may be undesirable, but we
cannot add indentation outside of the function (edge case: strings
including newline are displayed in the messages).
2015-10-15 15:12:28 +06:00
mrkkrp
b062a397ee made format of error messages conventional
Closes #56.

In particular, file name and textual position are represented like this:

  filename.hs:5:6:
    error message

This format should be more conventional, so various tools will be able
to parse it and provide some support (for example, Emacs can work with
this format).
2015-10-14 17:48:44 +06:00
mrkkrp
a9421728d6 typos and corrections 2015-10-10 20:45:27 +06:00
mrkkrp
a70e07a408 do not export ‘Consumed’ and ‘Reply’
‘Text.Megaparsec’ and ‘Text.Megaparsec.Prim’ do not export these data
types and their constructors anymore. These data types are rather
low-level implementation detail that should not be visible to
end-user. They are also subject to certain changes in future.
2015-10-06 22:36:59 +06:00
Benjamin Kaestner
65aa745a58 Add #if for bool :: a -> a -> Bool -> a. 2015-10-03 16:52:20 +02:00
Benjamin Kaestner
d97398a016 Add compatibility to base-4.7.0.x
This patch introduces compatibility to base-4.7.0.x. It was tested
on Win 8.1 x86_64, using GHC 7.8.4. It mainly consists of a bunch
of #if !MIN_VERSION(4,8,0) ... #endif additions and a lower bound
on base in the cabal file as well as a general introduction of the
CPP extension via default-extensions.

It also removes a potential error source in tests/Util.hs, since
the backslash in /=\ can lead to strange quirks on certain systems
(backslash and newline only separated by whitespace).

Other, squashed commits:

- Remove 'recent version of base' from Readme

- Change necessary version of GHC
2015-09-30 20:18:25 +02:00
Artyom
5efa258644 reponsibilitity → responsibility 2015-09-30 16:09:08 +03:00
mrkkrp
321b781e29 refresh values of “Portability” field
‘Text.Megaparsec.Prim’ cannot be considered portable since it uses
multi-parameter type classes and functional dependencies.

Other modules that depend on these non-portable features from
‘Text.Megaparsec.Prim’ should be considered non-portable too.
2015-09-27 14:46:12 +06:00
mrkkrp
319addf767 use ‘ExistentialQuantification’ locally
Only in module ‘Text.Megaparsec.Perm’ where it is necessary.
2015-09-27 14:27:01 +06:00
mrkkrp
9774ed9de9 rename ‘parse'’ → ‘parseMaybe’ 2015-09-24 17:13:06 +06:00
mrkkrp
1896856e1c move fixity declaration for (<?>) where it belongs 2015-09-23 21:04:51 +06:00
mrkkrp
1617f9b1b8 even more cosmetic corrections
Make details consistent and fix some minor cosmetic issues.
2015-09-23 19:46:24 +06:00
mrkkrp
3975ae52d0 cosmetic improvements, courtesy of @neongreen
Closes #37.

Most part of these changes is proposed by @neongreen. To apply precisely
what I deem acceptable, correct some of them in other way, and add some
other things, I've manually re-edited this.
2015-09-23 17:23:24 +06:00