Haskell Alex - erro no modelo de wrapper
Eu estou tentando entender Alex e lexers em geral, mas estou tendo problemas para executar meu lexer.
Eu escrevi lexers em wrappers "básicos" e "posn", mas não consegui usar o wrapper "monad". Acho que tenho que usarmonad
invólucro porque eu preciso coletar seqüências de caracteres e posições de token na entrada. Eu também preciso de vários estados. Por enquanto estou tentando executar este simples exemplo:
<code>{ module Main (main) where } %wrapper "monad" $whitespace = [\ \b\t\n\f\v\r] $digit = 0-9 $alpha = [a-zA-Z_] $upper = [A-Z] $lower = [a-z] @tidentifier = $upper($alpha|_|$digit)* @identifier = $lower($alpha|_|$digit)* tokens :- $whitespace+ ; $upper $alpha+ { typeId } $lower $alpha+ { id_ } $digit+ { int } { data Lexeme = L AlexPosn LexemeClass String data LexemeClass = TypeId String | Id String | Int Int | EOF deriving (Show, Eq) typeId :: AlexInput -> Int -> Alex Lexeme typeId = undefined id_ :: AlexInput -> Int -> Alex Lexeme id_ = undefined int :: AlexInput -> Int -> Alex Lexeme int = undefined alexEOF = return (L undefined EOF "") main :: IO () main = do s <- getContents let r = runAlex s $ do return alexMonadScan print r } </code>
Minhas ações sãoundefined
para agora. Quando tento compilá-lo, estou recebendo este erro:
<code>➜ haskell ghc --make Tokens.hs [1 of 1] Compiling Main ( Tokens.hs, Tokens.o ) templates/wrappers.hs:208:17: Couldn't match expected type `(AlexPosn, Char, [Byte], String)' with actual type `(t0, t1, t2)' Expected type: AlexInput Actual type: (t0, t1, t2) In the return type of a call of `ignorePendingBytes' In the first argument of `action', namely `(ignorePendingBytes inp)' </code>
Eu também estou recebendo vários erros quando tento compilar exemplos no repositório github de Alex, poderia estar relacionado com uma incompatibilidade de versão? Eu instalei o alex do cabal com o ghc 7.0.4. Alguma ideia?