-scanNumLit :: Int -> StringBuffer -> (Int,StringBuffer)
-scanNumLit (I# acc#) (StringBuffer fo l# s# c#) =
- loop acc# c#
- where
- loop acc# c# =
- case indexCharOffAddr# fo c# of
- ch# | isDigit (C# ch#) -> loop (acc# *# 10# +# (ord# ch# -# ord# '0'#)) (c# +# 1#)
- | ch# `eqChar#` '\NUL'# && c# >=# l# -> (I# acc#, StringBuffer fo l# l# l#) -- EOB, return immediately.
- | otherwise -> (I# acc#,StringBuffer fo l# s# c#)
-
-
-expandUntilMatch :: StringBuffer -> String -> StringBuffer
-expandUntilMatch (StringBuffer fo l# s# c#) str =
- loop c# str
- where
- loop c# [] = StringBuffer fo l# s# c#
- loop c# ((C# x#):xs) =
- if indexCharOffAddr# fo c# `eqChar#` x# then
- loop (c# +# 1#) xs
- else
- loop (c# +# 1#) str
-\end{code}
-
-\begin{code}
- -- at or beyond end of buffer?
-bufferExhausted :: StringBuffer -> Bool
-bufferExhausted (StringBuffer fo l# _ c#) = c# >=# l#
-
-emptyLexeme :: StringBuffer -> Bool
-emptyLexeme (StringBuffer fo l# s# c#) = s# ==# c#
-
- -- matching
-prefixMatch :: StringBuffer -> String -> Maybe StringBuffer
-prefixMatch (StringBuffer fo l# s# c#) str =
- loop c# str
- where
- loop c# [] = Just (StringBuffer fo l# s# c#)
- loop c# ((C# x#):xs) =
- if indexCharOffAddr# fo c# `eqChar#` x# then
- loop (c# +# 1#) xs
- else
- Nothing
-
-untilEndOfString# :: StringBuffer -> StringBuffer
-untilEndOfString# (StringBuffer fo l# s# c#) =
- loop c#
- where
- loop c# =
- case indexCharOffAddr# fo c# of
- '\"'# ->
- case indexCharOffAddr# fo (c# -# 1#) of
- '\\'# ->
- -- looks like an escaped something or other to me,
- -- better count the number of "\\"s that are immediately
- -- preceeding to decide if the " is escaped.
- let
- odd_slashes flg i# =
- case indexCharOffAddr# fo i# of
- '\\'# -> odd_slashes (not flg) (i# -# 1#)
- _ -> flg
- in
- if odd_slashes True (c# -# 2#) then
- -- odd number, " is ecaped.
- loop (c# +# 1#)
- else -- a real end of string delimiter after all.
- StringBuffer fo l# s# c#
- _ -> StringBuffer fo l# s# c#
- '\NUL'# ->
- if c# >=# l# then -- hit sentinel, this doesn't look too good..
- StringBuffer fo l# l# l#
- else
- loop (c# +# 1#)
- _ -> loop (c# +# 1#)
-
-
-untilEndOfChar# :: StringBuffer -> StringBuffer
-untilEndOfChar# (StringBuffer fo l# s# c#) =
- loop c#
- where
- loop c# =
- case indexCharOffAddr# fo c# of
- '\''# ->
- case indexCharOffAddr# fo (c# -# 1#) of
- '\\'# ->
- case indexCharOffAddr# fo (c# -# 2#) of
- '\\'# -> -- end of char
- StringBuffer fo l# s# c#
- _ -> loop (c# +# 1#) -- false alarm
- _ -> StringBuffer fo l# s# c#
- '\NUL'# ->
- if c# >=# l# then -- hit sentinel, this doesn't look too good..
- StringBuffer fo l# l# l#
- else
- loop (c# +# 1#)
- _ -> loop (c# +# 1#)
-
-untilChar# :: StringBuffer -> Char# -> StringBuffer
-untilChar# (StringBuffer fo l# s# c#) x# =
- loop c#
- where
- loop c# =
- if indexCharOffAddr# fo c# `eqChar#` x# then
- StringBuffer fo l# s# c#
- else
- loop (c# +# 1#)
-
- -- conversion
-lexemeToString :: StringBuffer -> String
-lexemeToString (StringBuffer fo _ start_pos# current#) =
- if start_pos# ==# current# then
- ""
- else
- unpackCStringBA (copySubStr (A# fo) (I# start_pos#) (I# (current# -# start_pos#)))
-
-lexemeToByteArray :: StringBuffer -> _ByteArray Int
-lexemeToByteArray (StringBuffer fo _ start_pos# current#) =
- if start_pos# ==# current# then
- error "lexemeToByteArray"
- else
- copySubStr (A# fo) (I# start_pos#) (I# (current# -# start_pos#))
-
-lexemeToFastString :: StringBuffer -> FastString
-lexemeToFastString (StringBuffer fo l# start_pos# current#) =
- if start_pos# ==# current# then
- mkFastCharString2 (A# fo) (I# 0#)
- else
- mkFastSubString (A# fo) (I# start_pos#) (I# (current# -# start_pos#))
-
-{-
- Create a StringBuffer from the current lexeme, and add a sentinel
- at the end. Know What You're Doing before taking this function
- into use..
--}
-lexemeToBuffer :: StringBuffer -> StringBuffer
-lexemeToBuffer (StringBuffer fo l# start_pos# current#) =
- if start_pos# ==# current# then
- StringBuffer fo 0# start_pos# current# -- an error, really.
- else
- unsafeWriteBuffer (StringBuffer fo (current# -# start_pos#) start_pos# start_pos#)
- (current# -# 1#)
- '\NUL'#
-