haskell / haskell/alex

Is there a way to modify the default lexical error message from within an .x file.

Open
#276 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
323
Forks
87
PR merge metrics
No merged PRs in 30d

Description

The lexical error message comes from this function in the generated .hs file:

```
#ifdef ALEX_MONAD_BYTESTRING
alexMonadScan = do
inp__@(_,_,_,n) <- alexGetInput
sc <- alexGetStartCode
case alexScan inp__ sc of
AlexEOF -> alexEOF
AlexError ((AlexPn _ line column),_,_,_) -> alexError $ "lexical error at line " ++ (show line) ++ ", column " ++ (show column)
AlexSkip inp__' _len -> do
alexSetInput inp__'
alexMonadScan
AlexToken inp__'@(_,_,_,n') _ action -> let len = n'-n in do
alexSetInput inp__'
action (ignorePendingBytes inp__) len
#endif
```

I can alter the line `alexError $ "lexical error at line " ++ (show line) ++ ", column " ++ (show column)` to get what I want but, this is going to require manual changes every time I regenerate the lexer. Is there some simple workaround or can this be added as a feature?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.