summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2011-08-08 09:24:09 +0100
committerSimon Marlow <marlowsd@gmail.com>2011-08-08 13:48:39 +0100
commit61ce073196ebe94d2c1695a3ff34a95153c941a2 (patch)
tree6ec2d3b3b3acadeb47ae0a47ec699aaae241801b
parent6b5bbe0747744bd56b09f5c2e53ec288c5507e29 (diff)
downloadhaskell-61ce073196ebe94d2c1695a3ff34a95153c941a2.tar.gz
compatibility with Alex 3.0
-rw-r--r--utils/genprimopcode/Lexer.x2
-rw-r--r--utils/genprimopcode/ParserM.hs12
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