Permalink
Browse files

refactoring only

  • Loading branch information...
simonmar committed Aug 10, 2011
1 parent 5ecc9ab commit a3abdc93934065d23f7859f5586e77471e4c69dc
Showing with 30 additions and 22 deletions.
  1. +30 −22 templates/wrappers.hs
View
@@ -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
@@ -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)
@@ -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) =

0 comments on commit a3abdc9

Please sign in to comment.