alex
alex copied to clipboard
Allow custom error types in monad wrappers
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)
- Is there an easier way to do this?
- Am I missing some problems with this approach?
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!
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?
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
.
@Boarders : Still up to a PR?
@andreasabel I'll start having a look in the next couple of weeks!
Sorry I had intended to work on this but was blocked by #195