haskell / alex

A lexical analyser generator for Haskell
https://hackage.haskell.org/package/alex
BSD 3-Clause "New" or "Revised" License
297 stars 82 forks source link

Report multiple errors in Alex monad #144

Open gustavoaca1997 opened 5 years ago

gustavoaca1997 commented 5 years ago

Alexis defined as

newtype Alex a = Alex { unAlex :: AlexState
-> Either String (AlexState, a) }

where any error is stored in the Left as String. It would be great if the programmer could define its own "error state" or maybe if Alex could already report more than one lexical error. I had to define my AlexUserState as

data AlexUserState = AlexUserState {
    matches :: Either [Error] [Token]
}

for storing all lexical errors that have occurred and then show them to the user.