summaryrefslogtreecommitdiff
path: root/libraries/ghc-boot-th
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2016-09-01 14:13:47 -0400
committerBen Gamari <ben@smart-cactus.org>2016-09-01 14:13:48 -0400
commit8d35e18d885e60f998a9dddb6db19762fe4c6d92 (patch)
tree0dc9eaa34f6754564ef2869e67e3ce381ea766a8 /libraries/ghc-boot-th
parent1e39c29ab55b9df83df142ad50e7a79e22f47f9e (diff)
downloadhaskell-8d35e18d885e60f998a9dddb6db19762fe4c6d92.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/ghc-boot-th')
-rw-r--r--libraries/ghc-boot-th/GHC/Lexeme.hs23
1 files changed, 20 insertions, 3 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