From 1145d75aeb749b255533ea5f76d8c57146881cb6 Mon Sep 17 00:00:00 2001
From: simonmar <unknown>
Date: Wed, 5 Jan 2000 17:23:34 +0000
Subject: [PATCH] [project @ 2000-01-05 17:23:34 by simonmar] Emit a reasonable
 error message instead of crashing when there's an unterminated
 literal-liberal in the source file.

---
 ghc/compiler/parser/Lex.lhs         |  9 +++++----
 ghc/compiler/utils/StringBuffer.lhs | 14 +++++++-------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/ghc/compiler/parser/Lex.lhs b/ghc/compiler/parser/Lex.lhs
index ba2ed1fd6315..c86721c9f6cc 100644
--- a/ghc/compiler/parser/Lex.lhs
+++ b/ghc/compiler/parser/Lex.lhs
@@ -369,7 +369,8 @@ lexer cont buf s@(PState{
 		})
 
 	-- first, start a new lexeme and lose all the whitespace
-  = tab line bol atbol (stepOverLexeme buf)
+  =  _scc_ "Lexer" 
+  tab line bol atbol (stepOverLexeme buf)
   where
 	line = srcLocLine loc
 
@@ -509,7 +510,6 @@ lexBOL cont buf s@(PState{
 lexToken :: (Token -> P a) -> Int# -> P a
 lexToken cont glaexts buf =
  --trace "lexToken" $
- _scc_ "Lexer" 
   case currentChar# buf of
 
     -- special symbols ----------------------------------------------------
@@ -864,9 +864,10 @@ after_lexnum cont glaexts i buf
 
 lex_cstring cont buf =
  case expandUntilMatch (stepOverLexeme buf) "\'\'" of
-   buf' -> cont (ITlitlit (lexemeToFastString 
+   Just buf' -> cont (ITlitlit (lexemeToFastString 
 				(setCurrentPos# buf' (negateInt# 2#))))
-           	(mergeLexemes buf buf')
+           	   (mergeLexemes buf buf')
+   Nothing   -> lexError "unterminated ``" buf
 
 ------------------------------------------------------------------------------
 -- Character Classes
diff --git a/ghc/compiler/utils/StringBuffer.lhs b/ghc/compiler/utils/StringBuffer.lhs
index 115d36c50946..b6b728fa451d 100644
--- a/ghc/compiler/utils/StringBuffer.lhs
+++ b/ghc/compiler/utils/StringBuffer.lhs
@@ -415,16 +415,16 @@ scanNumLit acc (StringBuffer fo l# s# c#) =
          | 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}
 
-- 
GitLab