Add error messages for incomplete parsing#3
Open
Ivan-Yudin wants to merge 1 commit intoHappstack:masterfrom
Open
Add error messages for incomplete parsing#3Ivan-Yudin wants to merge 1 commit intoHappstack:masterfrom
Ivan-Yudin wants to merge 1 commit intoHappstack:masterfrom
Conversation
As result of applying
> runParser . prs
to a boomerang
> b :: Boomerang e tok a b
and initial position
> initalPosition (Nothing :: Maybe e)
one gets a list consisting of three type of elements:
- those that resulted from errors encoded in primitive parsers of the form
> Left e
where e contains error message and position where the error occur;
- those that produce complete successful parsing of the form
> Right ((f,tok), pos)
where tok is empty in an appropriate sense;
- and those where the parsing stopped before the full input whose exhausted of
the form
> Right ((f,tok), pos)
with non-empty tok and pos been the first place starting from which no parsing
was made.
In the previous version the elements of last type were silently thrown away,
which created incomplete error messages. For example
> parseString Text.Boomerang.String.alpha "a("
was given the message
This patch fixes the above issue by explicitly handling the results of parsing
of the third kind in the function
> parse1
This led to the following change of API:
- the result of the function "parse" now includes an extra field that contains
the position of the first non-parsed element;
- the class ErrorPosition got an extra method "setPosition" that permits to add
position to the messages generated in "parse1" for incomplete parses;
- the instance of "ErrorPosition (ParserError p)" is changed according to the
new interface of the class ErrorPosition.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
I have tried to improve the error messages produced
by parsers in the case of error-less incomplete parsings.
(The example is in the git commit message as well as
comments on changes done.)
The patch makes the definition of the function "parse1"
more explicit (it doesn't use the functions "bestError"
and "maximumBy" now) , but in this way one avoids
to go through the list of possible parsings several times.
There is a type change in the function "parse" exported by
the module Prim.hs, since we need to know the position
where the parsing stopped when emitting a message in
the function "parse1". This can be avoided by introducing
a new function "parse' " or putting the corresponding code
inside of the definition of "parse1" . I am not sure what is
better as of now the function "parse" is not used in other
parts of the Boomerang library, and it is unclear to me if
anybody imports it. (In most cases only the specific parsers
like parseString, parseStrings, parseTexts would be used.)
Best,
Ivan
PS. I have run the travis build on my master branch and it
was successful.