Skip to content

Commit

Permalink
refactoring only
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmar committed Nov 25, 2011
1 parent 5ecc9ab commit a3abdc9
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions templates/wrappers.hs
Expand Up @@ -81,11 +81,40 @@ alexGetByte :: AlexInput -> Maybe (Byte,AlexInput)
alexGetByte (p,_,cs) | ByteString.null cs = Nothing
| otherwise = let b = ByteString.head cs
cs' = ByteString.tail cs
c = Data.Char.chr (fromIntegral b)
c = ByteString.w2c b
p' = alexMove p c
in p' `seq` cs' `seq` Just (b, (p', c, cs'))
#endif

#ifdef ALEX_BASIC_BYTESTRING
type AlexInput = (Char,
ByteString.ByteString)

alexInputPrevChar :: AlexInput -> Char
alexInputPrevChar (c,_) = c

alexGetByte (_, cs)
| ByteString.null cs = Nothing
| otherwise = Just (ByteString.head cs,
(ByteString.w2c $ ByteString.head cs,
ByteString.tail cs))
#endif

#ifdef ALEX_STRICT_BYTESTRING
data AlexInput = AlexInput { alexChar :: {-# UNPACK #-}!Char
, alexStr :: {-# UNPACK #-}!ByteString.ByteString }

alexInputPrevChar :: AlexInput -> Char
alexInputPrevChar = alexChar

alexGetByte (AlexInput _ cs)
| ByteString.null cs = Nothing
| otherwise = Just $! (ByteString.head cs, AlexInput c cs')
where
(c,cs') = (ByteString.w2c (ByteString.unsafeHead cs)
, ByteString.unsafeTail cs)
#endif

-- -----------------------------------------------------------------------------
-- Token positions

Expand Down Expand Up @@ -319,15 +348,6 @@ alexGetByte (_,[],(c:s)) = case utf8Encode c of
-- Basic wrapper, ByteString version

#ifdef ALEX_BASIC_BYTESTRING
type AlexInput = (Char,ByteString.ByteString)

alexGetByte (_, cs)
| ByteString.null cs = Nothing
| otherwise = Just (ByteString.head cs,
(ByteString.w2c $ ByteString.head cs,
ByteString.tail cs))

alexInputPrevChar (c,_) = c

-- alexScanTokens :: String -> [token]
alexScanTokens str = go ('\n',str)
Expand All @@ -343,18 +363,6 @@ alexScanTokens str = go ('\n',str)

#ifdef ALEX_STRICT_BYTESTRING

data AlexInput = AlexInput { alexChar :: {-# UNPACK #-}!Char
, alexStr :: {-# UNPACK #-}!ByteString.ByteString }

alexGetByte (AlexInput _ cs)
| ByteString.null cs = Nothing
| otherwise = Just $! (ByteString.head cs, AlexInput c cs')
where
(c,cs') = (ByteString.w2c (ByteString.unsafeHead cs)
, ByteString.unsafeTail cs)

alexInputPrevChar = alexChar

-- alexScanTokens :: String -> [token]
alexScanTokens str = go (AlexInput '\n' str)
where go inp@(AlexInput _ str) =
Expand Down

0 comments on commit a3abdc9

Please sign in to comment.