Commit Graph

57 Commits

Author SHA1 Message Date
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
mrkkrp
20984c20f2 cosmetic changes in ‘Text.Megaparsec.Prim’
Also eliminated dead segment of code in ‘token'’.
2015-08-22 01:12:26 +06:00
mrkkrp
d0cdb85e89 don't use ‘try’ in ‘manyTill’ unconditionally 2015-08-21 20:29:06 +06:00
mrkkrp
2fa2805aea derive ‘Eq’ instance for ‘Message’ and ‘ParseError’ 2015-08-21 14:02:29 +06:00
mrkkrp
f9cfe390af various minor changes, renamed functions
Among other changes two functions have been renamed:

* ‘parseMaybe’ → ‘parse'’ (also added to change log)
* ‘putState’ → ‘setState’ (for consistency)
2015-08-20 16:37:52 +06:00
mrkkrp
3661da90e5 temporarily simplify token parsing
The improved error messages in Megaparsec are quite sensitive to how
parsers are written, which parts of parser are labeled, etc. Current
implementation of token parsers in ‘Text.Megaparsec.Token’ is written
without this in mind. We will improve the module later, for now let us
rewrite/simplify some parts to avoid failing tests.
2015-08-20 01:38:00 +06:00
mrkkrp
110859b9c2 added new primitive combinator ‘hidden’
Added new primitive combinator ‘hidden p’ which hides “expected” tokens
in error message when parser ‘p’ fails.
2015-08-20 01:38:00 +06:00
mrkkrp
fc5abbc7fc ‘lookAhead p’ should discard hints produced by ‘p’ 2015-08-20 01:38:00 +06:00
mrkkrp
d45c2c0658 accumulate hints when previous parser consumes
If ‘x’ in ‘x >>= y’ consumes input but produces some hints, we should
accumulate them nonetheless. Why it's important can be demonstrated by
the following test:

  many (char 'a') >> many (char 'b') >> eof

This should fail on input "ac" with the following message:

  parse error at line 1, column 2:
  unexpected 'c'
  expecting 'a', 'b' or end of input

As you can see even though parser ‘many (char 'a')’ consumed input, its
hits may be useful later.
2015-08-20 01:38:00 +06:00
mrkkrp
987381eaa7 derive ‘Monoid’ instance for ‘Hints’ 2015-08-20 01:37:58 +06:00
mrkkrp
455bfa3076 major improvements of ‘Text.Megaparsec.Prim’
* Removed ‘optionMaybe’ parser, because ‘optional’ from
  ‘Control.Applicative’ does the same thing.

* Renamed ‘tokenPrim’ → ‘token’, removed old ‘token’, because
  ‘tokenPrim’ is more general and ‘token’ is little used.

* Fixed bug with ‘notFollowedBy’ always succeeded with parsers that
  don't consume input, see #6.

* Hint system introduced that greatly improved quality of error messages
  and made code of ‘Text.Megaparsec.Prim’ a lot clearer.

The improvements affected other modules too:

* Some parsers from ‘Text.Megaparsec.Combinators’ now live in
  ‘Text.Megaparsec.Prim’.

* Hint system improved error messages, so I needed to rewrite test for
  ‘Text.Megaparsec.Char.eol’, since it's error messages are very
  intelligent now and cannot be emulated by ‘newline’ and ‘crlf’ parsers
  used separately.

* Test for Bug9 from old-tests is passed successfully again.
2015-08-17 21:58:59 +06:00
mrkkrp
65fbedee1c added more powerful ‘count’ parser, close #17
This parser can be told to parse from ‘m’ to ‘n’ occurrences of some
thing. Old parser ‘count’ is now named ‘count’' and defined in terms of
that more powerful one.

This commit also reorders functions in module
‘Text.Megaparsec.Combinator’ and everywhere where the functions are
listed. The same order is used everywhere.
2015-08-13 01:02:33 +06:00
mrkkrp
287a777e6c cosmetic changes (indentation, etc) 2015-08-13 00:02:49 +06:00
mrkkrp
77a54394b5 extend collection of character parsers, close #16
Added new character parsers in ‘Text.Megaparsec.Char’:

* ‘controlChar’
* ‘printChar’
* ‘markChar’
* ‘numberChar’
* ‘punctuationChar’
* ‘symbolChar’
* ‘separatorChar’
* ‘asciiChar’
* ‘latin1Char’
* ‘charCategory’

Renamed some parsers:

‘spaces’   → ‘space’
‘space’    → ‘spaceChar’
‘lower’    → ‘lowerChar’
‘upper’    → ‘upperChar’
‘letter’   → ‘letterChar’
‘alphaNum’ → ‘alphaNumChar’
‘digit’    → ‘digitChar’
‘octDigit’ → ‘octDigitChar’
‘hexDigit’ → ‘hexDigitChar’

Descriptions of old parsers have been updated to accent some
Unicode-specific moments. For example, old description of ‘letter’
stated that it parses letters from “a” to “z” and from “A” to “Z”. This
is wrong, since it used ‘Data.Char.isAlpha’ predicate internally and
thus parsed many more characters.
2015-08-12 23:00:03 +06:00
mrkkrp
bd04b4328c various minor changes 2015-08-12 18:41:22 +06:00
mrkkrp
c13ca493ae experimental branch with different Messages 2015-08-11 18:15:02 +06:00
mrkkrp
176fe8d9c1 improve quality of error messages, fixed #13 2015-08-11 03:21:52 +06:00
mrkkrp
bb074cc52b fixed a regression in ‘Text.Megaparsec.Error’
I've improved tests so this sort of bug won't appear in future.
2015-08-11 03:19:16 +06:00
mrkkrp
dedbe7a897 fix regression in ‘setErrorMessage’, add tests
New tests shows that I had wrong assumption about workings of this
particular function. This is not a problem, though, complete test-suite
will eliminate this sort of nuisance soon.
2015-08-09 00:38:30 +06:00
mrkkrp
c4350dca37 further cosmetic changes in ‘Text.Megaparsec.Char’ 2015-08-09 00:37:51 +06:00
mrkkrp
fcf1b972e8 a minor correction in doc-string of ‘setErrorMessage’ 2015-08-08 15:53:55 +06:00
mrkkrp
ebc1fae39c cosmetic changes in ‘Text.Megaparsec.Char’ 2015-08-08 15:50:50 +06:00