diff options
author | Simon Marlow <marlowsd@gmail.com> | 2011-08-08 09:24:09 +0100 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2011-08-08 13:48:39 +0100 |
commit | 61ce073196ebe94d2c1695a3ff34a95153c941a2 (patch) | |
tree | 6ec2d3b3b3acadeb47ae0a47ec699aaae241801b /utils/genprimopcode/ParserM.hs | |
parent | 6b5bbe0747744bd56b09f5c2e53ec288c5507e29 (diff) | |
download | haskell-61ce073196ebe94d2c1695a3ff34a95153c941a2.tar.gz |
compatibility with Alex 3.0
Diffstat (limited to 'utils/genprimopcode/ParserM.hs')
-rw-r--r-- | utils/genprimopcode/ParserM.hs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/utils/genprimopcode/ParserM.hs b/utils/genprimopcode/ParserM.hs index a2b39d7a21..514ed3ec2f 100644 --- a/utils/genprimopcode/ParserM.hs +++ b/utils/genprimopcode/ParserM.hs @@ -13,11 +13,14 @@ module ParserM ( -- Positions get_pos, show_pos, -- Input - alexGetChar, alexInputPrevChar, input, position, + alexGetChar, alexGetByte, alexInputPrevChar, input, position, -- Other happyError ) where +import Data.Word (Word8) +import Data.Char (ord) + -- Parser Monad newtype ParserM a = ParserM (AlexInput -> St -> Either String (AlexInput, St, a)) @@ -133,6 +136,13 @@ show_pos (Pos l c) = "line " ++ show l ++ ", column " ++ show c data AlexInput = AlexInput {position :: !Pos, input :: String} +-- alexGetByte is for Alex >= 3.0, alexGetChar for earlier +-- XXX no UTF-8; we should do this properly sometime +alexGetByte :: AlexInput -> Maybe (Word8,AlexInput) +alexGetByte (AlexInput p (x:xs)) = Just (fromIntegral (ord x), + AlexInput (alexMove p x) xs) +alexGetByte (AlexInput _ []) = Nothing + alexGetChar :: AlexInput -> Maybe (Char,AlexInput) alexGetChar (AlexInput p (x:xs)) = Just (x, AlexInput (alexMove p x) xs) alexGetChar (AlexInput _ []) = Nothing |