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

Allow custom error types in monad wrappers #178

Open
anka-213 opened this issue Feb 26, 2021 · 7 comments
Open

Allow custom error types in monad wrappers #178

anka-213 opened this issue Feb 26, 2021 · 7 comments
Labels
feature request wrapper Concerning wrapper code

Comments

@anka-213
Copy link

I want to extract the position information on lexing errors so I can send them to an LSP client, but the error type for the wrappers is hard coded to be string, so it is difficult to send along that extra information.
As far as I can tell, the change would mostly consist of replacing Either String a with Either err a, adding a corresponding type parameter to Alex a and adjusting the line

  AlexError ((AlexPn _ line column),_,_,_) -> alexError $ "lexical error at line " ++ (show line) ++ ", column " ++ (show column)
  1. Is there an easier way to do this?
  2. Am I missing some problems with this approach?
@Ericson2314
Copy link
Collaborator

Yeah this looks good to me, and something I'd want too. I thought some of the wrappers might affect the error type, but no they don't, only AlexInput not `Alex.

If you make a PR for this I'd be happy to merge it!

@Boarders
Copy link

I'm happy to make a PR for this but I'd be curious what we do with the line in question:

AlexError ((AlexPn _ line column),_,_,_) -> alexError $ "lexical error at line " ++ (show line) ++ ", column " ++ (show column)

Any ideas on what would be best here?

@solomon-b
Copy link

solomon-b commented Nov 2, 2021

I'm happy to make a PR for this but I'd be curious what we do with the line in question:

AlexError ((AlexPn _ line column),_,_,_) -> alexError $ "lexical error at line " ++ (show line) ++ ", column " ++ (show column)

Any ideas on what would be best here?

What if we did something like Megaparsec where there is a concrete error type plus an additional optional error type:

data LexError e = LexError AlexPosn String | CustomError e
runAlex :: String -> Alex a -> Either (LexError e) a

Then if you don't want a custom error you can do LexError Void.

@andreasabel andreasabel added feature request wrapper Concerning wrapper code labels Jan 25, 2022
@andreasabel
Copy link
Member

@Boarders : Still up to a PR?

@Boarders
Copy link

@andreasabel I'll start having a look in the next couple of weeks!

@solomon-b
Copy link

Sorry I had intended to work on this but was blocked by #195

@swingbit
Copy link

Just to know, is this abandoned?

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

No branches or pull requests

6 participants