Haskell Alex - błąd w szablonie opakowania
Próbuję zrozumieć Alexa i lektyków w ogólności, ale mam kłopoty z uruchomieniem mojego leksyka.
Napisałem leksery w opakowaniach „podstawowych” i „posn”, ale nie mogłem w opakowaniu „monad”. Myślę, że muszę użyćmonad
wrapper, ponieważ muszę zbierać łańcuchy i pozycje żetonów na wejściu. Potrzebuję też wielu stanów. Na razie staram się uruchomić ten prosty przykład:
<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>
Moje działania sąundefined
Na razie. Kiedy próbuję go skompilować, otrzymuję ten błąd:
<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>
Dostaję także różne błędy, gdy próbuję skompilować przykłady w repozytorium github Alexa, czy może to być związane z niedopasowaniem wersji? Zainstalowałem alex z cabal z ghc 7.0.4. Jakieś pomysły?