Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting line / column numbers from a failed parse #54

Open
statusfailed opened this issue Jan 27, 2016 · 3 comments
Open

Extracting line / column numbers from a failed parse #54

statusfailed opened this issue Jan 27, 2016 · 3 comments

Comments

@statusfailed
Copy link
Collaborator

Is it possible to get the position of an error from a failed parse? I see that "Result" is either

Success a    
Failure Doc

But it doesn't seem like I'd be able to extract the line number from the Doc
The docs for Err also indicate that position isn't included, but not the reason why.

Is there a way to get this information?

@statusfailed
Copy link
Collaborator Author

So I've got the workings of a patch for this: https://github.com/statusfailed/trifecta/tree/failed-parse-locations

It works OK (although I'm not sure if there are any bugs - I basically just changed some types and fixed errors until it compiled). here's an example of what output you get:

GHCi> parseString (liftM2 (,) stringLiteral natural) mempty "\"Hi there\"\n\nBADPARSE" :: Result (String, Integer)
Failure (ErrInfo {_errDoc = (interactive):3:1: error: expected: natural
BADPARSE<EOF> 
^             , _errDeltas = [Lines 2 0 12 0]})

Unfortunately I've had to change the "Result" type, which breaks backwards compatibility. I'm not sure what the minimally-breaking way to write this would be - maybe add some IntermediateResult type which can be used to build a Result by the existing functions (parseString, parseByteString, etc.).
Then I could add more (different) parse functions, like "parseStringWithLocations".

@ekmett any thoughts?

@ekmett
Copy link
Owner

ekmett commented Jan 28, 2016

We need to change the Result and error types a bit anyways to support a race combinator, so I expect a non-backwards compatible release eventually anyways. =)

Put that into a pull request, and I can merge it, forcing me to remember to deal with this when I fix race.

@statusfailed
Copy link
Collaborator Author

Will do, but it's pretty messy! Let me know if you've any preferences for tidying before merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants