diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x index 4caca44a70151bdcabcbeabcb5d5a60e31a29987..b2f08f205281035399108dab9ff861c02dabbed1 100644 --- a/compiler/parser/Lexer.x +++ b/compiler/parser/Lexer.x @@ -699,8 +699,19 @@ notFollowedBy char _ _ _ (AI _ _ buf) notFollowedBySymbol _ _ _ (AI _ _ buf) = nextCharIs buf (`notElem` "!#$%&*+./<=>?@\\^|-~") +-- We must reject doc comments as being ordinary comments everywhere. +-- In some cases the doc comment will be selected as the lexeme due to +-- maximal munch, but not always, because the nested comment rule is +-- valid in all states, but the doc-comment rules are only valid in +-- the non-layout states. isNormalComment bits _ _ (AI _ _ buf) - = nextCharIs 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)) haddockDisabledAnd p bits _ _ (AI _ _ buf) = if haddockEnabled bits then False else (p buf)