Skip to content

parsing failure context label #96

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

Merged
merged 2 commits into from
Oct 1, 2020

Conversation

jamesdbrock
Copy link
Member

What does this pull request do?

Resolves #95

Also, in a separate commit, add a link in the README to purescript-parsing-dataview, as offered by @garyb #88 (comment)

Where should the reviewer start?

There is one function added, and one test.

How should this be manually tested?

pulp --psc-package test

-- | If parsing fails inside this labelled context, then prepend the `String`
-- | to the error `String` in the `ParseError`.
label :: forall m s a. Monad m => String -> ParserT s m a -> ParserT s m a
label messagePrefix p = catchError p $ \ (ParseError message pos) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there value in appending with a space by default, or should that be left to the user?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good question. I say leave it to the user, who might reasonably choose to append " " or "\n" or something else.

@jamesdbrock
Copy link
Member Author

This is actually more like a Megaparsec region than a label. Maybe the name of the function should be different.

@thomashoneyman
Copy link
Contributor

I don't have an opinion on which of those names is used for the function, but another maintainer may. If you think that region is more informative, then I am OK with that.

@jamesdbrock
Copy link
Member Author

Oh now I remember why I thought the name label would be good, because this is the same function as
label from the Data.Binary.Get parsing monad.

@thomashoneyman
Copy link
Contributor

I'm going to go ahead and merge this, but if you would like to revisit the name prior to the next release of the library then please feel free to open an issue / PR. Thanks!

@thomashoneyman thomashoneyman merged commit fc6cd08 into purescript-contrib:master Oct 1, 2020
@jamesdbrock
Copy link
Member Author

Cool I think it's good the way it is, thank you @thomashoneyman

@jamesdbrock
Copy link
Member Author

I just realized that this should be

label :: forall m s a. Monad m => (ParseError -> ParseError) -> ParserT s m a -> ParserT s m a

So that the user can do whatever they want to the ParseError, not just prepending a String.

Also probably better for performance, since the String argument will get strictly evaluated, but this (ParseError -> ParseError) funciton would only be called on failure.

@thomashoneyman
Copy link
Contributor

I haven’t released anything yet — I’m on board, want to make this update?

@jamesdbrock
Copy link
Member Author

Oh hi! Ok, I'll make the update.

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

Successfully merging this pull request may close these issues.

parsing failure context label
2 participants