Commit Graph

113 Commits

Author SHA1 Message Date
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
mrkkrp
80e93b90a6 fixing things in ‘Text.Megaparsec.Error’ 2015-08-08 15:48:20 +06:00
mrkkrp
3daa70f15a representation of tokens in error messages, fixed #12
* Type class ‘ShowToken’ introduced to pretty-print tokens.

* For now, we have defined instances for ‘String’ and ‘Char’.
2015-08-06 16:37:08 +06:00
mrkkrp
0608926db2 extends description of ‘Text.Megaparsec’ module 2015-08-04 00:15:16 +06:00
mrkkrp
cbbf27ddd0 export only useful (for user) functions
User still can import ‘Text.Megaparsec.Prim’ to access the stuff, but
it's very unlikely that this sort of things is used often.
2015-08-04 00:02:23 +06:00
mrkkrp
02e5f148e9 updated doc for ‘Text.Megaparsec.Prim.runParsecT’ 2015-08-04 00:01:38 +06:00
mrkkrp
be36490aa2 corrections for ‘Text.Megaparsec.Error’ 2015-08-03 23:44:40 +06:00
mrkkrp
79a378c9c4 remove parenthesis around “line & column” block 2015-08-03 20:45:09 +06:00
mrkkrp
437608c2c7 minor corrections in module ‘Text.Megaparsec.Pos’ 2015-08-03 13:20:15 +06:00
mrkkrp
3ef5e5e621 renamed ‘MegaParsec’ → ‘Megaparsec’, close #10 2015-08-01 22:24:45 +06:00
mrkkrp
3c69bc8f48 re-export ‘(<|>)’, ‘many’, ‘some’, and ‘optional’, fixes #9
These functions are now re-exported from ‘Control.Applicative’
module. ‘many’ and ‘some’ are now part of ‘Alternative’ instance of
‘ParsecT’.

Note that these functions are re-exported only in ‘Text.MegaParsec’
module, but not in ‘Text.MegaParsec.Prim’ to avoid duplication of
floating doc-strings. Others internal modules now just casually import
‘Control.Applicative’ for their needs.

Note that ‘many1’ was renamed to ‘some’, the same is done for other
parsers that had ‘many1’ part in their names (for consistency).
2015-08-01 20:49:45 +06:00
Albert Netymk
189106f001 Remove try in float parser.
According to this post
(http://blog.ezyang.com/2014/05/parsec-try-a-or-b-considered-harmful/),
the error message could be confusing if using `try`. `"3.a"` is one case
to expose this behavior.
2015-07-31 23:45:42 +02:00
mrkkrp
1ce541aaba remove word ‘unsigned’ from descriptions 2015-08-01 01:31:31 +06:00
mrkkrp
7c0341af72 the grammars overlap so there should be a ‘try’ 2015-07-31 20:31:38 +06:00
mrkkrp
c5bcdfb220 rewritten parsing of numbers, fixes #2 and #3
Changed how numbers are parsed because they were parsed in a naïf and
hairy way. Added tests for #2 and #3 (in old Parsec project these are
number 35 and 39 respectively).

* Since Haskell report doesn't say anything about sign, I've made
  ‘integer’ and ‘float’ parse numbers without sign.

* Removed ‘natural’ parser, it's equal to new ‘integer’ now.

* Renamed ‘naturalOrFloat’ → ‘number’ — this doesn't parse sign too.

* Added new combinator ‘signed’ to parse all sorts of signed numbers.

* For the sake of convenience I've added ‘integer'’, ‘float'’, and
 ‘number'’ combinators that also can parse signed numbers out of box.
2015-07-31 17:30:38 +06:00
mrkkrp
b19dae4315 improve efficiency of applicative interface 2015-07-31 01:50:36 +06:00
mrkkrp
b936e3c3a9 improved documentation, fixes #1 2015-07-31 00:36:54 +06:00
mrkkrp
773e9ccabe cosmetic changes in copyright (headers) 2015-07-30 22:20:37 +06:00
mrkkrp
e6f2379b22 refactoring, phase 3 2015-07-30 21:45:06 +06:00
mrkkrp
137ce0a521 refactoring, phase 2 2015-07-29 14:44:58 +06:00
mrkkrp
227667f829 refactoring, phase 1 2015-07-28 19:32:19 +06:00
Ben Pence
dd14602877 Fixes minor documentation inconsistency 2015-05-17 11:18:05 -07:00
Simon Vandel Sillesen
4aeaede85d Fix documentation for emptyDef not rendering 2015-04-15 19:01:53 +02:00
Antoine Latter
19a62ae80a Remove split-base conditional compilation option. 2015-03-21 20:40:02 -05:00
Antoine Latter
03242e474c Export 'runP' from Text.Parsec
Fixes #27.
2015-03-19 10:30:21 -04:00
Joel Williamson
6382eeec38 Fixed type of argument to char in examples
The examples for identStart and identLetter were calling `char "_"`. char should take a character literal, not a string.
2015-03-07 13:16:49 -05:00
Tal Walter
2b74642d7d Fixed a mistake (Applicative to Alternative) in the parserZero comments 2015-01-24 09:07:01 +02:00
cdepillabout
640cbdd306 Fixing spelling mistake in doc for chain function
Fix a small spelling mistake in the haskell doc for chainr1, chainl1, chainr, and chainl.
2015-01-11 01:32:00 +09:00
Antoine Latter
37d34b23eb Merge branch 'master' into 3.1.7_maint
Conflicts:
	parsec.cabal
2015-01-09 20:44:02 -06:00
Antoine Latter
355d8f2fc6 Fix module exports for Stream, Consumed, Reply, and State. 2015-01-09 20:33:05 -06:00
Daniel Gorin
3fb40aaa68 Add an Eq instance for ParseError 2014-11-03 16:30:21 +00:00
Slava Shklyaev
22ee53e06d Fix a typo 2014-10-29 19:36:12 +02:00
Emil Skoeldberg
ed944b4a96 Spelling fix. ('seperate' -> 'separate'). 2014-10-29 11:21:46 +00:00
Marios Titas
f7faa2a1af lookAhead: reset error messages on success 2014-09-24 20:33:15 -05:00
Antoine Latter
f4601acddf Revert "Track current position in the 'tokens' function"
This reverts commit 860764939c.

This fixes #9.
2014-09-24 19:43:08 -05:00
Antoine Latter
fd8ecf5d03 Fix off-by-one error in Token charControl.
Fixes #2.
2014-09-09 20:17:49 -05:00
Daniel Díaz
d98a576f5a Renamed 'anyNewline' to 'endOfLine' as suggested in #3 by @aslatter. 2014-05-19 13:48:37 +02:00