Commit Graph

194 Commits

Author SHA1 Message Date
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
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