From 0c305dcaad0db515630cf0d71174a5dca4bd2258 Mon Sep 17 00:00:00 2001 From: sof Date: Wed, 19 Mar 1997 09:09:33 +0000 Subject: [PATCH] [project @ 1997-03-19 09:09:33 by sof] Fixed to gracefully handle decl delims (;;) inside strings --- ghc/compiler/reader/Lex.lhs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/ghc/compiler/reader/Lex.lhs b/ghc/compiler/reader/Lex.lhs index 626762d..edc6f05 100644 --- a/ghc/compiler/reader/Lex.lhs +++ b/ghc/compiler/reader/Lex.lhs @@ -438,9 +438,9 @@ lex_keyword buf = Just xx -> xx : lexIface (stepOverLexeme buf') lex_decl buf = - case expandUntilMatch buf ";;" of + case doDiscard False buf of -- spin until ;; is found buf' -> --- _trace (show (lexemeToString buf')) $ + {- _trace (show (lexemeToString buf')) $ -} case currentChar# buf' of '\n'# -> -- newline, no id info. ITtysig (lexIface (lexemeToBuffer (decLexeme buf'))) : @@ -452,7 +452,7 @@ lex_decl buf = ITtysig (lexIface (lexemeToBuffer (decLexeme buf'))) : lexIface (stepOverLexeme buf') c -> -- run all over the id info - case expandUntilMatch (stepOverLexeme buf') ";;" of + case doDiscard False (stepOverLexeme buf') of -- spin until ;; is found (outside a string!) buf'' -> --_trace ((C# c):show (lexemeToString (decLexeme buf'))) $ --_trace (show (lexemeToString (decLexeme buf''))) $ @@ -763,13 +763,24 @@ haskellKeywordsFM = listToUFM $ -- doDiscard rips along really fast looking for a double semicolon, -- indicating the end of the pragma we're skipping -doDiscard buf = +doDiscard inStr buf = +-- _trace (show (C# (currentChar# buf))) $ case currentChar# buf of ';'# -> - case lookAhead# buf 1# of - ';'# -> stepOnBy# buf 2# - _ -> doDiscard (stepOn buf) - _ -> doDiscard (stepOn buf) + if not inStr then + case lookAhead# buf 1# of + ';'# -> incLexeme (incLexeme buf) + _ -> doDiscard inStr (incLexeme buf) + else + doDiscard inStr (incLexeme buf) + '"'# -> + case lookAhead# buf (negateInt# 1#) of --backwards, actually + '\\'# -> -- false alarm, escaped. + doDiscard inStr (incLexeme buf) + _ -> case inStr of -- forced to avoid build-up + True -> doDiscard False (incLexeme buf) + False -> doDiscard True (incLexeme buf) + _ -> doDiscard inStr (incLexeme buf) \end{code} -- 1.7.10.4