[project @ 2000-03-06 11:58:27 by simonmar]
authorsimonmar <unknown>
Mon, 6 Mar 2000 11:58:28 +0000 (11:58 +0000)
committersimonmar <unknown>
Mon, 6 Mar 2000 11:58:28 +0000 (11:58 +0000)
Turn the panic in Lex.popContext into a parse error.

ghc/compiler/parser/Lex.lhs
ghc/compiler/parser/ParseUtil.lhs

index b2f04b0..6d56a6d 100644 (file)
@@ -20,7 +20,7 @@ An example that provokes the error is
 
 module Lex (
 
-       ifaceParseErr,
+       ifaceParseErr, srcParseErr,
 
        -- Monad for parser
        Token(..), lexer, ParseResult(..), PState(..),
@@ -1250,10 +1250,10 @@ layoutOff buf s@(PState{ context = ctx }) =
     POk s{ context = NoLayout:ctx } ()
 
 popContext :: P ()
-popContext = \ buf s@(PState{ context = ctx }) ->
+popContext = \ buf s@(PState{ context = ctx, loc = loc }) ->
   case ctx of
        (_:tl) -> POk s{ context = tl } ()
-       []    -> panic "Lex.popContext: empty context"
+       []     -> PFailed (srcParseErr buf loc)
 
 {- 
  Note that if the name of the file we're processing ends
@@ -1295,4 +1295,17 @@ ifaceVersionErr hi_vers l toks
         Nothing -> ptext SLIT("pre ghc-3.02 version")
        Just v  -> ptext SLIT("version") <+> integer v
 
+-----------------------------------------------------------------------------
+
+srcParseErr :: StringBuffer -> SrcLoc -> Message
+srcParseErr s l
+  = hcat [ppr l, 
+         if null token 
+            then ptext SLIT(": parse error (possibly incorrect indentation)")
+            else hcat [ptext SLIT(": parse error on input "),
+                       char '`', text token, char '\'']
+    ]
+  where 
+       token = lexemeToString s
+
 \end{code}
index c396e3f..e26415e 100644 (file)
@@ -6,7 +6,6 @@
 \begin{code}
 module ParseUtil (
          parseError            -- String -> Pa
-       , srcParseErr           -- StringBuffer -> SrcLoc -> Message
        , cbot                  -- a
        , splitForConApp        -- RdrNameHsType -> [RdrNameBangType]
                                --     -> P (RdrName, [RdrNameBangType])
@@ -71,17 +70,6 @@ parseError s =
   getSrcLocP `thenP` \ loc ->
   failMsgP (hcat [ppr loc, text ": ", text s])
 
-srcParseErr :: StringBuffer -> SrcLoc -> Message
-srcParseErr s l
-  = hcat [ppr l, 
-         if null token 
-            then ptext SLIT(": parse error (possibly incorrect indentation)")
-            else hcat [ptext SLIT(": parse error on input "),
-                       char '`', text token, char '\'']
-    ]
-  where 
-       token = lexemeToString s
-
 cbot = panic "CCall:result_ty"
 
 -----------------------------------------------------------------------------