summaryrefslogtreecommitdiff
path: root/utils/genprimopcode/ParserM.hs
diff options
context:
space:
mode:
Diffstat (limited to 'utils/genprimopcode/ParserM.hs')
-rw-r--r--utils/genprimopcode/ParserM.hs12
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