diff options
author | Malo Jaffré <jaffre.malo@gmail.com> | 2016-09-01 14:13:47 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-09-01 15:05:16 -0400 |
commit | f233f00b1915ac6c0a200b8017a9f07deefd401e (patch) | |
tree | 0dc9eaa34f6754564ef2869e67e3ce381ea766a8 /libraries | |
parent | b946cf3f5d6fd273a79b008472e8cb0ad1432be1 (diff) | |
download | haskell-f233f00b1915ac6c0a200b8017a9f07deefd401e.tar.gz |
Fix startsVarSym and refactor operator predicates (fixes #4239)
startsVarSym used isSymbol which does not recognize valid operators
beginning with OtherPunctuation generalCategory (e. g. (·)).
Move it to ghc-boot-th for reducing duplication.
This patch fixes template-haskell pretty printer, which is used by
-ddump-minimal-imports.
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2480
GHC Trac Issues: #4239
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/ghc-boot-th/GHC/Lexeme.hs | 23 | ||||
-rw-r--r-- | libraries/template-haskell/Language/Haskell/TH/Ppr.hs | 8 |
2 files changed, 23 insertions, 8 deletions
diff --git a/libraries/ghc-boot-th/GHC/Lexeme.hs b/libraries/ghc-boot-th/GHC/Lexeme.hs index 677c9a65e6..2ecee61ea6 100644 --- a/libraries/ghc-boot-th/GHC/Lexeme.hs +++ b/libraries/ghc-boot-th/GHC/Lexeme.hs @@ -11,14 +11,31 @@ module GHC.Lexeme ( -- * Lexical characteristics of Haskell names startsVarSym, startsVarId, startsConSym, startsConId, - startsVarSymASCII, isVarSymChar + startsVarSymASCII, isVarSymChar, okSymChar ) where import Data.Char +-- | Is this character acceptable in a symbol (after the first char)? +-- See alexGetByte in Lexer.x +okSymChar :: Char -> Bool +okSymChar c + | c `elem` "(),;[]`{}_\"'" + = False + | otherwise + = case generalCategory c of + ConnectorPunctuation -> True + DashPunctuation -> True + OtherPunctuation -> True + MathSymbol -> True + CurrencySymbol -> True + ModifierSymbol -> True + OtherSymbol -> True + _ -> False + startsVarSym, startsVarId, startsConSym, startsConId :: Char -> Bool -startsVarSym c = startsVarSymASCII c || (ord c > 0x7f && isSymbol c) -- Infix Ids -startsConSym c = c == ':' -- Infix data constructors +startsVarSym c = okSymChar c && c /= ':' -- Infix Ids +startsConSym c = c == ':' -- Infix data constructors startsVarId c = c == '_' || case generalCategory c of -- Ordinary Ids LowercaseLetter -> True OtherLetter -> True -- See #1103 diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs index bdd4dd388a..0462a8da25 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs @@ -10,8 +10,9 @@ import Text.PrettyPrint (render) import Language.Haskell.TH.PprLib import Language.Haskell.TH.Syntax import Data.Word ( Word8 ) -import Data.Char ( toLower, chr, ord, isSymbol ) +import Data.Char ( toLower, chr) import GHC.Show ( showMultiLineString ) +import GHC.Lexeme( startsVarSym ) import Data.Ratio ( numerator, denominator ) nestDepth :: Int @@ -114,12 +115,9 @@ isSymOcc :: Name -> Bool isSymOcc n = case nameBase n of [] -> True -- Empty name; weird - (c:_) -> isSymbolASCII c || (ord c > 0x7f && isSymbol c) + (c:_) -> startsVarSym c -- c.f. OccName.startsVarSym in GHC itself -isSymbolASCII :: Char -> Bool -isSymbolASCII c = c `elem` "!#$%&*+./<=>?@\\^|~-" - pprInfixExp :: Exp -> Doc pprInfixExp (VarE v) = pprName' Infix v pprInfixExp (ConE v) = pprName' Infix v |