From 61ce073196ebe94d2c1695a3ff34a95153c941a2 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Mon, 8 Aug 2011 09:24:09 +0100 Subject: compatibility with Alex 3.0 --- utils/genprimopcode/Lexer.x | 2 +- utils/genprimopcode/ParserM.hs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/utils/genprimopcode/Lexer.x b/utils/genprimopcode/Lexer.x index 6f48c02f8f..24ea7b2ef6 100644 --- a/utils/genprimopcode/Lexer.x +++ b/utils/genprimopcode/Lexer.x @@ -14,7 +14,7 @@ import ParserM (ParserM (..), mkT, mkTv, Token(..), St, start_code, set_start_code, inc_brace_depth, dec_brace_depth, show_pos, position, input, - AlexInput, alexGetChar, alexInputPrevChar) + AlexInput, alexGetChar, alexGetByte, alexInputPrevChar) } words :- 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 -- cgit v1.2.1