Commit Graph

170 Commits

Author SHA1 Message Date
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
mrkkrp
d0409a897e implemented flexible tab width
Closes #38.

Now tab width can be manipulated with via the following functions:

* ‘getTabWidth’
* ‘setTabWidth’

Other auxiliary changes were performed, such as updating of
‘updatePosChar’.

This also corrects a bit obsolete descriptions of some functions.
2015-09-23 16:47:17 +06:00
mrkkrp
38abf590db make ‘string'’ return actually parsed input
Closes #36.

We should try to preserve original information where possible. User then
can convert case of parsed string if necessary. Previous implementation
discarded actually parsed string and returned argument of the
function — this can be considered as data loss of a sort.
2015-09-23 11:43:58 +06:00
mrkkrp
9adf4c7d46 use constant instead of literal string 2015-09-23 11:13:22 +06:00
mrkkrp
fbc08037ba eliminate little used type synonyms
The type synonyms seem to be little used: ‘SourceName’, ‘Line’, and
‘Column’. They rather contaminate name space.
2015-09-23 11:10:22 +06:00
Artyom
935f3eeecc Fix the explanation for 'try' 2015-09-23 10:57:47 +06:00
mrkkrp
de63d7a0ad fixed a couple of typos in comments 2015-09-22 23:30:54 +06:00
mrkkrp
dcc53ad0b7 improved error messages for labelled ‘many’
Closes #35.

Since ‘many’ (and thus ‘some’) are the only combinator that can succeed
consuming input and produce hints at the same time we can conclude that
‘cok'’ continuation in ‘pLabel’ combinator is only called when ‘many’ is
labelled. By correcting label in this case prepending the phrase “rest
of ” to actual label we can greatly improve result error message.
2015-09-22 15:09:40 +06:00
mrkkrp
dbfa03221c correct ‘lookAhead’ and ‘notFollowedBy’
…for some instances of ‘MonadParsec’.
2015-09-21 15:31:19 +06:00
mrkkrp
ce1655c980 some transformers are instances of ‘MonadParsec’
In particular:

* ‘Lazy.StateT’
* ‘Strict.StateT’
* ‘ReaderT’
* ‘Lazy.WriterT’
* ‘Strict.WriterT’
* ‘IndentityT’
2015-09-20 15:21:35 +06:00
mrkkrp
d8515202fe eliminate obsolete ‘GenParser’ type synonym 2015-09-19 21:13:53 +06:00
mrkkrp
1a7981ba34 move ‘(<?>)’ outside of ‘MonadParsec’ type class 2015-09-19 21:02:37 +06:00
mrkkrp
303e739584 remove redundant and somewhat obsolete text 2015-09-18 21:53:09 +06:00
mrkkrp
fce6c3187c eliminated user state and written ‘MonadParsec’
Close # 27.

Backtracking user state can be achieved via combination of ‘StateT’
monad transformer and ‘ParsecT’:

  StateT StateType (ParsecT s m a)

This user state can be more flexible. This fact renders current built-in
user state redundant.

To help work with this new approach (combining monad transformers more
freely) we introduce ‘MonadParsec’ MTL-style type class. All tools that
come with Megaparsec library were modified to work smoothly with any
instance of ‘MonadParsec’, not only ‘ParsecT’.
2015-09-18 15:33:44 +06:00
mrkkrp
02ebc7ee23 make combinators more general
Now all the combinators in ‘Text.Megaparsec.Combinator’ are defined for
any instance of ‘Control.Alternative’ (sometimes ‘Control.Applicative’).

Some combinators are inlined.
2015-09-18 15:31:32 +06:00
mrkkrp
4c1858f900 fix a typo: it's called ‘token’ now 2015-09-14 22:44:34 +06:00
mrkkrp
2fc5455591 make ‘Text.Megaparsec.Prim.token’ more flexible
Closes #29.

Now testing function can return ‘Either [Message] a’ so it can construct
full list of error messages. This may be useful in some cases when
tokens are more complex than simple characters.
2015-09-14 14:15:31 +06:00
mrkkrp
0d39e44f40 Merge branch 'new-lexer' 2015-09-13 21:16:39 +06:00
mrkkrp
ec3b5934f0 fix a typo (columns starts from 1) 2015-09-13 21:00:22 +06:00
mrkkrp
193d7ade07 fixed ‘skipLineComment’ and ‘skipBlockComment’
Multi-character staring/ending sequences should be wrapped with
‘try’. Also, ‘lookAhead’ should not be used in ‘skipBlockComment’.
2015-09-13 18:51:15 +06:00
mrkkrp
4e8a1c298a fixed the failing old test
Multi-character operators should use ‘try’ in order to be reported
correctly (as “operator”). I've mentioned it in doc-string of
‘makeExprParser’.

It's tempting to include ‘try’ directly in expression parsing code, but
following general spirit of Parsec toward ‘try’, I think current
solution is the best.
2015-09-11 15:10:14 +06:00
mrkkrp
3de3f6965d make ‘hexadecimal’ and ‘octal’ more powerful
Various languages may vary in how hexadecimal and octal literals should
be prefixed. Following the spirit of the new lexer we leave this to
programmer to decide.
2015-09-09 14:15:39 +06:00
mrkkrp
c6f06b2ed1 fix a typo 2015-09-08 20:27:49 +06:00
mrkkrp
7298c01387 first version of the new lexer module 2015-09-08 17:34:02 +06:00
mrkkrp
f58d5bfe1c further refinement 2015-09-06 15:23:12 +06:00
mrkkrp
b6a43c3335 started work on new lexer
Eliminated ‘Text.Megaparsec.Language’ module because at this point it is
clear that already existing definitions are of little use in
Megaparsec. I started writing “default” language definition in
‘Text.Megaparsec.Lexer’.

At this point it should be possible to parse languages where indentation
matters, although we will need to provide more helpers to make it
easier.
2015-09-06 15:23:12 +06:00
mrkkrp
d8d810e78e add sections to ‘Text.Megaparsec.Char’ module 2015-09-06 15:22:37 +06:00
mrkkrp
7516ec4f23 added more case-insensitive character parsers
The following parsers are introduced:

* ‘char'’
* ‘oneOf'’
* ‘noneOf'’
2015-09-06 15:17:37 +06:00
mrkkrp
6ac08b0956 added new parser ‘string'’
This is like ‘string’, but is case-insensitive.
2015-09-04 18:12:59 +06:00
mrkkrp
2ca6316f33 renamed ‘Text.Megaparsec.Token’ module
Now it's called ‘Text.Megaparsec.Lexer’. This commit contains other
cosmetic changes as well.
2015-08-30 16:00:07 +06:00
mrkkrp
0b3efb649b refactoring of ‘Text.Megaparsec.Expr’ 2015-08-29 16:54:15 +06:00
mrkkrp
eb14e7d327 improve functioning of ‘hidden’ combinator
When ‘p’ in ‘hidden p’ fails we should discard all expected messages and
don't add any new messages.
2015-08-29 16:01:36 +06:00
mrkkrp
89f34688ab don't create hints for errors without messages 2015-08-26 17:26:06 +06:00
mrkkrp
cb3078d07c don't put older hints before newer ones, fixes #25
Obviously order does matter here, since ‘Monoid’ instance for ‘Hints’ is
derived from [], so (<>) is the same as (++) and we should be careful
to keep things in the right order.
2015-08-26 15:53:37 +06:00
mrkkrp
c31f0769fd rewrite ‘choice’ as synonym of ‘asum’ 2015-08-26 06:37:41 +06:00
mrkkrp
2390f9f753 swap ‘count’ and ‘count'’ 2015-08-25 15:55:57 +06:00
mrkkrp
23b083cea6 deprecate some parsers, close #24
These parsers are considered deprecated:

* ‘chainl’
* ‘chainl1’
* ‘chainr’
* ‘chainr1’
* ‘sepEndBy’
* ‘sepEndBy1’

Apart from this, the commit includes various cosmetic changes in
module ‘Text.Megaparsec.Combinator’.
2015-08-25 02:04:10 +06:00
mrkkrp
40d92a19a0 rewritten ‘showMessages’ in clearer manner 2015-08-24 22:19:19 +06:00
mrkkrp
d431b396f4 improve indentation for readability 2015-08-24 16:38:00 +06:00
mrkkrp
a8577275c7 treat carriage return like ordinary character 2015-08-24 14:00:56 +06:00
mrkkrp
45f449ddb2 prefer longest match in ‘mergeError’, fixes #23
Since ‘mergeError’ is only used to merge errors from alternative
branches of parsing, longest match should be preferred.
2015-08-24 01:45:12 +06:00
mrkkrp
b81962e44a added combinator ‘someTill’ 2015-08-23 23:12:45 +06:00
mrkkrp
d6947a901f various cosmetic changes (including renaming)
The following functions and data types have been renamed:

* ‘permute’ → ‘makePermParser’
* ‘buildExpressionParser’ → ‘makeExprParser’
* ‘GenLanguageDef’ → ‘LanguageDef’
* ‘GenTokenParser’ → ‘Lexer’
* ‘makeTokenParser’ → ‘makeLexer’
2015-08-23 21:07:03 +06:00
mrkkrp
7dd2ad94ff minor corrections 2015-08-22 15:02:34 +06:00
mrkkrp
6e5735167f flip argument order for ‘label’, close #21 2015-08-22 14:57:16 +06:00