I'm trying to make a parser using Alex with Happy. I'm following the instructions from this post, but having trouble. I'm trying to track down the source of the following type error:
templates/wrappers.hs:234:9:
Couldn't match type ‘Token’ with ‘Int -> Alex Token’
Expected type: AlexInput -> Int -> Alex Token
Actual type: String -> Token
In a stmt of a 'do' block: action (ignorePendingBytes inp) len
In the expression:
do { alexSetInput inp';
action (ignorePendingBytes inp) len }
In a case alternative:
AlexToken inp' len action
-> do { alexSetInput inp';
action (ignorePendingBytes inp) len }
My lexer is in src/AnsiParser/FrontEnd/Lex.x. So I took a look in dist/build/AnsiParser/FrontEnd/Lex.hs, and all I can find is:
{-# LINE 1 "templates/wrappers.hs" #-}
{-# LINE 1 "templates/wrappers.hs" #-}
But I can't find any files named "wrapper.hs" on my system. How can I track down the cause of this error?
In case it's useful, here's a reduced version of my Parse.y:
{
module AnsiParser.FrontEnd.Parse where
import AnsiParser.FrontEnd.Lex
}
%name parseTokens
%tokentype { Token }
%lexer { lexWrap } { alexEOF }
%monad { Alex }
%error { parseError }
%token
-- tokens
%%
-- rules
{
parseError :: Token -> Alex a
parseError tokens = error ("Error!" ++ show tokens)
}
And Lex.x:
{
module AnsiParser.FrontEnd.Lex where
}
%wrapper "monad"
tokens :-
-- tokens
{
data Token
= -- token types
| TokenEOF
deriving (Show)
scanTokens = alexMonadScan
lexWrap :: (Token -> Alex a) -> Alex a
lexWrap = (alexMonadScan >>=)
alexEOF :: Alex Token
alexEOF = return TokenEOF
}
You can find the source for template/wrappers.hs
in the alex repo:
https://github.com/simonmar/alex/tree/master/templates
Running alex on your provided Lex.x
gave me this error:
alex: (Array.!): undefined array element
If you give me a working example I can track down your problem.