I have tried multiple example grammars and get the same error when I try to compile the generated files.
For example I have followed exactly the solution to this question - GLR_Lib.hs: Could not find module 'System'
where the grammar file is
%tokentype { ABC }
%error { parseError }
%token
a { A }
b { B }
c { C }
%%
s1 : a a a b {} | b s2 a {}
s2 : b a b s2 {} | c {}
{
data ABC = A | B | C deriving (Eq,Ord,Show)
parseError _ = error "bad"
}
But when I compile I get:
[1 of 2] Compiling ABCData ( ABCData.hs, ABCData.o )
[2 of 2] Compiling ABC ( ABC.hs, ANC.o )
GLR_Lib.hs:164:2: parse error on input ‘case’
This exact error has happened with every grammar that I have tried. I don't know what I could be doing differently to people that have the examples working successfully.
There are indentation errors in the
GLR_Lib
template. This is what I did to get it to work:ABCMain.hs
file../templates
for the edited templates.locate GLR_Lib
. On OSX with the Haskell Platform I found them in /Library/Haskell/current/share/happy-1.19.4/./templates
./templates/GLR_Lib
:import System
case new_stks of
stks' <- foldM (pack i) stks reds
happy --glr --template=./templates ABC.y
ghc --make ABCMain
You will probably only need the
GLR_Lib
andGLR_Base
templates.