Consider the following, working, Alex source file:
{
module Main (main) where
}
%wrapper "basic"
tokens :-
$white ;
. { rule "!"}
{
type Token = String
rule tok = \s -> tok
main = do
s <- getContents
mapM_ print (alexScanTokens s)
}
I would love to put my helper code closer to the top of the file, before all the rules. I tried doing this:
{
module Main (main) where
}
%wrapper "basic"
{
type Token = String
rule tok = \s -> tok
}
tokens :-
$white ;
. { rule "!"}
{
main = do
s <- getContents
mapM_ print (alexScanTokens s)
}
but got the following error:
test.x:11:2: parse error
(line 11 is the closing curly brace after my helper code)
Is there a way to move my helper code closer to the top of the file?
I also tried putting the helper code in the first block, together with "module Main" declaration but that didn't work because the "%wrapper" bit generates some import statements that need to appear right as the first thing in the generated file.