From 6e554967c4b55b15b7381112c0b03850610fb619 Mon Sep 17 00:00:00 2001 From: simonmar Date: Wed, 26 Sep 2001 09:16:00 +0000 Subject: [PATCH] [project @ 2001-09-26 09:16:00 by simonmar] When skipping a nested comment, keep track of the source location of the comment opener, so that we can report it in an error message rather than reporting the line at the end of the file. Also noticed a couple of ineficiencies in the nested comment code, so fixed those too. --- ghc/compiler/parser/Lex.lhs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ghc/compiler/parser/Lex.lhs b/ghc/compiler/parser/Lex.lhs index b4c9bc4..2a193d8 100644 --- a/ghc/compiler/parser/Lex.lhs +++ b/ghc/compiler/parser/Lex.lhs @@ -498,25 +498,28 @@ line_prag cont buf s@PState{loc=loc} = }}}} nested_comment :: P a -> P a -nested_comment cont buf = loop buf +nested_comment cont buf orig_state@PState{loc=loc} = loop buf orig_state where loop buf = case currentChar# buf of - '\NUL'# | bufferExhausted (stepOn buf) -> - lexError "unterminated `{-'" buf -- -} - '-'# | lookAhead# buf 1# `eqChar#` '}'# -> - cont (stepOnBy# buf 2#) + '-'# | lookAhead# buf 1# `eqChar#` '}'# -> cont (stepOnBy# buf 2#) '{'# | lookAhead# buf 1# `eqChar#` '-'# -> nested_comment (nested_comment cont) (stepOnBy# buf 2#) '\n'# -> \ s@PState{loc=loc} -> let buf' = stepOn buf in - nested_comment cont buf' - s{loc = incSrcLine loc, bol = currentIndex# buf', - atbol = 1#} + loop buf' s{loc = incSrcLine loc, + bol = currentIndex# buf', + atbol = 1#} + + -- pass the original state to lexError so that the error is + -- reported at the line it was originally on, not the line at + -- the end of the file. + '\NUL'# | bufferExhausted (stepOn buf) -> + \_ -> lexError "unterminated `{-'" buf orig_state -- -} - _ -> nested_comment cont (stepOn buf) + _ -> loop (stepOn buf) -- When we are lexing the first token of a line, check whether we need to -- insert virtual semicolons or close braces due to layout. -- 1.7.10.4