Quoting from the documentation of Alex:
"The overall layout of an Alex file is:
alex := [ @code ] [ wrapper ] { macrodef } @id ':-' { rule } [ @code ]
At the top of the file, the code fragment is normally used to declare the module name and some imports, and that is all it should do: don't declare any functions or types in the top code fragment, because Alex may need to inject some imports of its own into the generated lexer code, and it does this by adding them directly after this code fragment in the output file."
So, what you are trying to do violates the syntax. It seems that the sole place you can put the definition of the Token
datatype is at the final code block.
However, it is possible to have this code in a separate module, if you like, and import
it at the top code block.