The easiest solution is to make sure that the input always ends in \n
by simply appending one at the end of the input.
Alternatively, you can get the behavior you want by using a predicate instead of $
.
^@ident\:/{ eolOrEof } { ... }
A predicate can examine the input stream surrounding the token and decide if it should match or not. In this case, we simply have to examine the stream after the token to check for \n
or EOF.
The exact definition will depend on which wrapper you're using (the definition of the type AlexInput
varies between wrappers), but here's one I got to work using the "basic"
wrapper.
eolOrEof :: user -> AlexInput -> Int -> AlexInput -> Bool
eolOrEof _ _ _ (_, after) =
case after of
[] -> True -- end-of-file
('\n':_) -> True -- end-of-line
_ -> False