Skip to content
Snippets Groups Projects
Commit df87766e authored by Gergő Érdi's avatar Gergő Érdi
Browse files

isLexVarSym: check all characters of the name, not just the first one.

This is so that generated names like e.g. workers don't show up as
infix operators when using something like -ddump-simpl.
parent 25f98585
No related branches found
No related tags found
No related merge requests found
...@@ -501,7 +501,7 @@ isDataSymOcc _ = False ...@@ -501,7 +501,7 @@ isDataSymOcc _ = False
-- it is a data constructor or variable or whatever) -- it is a data constructor or variable or whatever)
isSymOcc :: OccName -> Bool isSymOcc :: OccName -> Bool
isSymOcc (OccName DataName s) = isLexConSym s isSymOcc (OccName DataName s) = isLexConSym s
isSymOcc (OccName TcClsName s) = isLexConSym s || isLexVarSym s isSymOcc (OccName TcClsName s) = isLexSym s
isSymOcc (OccName VarName s) = isLexSym s isSymOcc (OccName VarName s) = isLexSym s
isSymOcc (OccName TvName s) = isLexSym s isSymOcc (OccName TvName s) = isLexSym s
-- Pretty inefficient! -- Pretty inefficient!
...@@ -869,6 +869,15 @@ isTupleOcc_maybe (OccName ns fs) ...@@ -869,6 +869,15 @@ isTupleOcc_maybe (OccName ns fs)
These functions test strings to see if they fit the lexical categories These functions test strings to see if they fit the lexical categories
defined in the Haskell report. defined in the Haskell report.
Note [Classification of generated names]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Some names generated for internal use can show up in debugging output,
e.g. when using -ddump-simpl. These generated names start with a $
but should still be pretty-printed using prefix notation. We make sure
this is the case in isLexVarSym by only classifying a name as a symbol
if all its characters are symbols, not just its first one.
\begin{code} \begin{code}
isLexCon, isLexVar, isLexId, isLexSym :: FastString -> Bool isLexCon, isLexVar, isLexId, isLexSym :: FastString -> Bool
isLexConId, isLexConSym, isLexVarId, isLexVarSym :: FastString -> Bool isLexConId, isLexConSym, isLexVarId, isLexVarSym :: FastString -> Bool
...@@ -895,19 +904,23 @@ isLexConSym cs -- Infix type or data constructors ...@@ -895,19 +904,23 @@ isLexConSym cs -- Infix type or data constructors
| cs == (fsLit "->") = True | cs == (fsLit "->") = True
| otherwise = startsConSym (headFS cs) | otherwise = startsConSym (headFS cs)
isLexVarSym cs -- Infix identifiers isLexVarSym fs -- Infix identifiers e.g. "+"
| nullFS cs = False -- e.g. "+" = case (if nullFS fs then [] else unpackFS fs) of
| otherwise = startsVarSym (headFS cs) [] -> False
(c:cs) -> startsVarSym c && all isVarSymChar cs
------------- -------------
startsVarSym, startsVarId, startsConSym, startsConId :: Char -> Bool startsVarSym, startsVarId, startsConSym, startsConId :: Char -> Bool
startsVarSym c = isSymbolASCII c || (ord c > 0x7f && isSymbol c) -- Infix Ids startsVarSym c = isSymbolASCII c || (ord c > 0x7f && isSymbol c) -- Infix Ids
startsConSym c = c == ':' -- Infix data constructors startsConSym c = c == ':' -- Infix data constructors
startsVarId c = isLower c || c == '_' -- Ordinary Ids startsVarId c = isLower c || c == '_' -- Ordinary Ids
startsConId c = isUpper c || c == '(' -- Ordinary type constructors and data constructors startsConId c = isUpper c || c == '(' -- Ordinary type constructors and data constructors
isSymbolASCII :: Char -> Bool isSymbolASCII :: Char -> Bool
isSymbolASCII c = c `elem` "!#$%&*+./<=>?@\\^|~-" isSymbolASCII c = c `elem` "!#$%&*+./<=>?@\\^|~-"
isVarSymChar :: Char -> Bool
isVarSymChar c = c == ':' || startsVarSym c
\end{code} \end{code}
%************************************************************************ %************************************************************************
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment