Skip to content

Commit b112143

Browse files
committed
Use case to make things strict
1 parent 4ccece3 commit b112143

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

templates/wrappers.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ utf8Encode :: Char -> [Word8]
3333
utf8Encode = uncurry (:) . utf8Encode'
3434

3535
utf8Encode' :: Char -> (Word8, [Word8])
36-
utf8Encode' c = (fromIntegral x, map fromIntegral xs)
36+
utf8Encode' c = case go (ord c) of
37+
(x, xs) -> (fromIntegral x, map fromIntegral xs)
3738
where
3839
go oc
3940
| oc <= 0x7f = ( oc
@@ -53,7 +54,6 @@ utf8Encode' c = (fromIntegral x, map fromIntegral xs)
5354
, 0x80 + ((oc `Data.Bits.shiftR` 6) Data.Bits..&. 0x3f)
5455
, 0x80 + oc Data.Bits..&. 0x3f
5556
])
56-
(x, xs) = go (ord c)
5757

5858
#endif
5959

@@ -78,8 +78,8 @@ alexGetByte :: AlexInput -> Maybe (Byte,AlexInput)
7878
alexGetByte (p,c,(b:bs),s) = Just (b,(p,c,bs,s))
7979
alexGetByte (_,_,[],[]) = Nothing
8080
alexGetByte (p,_,[],(c:s)) = let p' = alexMove p c
81-
(b, bs) = utf8Encode' c
82-
in p' `seq` Just (b, (p', c, bs, s))
81+
in case utf8Encode' c of
82+
(b, bs) -> p' `seq` Just (b, (p', c, bs, s))
8383
#endif
8484

8585
#if defined(ALEX_POSN_BYTESTRING) || defined(ALEX_MONAD_BYTESTRING)
@@ -340,8 +340,8 @@ alexScanTokens str = go ('\n',[],str)
340340
alexGetByte :: AlexInput -> Maybe (Byte,AlexInput)
341341
alexGetByte (c,(b:bs),s) = Just (b,(c,bs,s))
342342
alexGetByte (_,[],[]) = Nothing
343-
alexGetByte (_,[],(c:s)) = let (b, bs) = utf8Encode' c
344-
in Just (b, (c, bs, s))
343+
alexGetByte (_,[],(c:s)) = case utf8Encode' c of
344+
(b, bs) -> Just (b, (c, bs, s))
345345
#endif
346346

347347

tests/default_typeclass.x

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ tokens :-
5252

5353
-- | Encode a Haskell String to a list of Word8 values, in UTF8 format.
5454
utf8Encode' :: Char -> (Word8, [Word8])
55-
utf8Encode' c = (fromIntegral x, map fromIntegral xs)
55+
utf8Encode' c = case go (ord c) of
56+
(x, xs) -> (fromIntegral x, map fromIntegral xs)
5657
where
5758
go oc
5859
| oc <= 0x7f = ( oc
@@ -72,7 +73,6 @@ utf8Encode' c = (fromIntegral x, map fromIntegral xs)
7273
, 0x80 + ((oc `Data.Bits.shiftR` 6) Data.Bits..&. 0x3f)
7374
, 0x80 + oc Data.Bits..&. 0x3f
7475
])
75-
(x, xs) = go (ord c)
7676

7777
type Byte = Word8
7878

@@ -102,8 +102,8 @@ alexGetByte :: AlexInput -> Maybe (Byte,AlexInput)
102102
alexGetByte (p,c,(b:bs),s) = Just (b,(p,c,bs,s))
103103
alexGetByte (_,_,[],[]) = Nothing
104104
alexGetByte (p,_,[],(c:s)) = let p' = alexMove p c
105-
(b, bs) = utf8Encode' c
106-
in p' `seq` Just (b, (p', c, bs, s))
105+
in case utf8Encode' c of
106+
(b, bs) -> p' `seq` Just (b, (p', c, bs, s))
107107

108108
data AlexPosn = AlexPn !Int !Int !Int
109109
deriving (Eq,Show)

0 commit comments

Comments
 (0)