Skip to content

Commit 2cd298f

Browse files
authored
Merge pull request #135 from josephcsible/nonempty
Fix warnings about non-exhaustive patterns
2 parents c6c8870 + b112143 commit 2cd298f

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

templates/wrappers.hs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,30 @@ import qualified Data.Bits
3030

3131
-- | Encode a Haskell String to a list of Word8 values, in UTF8 format.
3232
utf8Encode :: Char -> [Word8]
33-
utf8Encode = map fromIntegral . go . ord
33+
utf8Encode = uncurry (:) . utf8Encode'
34+
35+
utf8Encode' :: Char -> (Word8, [Word8])
36+
utf8Encode' c = case go (ord c) of
37+
(x, xs) -> (fromIntegral x, map fromIntegral xs)
3438
where
3539
go oc
36-
| oc <= 0x7f = [oc]
40+
| oc <= 0x7f = ( oc
41+
, [
42+
])
3743

38-
| oc <= 0x7ff = [ 0xc0 + (oc `Data.Bits.shiftR` 6)
39-
, 0x80 + oc Data.Bits..&. 0x3f
40-
]
44+
| oc <= 0x7ff = ( 0xc0 + (oc `Data.Bits.shiftR` 6)
45+
, [0x80 + oc Data.Bits..&. 0x3f
46+
])
4147

42-
| oc <= 0xffff = [ 0xe0 + (oc `Data.Bits.shiftR` 12)
43-
, 0x80 + ((oc `Data.Bits.shiftR` 6) Data.Bits..&. 0x3f)
48+
| oc <= 0xffff = ( 0xe0 + (oc `Data.Bits.shiftR` 12)
49+
, [0x80 + ((oc `Data.Bits.shiftR` 6) Data.Bits..&. 0x3f)
4450
, 0x80 + oc Data.Bits..&. 0x3f
45-
]
46-
| otherwise = [ 0xf0 + (oc `Data.Bits.shiftR` 18)
47-
, 0x80 + ((oc `Data.Bits.shiftR` 12) Data.Bits..&. 0x3f)
51+
])
52+
| otherwise = ( 0xf0 + (oc `Data.Bits.shiftR` 18)
53+
, [0x80 + ((oc `Data.Bits.shiftR` 12) Data.Bits..&. 0x3f)
4854
, 0x80 + ((oc `Data.Bits.shiftR` 6) Data.Bits..&. 0x3f)
4955
, 0x80 + oc Data.Bits..&. 0x3f
50-
]
56+
])
5157

5258
#endif
5359

@@ -72,8 +78,8 @@ alexGetByte :: AlexInput -> Maybe (Byte,AlexInput)
7278
alexGetByte (p,c,(b:bs),s) = Just (b,(p,c,bs,s))
7379
alexGetByte (_,_,[],[]) = Nothing
7480
alexGetByte (p,_,[],(c:s)) = let p' = alexMove p c
75-
(b:bs) = utf8Encode c
76-
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))
7783
#endif
7884

7985
#if defined(ALEX_POSN_BYTESTRING) || defined(ALEX_MONAD_BYTESTRING)
@@ -334,9 +340,8 @@ alexScanTokens str = go ('\n',[],str)
334340
alexGetByte :: AlexInput -> Maybe (Byte,AlexInput)
335341
alexGetByte (c,(b:bs),s) = Just (b,(c,bs,s))
336342
alexGetByte (_,[],[]) = Nothing
337-
alexGetByte (_,[],(c:s)) = case utf8Encode c of
338-
(b:bs) -> Just (b, (c, bs, s))
339-
[] -> Nothing
343+
alexGetByte (_,[],(c:s)) = case utf8Encode' c of
344+
(b, bs) -> Just (b, (c, bs, s))
340345
#endif
341346

342347

tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ endif
1313

1414
# NOTE: This assumes that a working `ghc` is on $PATH; this may not necessarily be the same GHC used by `cabal` for building `alex`.
1515
HC=ghc
16-
HC_OPTS=-Wall -fno-warn-missing-signatures -fno-warn-unused-imports -fno-warn-tabs -Werror
16+
HC_OPTS=-Wall -fwarn-incomplete-uni-patterns -fno-warn-missing-signatures -fno-warn-unused-imports -fno-warn-tabs -Werror
1717

1818
.PRECIOUS: %.n.hs %.g.hs %.o %.exe %.bin
1919

tests/default_typeclass.x

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,28 @@ tokens :-
5151
{
5252

5353
-- | Encode a Haskell String to a list of Word8 values, in UTF8 format.
54-
utf8Encode :: Char -> [Word8]
55-
utf8Encode = map fromIntegral . go . ord
54+
utf8Encode' :: Char -> (Word8, [Word8])
55+
utf8Encode' c = case go (ord c) of
56+
(x, xs) -> (fromIntegral x, map fromIntegral xs)
5657
where
5758
go oc
58-
| oc <= 0x7f = [oc]
59+
| oc <= 0x7f = ( oc
60+
, [
61+
])
5962

60-
| oc <= 0x7ff = [ 0xc0 + (oc `Data.Bits.shiftR` 6)
61-
, 0x80 + oc Data.Bits..&. 0x3f
62-
]
63+
| oc <= 0x7ff = ( 0xc0 + (oc `Data.Bits.shiftR` 6)
64+
, [0x80 + oc Data.Bits..&. 0x3f
65+
])
6366

64-
| oc <= 0xffff = [ 0xe0 + (oc `Data.Bits.shiftR` 12)
65-
, 0x80 + ((oc `Data.Bits.shiftR` 6) Data.Bits..&. 0x3f)
67+
| oc <= 0xffff = ( 0xe0 + (oc `Data.Bits.shiftR` 12)
68+
, [0x80 + ((oc `Data.Bits.shiftR` 6) Data.Bits..&. 0x3f)
6669
, 0x80 + oc Data.Bits..&. 0x3f
67-
]
68-
| otherwise = [ 0xf0 + (oc `Data.Bits.shiftR` 18)
69-
, 0x80 + ((oc `Data.Bits.shiftR` 12) Data.Bits..&. 0x3f)
70+
])
71+
| otherwise = ( 0xf0 + (oc `Data.Bits.shiftR` 18)
72+
, [0x80 + ((oc `Data.Bits.shiftR` 12) Data.Bits..&. 0x3f)
7073
, 0x80 + ((oc `Data.Bits.shiftR` 6) Data.Bits..&. 0x3f)
7174
, 0x80 + oc Data.Bits..&. 0x3f
72-
]
75+
])
7376

7477
type Byte = Word8
7578

@@ -99,8 +102,8 @@ alexGetByte :: AlexInput -> Maybe (Byte,AlexInput)
99102
alexGetByte (p,c,(b:bs),s) = Just (b,(p,c,bs,s))
100103
alexGetByte (_,_,[],[]) = Nothing
101104
alexGetByte (p,_,[],(c:s)) = let p' = alexMove p c
102-
(b:bs) = utf8Encode c
103-
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))
104107

105108
data AlexPosn = AlexPn !Int !Int !Int
106109
deriving (Eq,Show)

0 commit comments

Comments
 (0)