Sto cercando di capire Alex e lexers in generale, ma ho problemi a eseguire il mio lexer.Haskell Alex - errore nel modello di wrapper
Ho scritto i lexer nei wrapper "basic" e "posn", ma non ho potuto nel wrapper "monad". Penso di dover usare il wrapper monad
perché ho bisogno di raccogliere le stringhe e le posizioni dei token in input. Ho anche bisogno di più stati. Per ora sto cercando di eseguire questo semplice exmaple:
{
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
}
mie azioni sono undefined
per ora. Quando provo a compilarlo, sto ottenendo questo errore:
➜ 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)'
Sto anche ricevendo vari errori quando provo a compilare esempi nella repo github di Alex, potrebbe essere correlato con una versione non corrispondente? Ho installato alex da cabal con ghc 7.0.4. Qualche idea?
Grazie! Devo aprire un problema nel suo repository GitHub? – sinan
@sinan: Sì, sarebbe probabilmente una buona idea. – hammar