From 35cb95c2119a3d903ecfe388d3a8ef0f4ededfdd Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Mon, 7 May 2007 11:37:01 +0000 Subject: [PATCH] properly fix leakage of Haddock comment syntax (see #1091, test: read044) --- compiler/parser/Lexer.x | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x index aa236b1..4caca44 100644 --- a/compiler/parser/Lexer.x +++ b/compiler/parser/Lexer.x @@ -271,8 +271,8 @@ $tab+ { warn Opt_WarnTabs (text "Tab character") } -- Haddock comments <0,glaexts> { - "-- " / $docsym { multiline_doc_comment } - "{-" \ ? / $docsym { nested_doc_comment } + "-- " $docsym / { ifExtension haddockEnabled } { multiline_doc_comment } + "{-" \ ? $docsym / { ifExtension haddockEnabled } { nested_doc_comment } } -- "special" symbols @@ -700,13 +700,7 @@ notFollowedBySymbol _ _ _ (AI _ _ buf) = nextCharIs buf (`notElem` "!#$%&*+./<=>?@\\^|-~") isNormalComment bits _ _ (AI _ _ buf) - | haddockEnabled bits = notFollowedByDocOrPragma - | otherwise = nextCharIs buf (/='#') - where - notFollowedByDocOrPragma - = not $ spaceAndP buf (`nextCharIs` (`elem` "|^*$#")) - -spaceAndP buf p = p buf || nextCharIs buf (==' ') && p (snd (nextChar buf)) + = nextCharIs buf (/='#') haddockDisabledAnd p bits _ _ (AI _ _ buf) = if haddockEnabled bits then False else (p buf) @@ -785,13 +779,12 @@ nested_doc_comment span buf _len = withLexedDocType (go "") Just (c,input) -> go (c:commentAcc) input docType False withLexedDocType lexDocComment = do - input <- getInput - case alexGetChar input of - Nothing -> error "Can't happen" - Just ('|', input) -> lexDocComment input ITdocCommentNext False - Just ('^', input) -> lexDocComment input ITdocCommentPrev False - Just ('$', input) -> lexDocComment input ITdocCommentNamed False - Just ('*', input) -> lexDocSection 1 input + input@(AI _ _ buf) <- getInput + case prevChar buf ' ' of + '|' -> lexDocComment input ITdocCommentNext False + '^' -> lexDocComment input ITdocCommentPrev False + '$' -> lexDocComment input ITdocCommentNamed False + '*' -> lexDocSection 1 input where lexDocSection n input = case alexGetChar input of Just ('*', input) -> lexDocSection (n+1) input -- 1.7.10.4