X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fparser%2FLexer.x;h=b2f08f205281035399108dab9ff861c02dabbed1;hb=b1ab4b8a607addc4d097588db5761313c996a41f;hp=d9a0fb08b0e28e578d7a115ce0995fb14f90ce7b;hpb=317fc69d18eda68fd65f5ba634feafbe4a3923da;p=ghc-hetmet.git diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x index d9a0fb0..b2f08f2 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 @@ -646,7 +646,7 @@ reservedSymsFM = listToUFM $ ,("∀", ITforall, bit glaExtsBit) ,("→", ITrarrow, bit glaExtsBit) ,("←", ITlarrow, bit glaExtsBit) - ,("?", ITdotdot, bit glaExtsBit) + ,("⋯", ITdotdot, bit glaExtsBit) -- ToDo: ideally, → and ∷ should be "specials", so that they cannot -- form part of a large operator. This would let us have a better -- syntax for kinds: ɑ∷*→* would be a legal kind signature. (maybe). @@ -699,12 +699,17 @@ 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) | haddockEnabled bits = notFollowedByDocOrPragma | otherwise = nextCharIs buf (/='#') - where - notFollowedByDocOrPragma - = not $ spaceAndP buf (`nextCharIs` (`elem` "|^*$#")) + where + notFollowedByDocOrPragma + = not $ spaceAndP buf (`nextCharIs` (`elem` "|^*$#")) spaceAndP buf p = p buf || nextCharIs buf (==' ') && p (snd (nextChar buf)) @@ -785,13 +790,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