stepOnBy#, -- :: StringBuffer -> Int# -> StringBuffer
stepOnTo#, -- :: StringBuffer -> Int# -> StringBuffer
stepOnUntil, -- :: (Char -> Bool) -> StringBuffer -> StringBuffer
+ stepOnUntilChar#, -- :: StringBuffer -> Char# -> StringBuffer
stepOverLexeme, -- :: StringBuffer -> StringBuffer
scanNumLit, -- :: Int -> StringBuffer -> (Int, StringBuffer)
squeezeLexeme, -- :: StringBuffer -> Int# -> StringBuffer
-- matching
prefixMatch, -- :: StringBuffer -> String -> Bool
untilEndOfString#, -- :: StringBuffer -> Int#
- untilChar#, -- :: StringBuffer -> Char# -> Int#
-- conversion
lexemeToString, -- :: StringBuffer -> String
#include "HsVersions.h"
import GlaExts
-import Addr ( Addr(..) )
+import PrelAddr ( Addr(..) )
import Foreign
-import ST
import Char ( chr )
-- urk!
-#include "../lib/std/cbits/error.h"
+#include "../lib/std/cbits/stgerror.h"
#if __GLASGOW_HASKELL__ >= 303
-import IO ( openFile, slurpFile )
+import IO ( openFile
+#if __GLASGOW_HASKELL__ < 407
+ , slurpFile -- comes from PrelHandle or IOExts now
+#endif
+ )
import PrelIOBase
import PrelHandle
import Addr
\end{code}
\begin{code}
-instance Text StringBuffer where
+instance Show StringBuffer where
showsPrec _ s = showString ""
\end{code}
allocMem :: Int -> IO Addr
allocMem sz = do
-#if __GLASGOW_HASKELL__ < 303
chunk <- _ccall_ malloc sz
+#if __GLASGOW_HASKELL__ < 303
if chunk == nullAddr
then fail (userError "allocMem")
else return chunk
#else
- chunk <- _ccall_ allocMemory__ sz
if chunk == nullAddr
then constructErrorAndFail "allocMem"
else return chunk
| otherwise -> (acc,StringBuffer fo l# s# c#)
-expandUntilMatch :: StringBuffer -> String -> StringBuffer
+expandUntilMatch :: StringBuffer -> String -> Maybe StringBuffer
expandUntilMatch (StringBuffer fo l# s# c#) str =
loop c# str
where
- loop c# [] = StringBuffer fo l# s# c#
- loop c# ((C# x#):xs)
- | indexCharOffAddr# fo c# `eqChar#` x#
- = loop (c# +# 1#) xs
- | otherwise
- = loop (c# +# 1#) str
+ loop c# [] = Just (StringBuffer fo l# s# c#)
+ loop c# ((C# x#):xs) =
+ case indexCharOffAddr# fo c# of
+ ch# | ch# `eqChar#` '\NUL'# && c# >=# l# -> Nothing
+ | ch# `eqChar#` x# -> loop (c# +# 1#) xs
+ | otherwise -> loop (c# +# 1#) str
\end{code}
_ -> loop (c# +# 1#)
-untilChar# :: StringBuffer -> Char# -> StringBuffer
-untilChar# (StringBuffer fo l# s# c#) x# =
+stepOnUntilChar# :: StringBuffer -> Char# -> StringBuffer
+stepOnUntilChar# (StringBuffer fo l# s# c#) x# =
loop c#
where
loop c#
| c# >=# l# || indexCharOffAddr# fo c# `eqChar#` x#
- = StringBuffer fo l# s# c#
+ = StringBuffer fo l# c# c#
| otherwise
= loop (c# +# 1#)
else
unpackCStringBA (copySubStr (A# fo) (I# start_pos#) (I# (current# -# start_pos#)))
-lexemeToByteArray :: StringBuffer -> _ByteArray Int
+lexemeToByteArray :: StringBuffer -> ByteArray Int
lexemeToByteArray (StringBuffer fo _ start_pos# current#) =
if start_pos# ==# current# then
error "lexemeToByteArray"