From 21e5a60ce20652826a8d74a4357706fca86edfa9 Mon Sep 17 00:00:00 2001 From: krasimir Date: Thu, 17 Apr 2008 12:56:46 +0000 Subject: ByteString.readFile should be used instead of readFileStrict. This fixes the problem with the open files --- src/GF/Source/LexGF.hs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/GF/Source') diff --git a/src/GF/Source/LexGF.hs b/src/GF/Source/LexGF.hs index 6bdd4ab9f..89067b6b6 100644 --- a/src/GF/Source/LexGF.hs +++ b/src/GF/Source/LexGF.hs @@ -4,6 +4,7 @@ module GF.Source.LexGF where +import qualified Data.ByteString.Char8 as BS #if __GLASGOW_HASKELL__ >= 603 #include "ghcconfig.h" @@ -119,24 +120,25 @@ alexMove (Pn a l c) _ = Pn (a+1) l (c+1) type AlexInput = (Posn, -- current position, Char, -- previous char - String) -- current input string + BS.ByteString) -- current input string -tokens :: String -> [Token] +tokens :: BS.ByteString -> [Token] tokens str = go (alexStartPos, '\n', str) where - go :: (Posn, Char, String) -> [Token] + go :: AlexInput -> [Token] go inp@(pos, _, str) = case alexScan inp 0 of AlexEOF -> [] AlexError (pos, _, _) -> [Err pos] AlexSkip inp' len -> go inp' - AlexToken inp' len act -> act pos (take len str) : (go inp') + AlexToken inp' len act -> act pos (BS.unpack (BS.take len str)) : (go inp') alexGetChar :: AlexInput -> Maybe (Char,AlexInput) -alexGetChar (p, c, []) = Nothing -alexGetChar (p, _, (c:s)) = - let p' = alexMove p c - in p' `seq` Just (c, (p', c, s)) +alexGetChar (p,_,cs) | BS.null cs = Nothing + | otherwise = let c = BS.head cs + cs' = BS.tail cs + p' = alexMove p c + in p' `seq` cs' `seq` Just (c, (p', c, cs')) alexInputPrevChar :: AlexInput -> Char alexInputPrevChar (p, c, s) = c -- cgit v1.2.3