@@ -51,25 +51,28 @@ tokens :-
51
51
{
52
52
53
53
-- | 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 = ( fromIntegral x, map fromIntegral xs)
56
56
where
57
57
go oc
58
- | oc <= 0x7f = [oc]
58
+ | oc <= 0x7f = ( oc
59
+ , [
60
+ ])
59
61
60
- | oc <= 0x7ff = [ 0xc0 + (oc `Data.Bits.shiftR` 6 )
61
- , 0x80 + oc Data.Bits..&. 0x3f
62
- ]
62
+ | oc <= 0x7ff = ( 0xc0 + (oc `Data.Bits .shiftR ` 6 )
63
+ , [ 0x80 + oc Data.Bits..&. 0x3f
64
+ ])
63
65
64
- | oc <= 0xffff = [ 0xe0 + (oc `Data.Bits.shiftR` 12 )
65
- , 0x80 + ((oc `Data.Bits.shiftR` 6 ) Data.Bits..&. 0x3f )
66
+ | oc <= 0xffff = ( 0xe0 + (oc `Data.Bits .shiftR ` 12 )
67
+ , [ 0x80 + ((oc `Data.Bits.shiftR` 6 ) Data.Bits..&. 0x3f )
66
68
, 0x80 + oc Data.Bits..&. 0x3f
67
- ]
68
- | otherwise = [ 0xf0 + (oc `Data.Bits.shiftR` 18 )
69
- , 0x80 + ((oc `Data.Bits.shiftR` 12 ) Data.Bits..&. 0x3f )
69
+ ])
70
+ | otherwise = ( 0xf0 + (oc `Data.Bits .shiftR ` 18 )
71
+ , [ 0x80 + ((oc `Data.Bits.shiftR` 12 ) Data.Bits..&. 0x3f )
70
72
, 0x80 + ((oc `Data.Bits.shiftR` 6 ) Data.Bits..&. 0x3f )
71
73
, 0x80 + oc Data.Bits..&. 0x3f
72
- ]
74
+ ])
75
+ (x, xs) = go (ord c)
73
76
74
77
type Byte = Word8
75
78
@@ -99,7 +102,7 @@ alexGetByte :: AlexInput -> Maybe (Byte,AlexInput)
99
102
alexGetByte (p,c,(b:bs),s) = Just (b,(p,c,bs,s))
100
103
alexGetByte (_,_,[],[]) = Nothing
101
104
alexGetByte (p,_,[],(c:s)) = let p' = alexMove p c
102
- (b: bs) = utf8Encode c
105
+ (b, bs) = utf8Encode' c
103
106
in p' `seq` Just (b, (p' , c, bs, s))
104
107
105
108
data AlexPosn = AlexPn !Int !Int !Int
0 commit comments