summaryrefslogtreecommitdiff
path: root/compiler/hsSyn/HsExpr.hs
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2017-02-17 12:13:14 +0200
committerAlan Zimmerman <alan.zimm@gmail.com>2017-02-18 20:40:09 +0200
commit43a082bb59310d10d3c7550d5cbeaab384ca4c76 (patch)
tree4aa60f80be7e87ede1db0af69e2c3e20d14d16a9 /compiler/hsSyn/HsExpr.hs
parent98e494afed3c73f88ff1d57a9ca46b1f6ddbd1b9 (diff)
downloadhaskell-43a082bb59310d10d3c7550d5cbeaab384ca4c76.tar.gz
Add HsEmbellished type to hsSynwip/embelleshed-rdr
Summary: A RdrName can be parsed with parens or backquotes if it is used prefix or infix respectively when it is normally not used that way. This is not captured in hsSyn, and must be inferred from the occName when pretty printing, or using the API annotations. Introduce a wrapper type around the name to capture this data Embellished name = EName name | EParens (Located name) | EBackquotes (Located name) So that we now have data HsExpr id = HsVar (LEmbellished id) -- ^ Variable and in the other relevant points in hsSyn. Test Plan: ./validate Reviewers: bgamari, austin, goldfire Subscribers: goldfire, thomie, mpickering, snowleopard Differential Revision: https://phabricator.haskell.org/D3145
Diffstat (limited to 'compiler/hsSyn/HsExpr.hs')
-rw-r--r--compiler/hsSyn/HsExpr.hs14
1 files changed, 8 insertions, 6 deletions
diff --git a/compiler/hsSyn/HsExpr.hs b/compiler/hsSyn/HsExpr.hs
index 71c408984b..0008827080 100644
--- a/compiler/hsSyn/HsExpr.hs
+++ b/compiler/hsSyn/HsExpr.hs
@@ -41,6 +41,7 @@ import Util
import Outputable
import FastString
import Type
+import HsEmbellished
-- libraries:
import Data.Data hiding (Fixity(..))
@@ -125,7 +126,7 @@ noSyntaxExpr = SyntaxExpr { syn_expr = HsLit (HsString NoSourceText
-- | Make a 'SyntaxExpr Name' (the "rn" is because this is used in the
-- renamer), missing its HsWrappers.
mkRnSyntaxExpr :: Name -> SyntaxExpr Name
-mkRnSyntaxExpr name = SyntaxExpr { syn_expr = HsVar $ noLoc name
+mkRnSyntaxExpr name = SyntaxExpr { syn_expr = HsVar $ noLoc $ EName name
, syn_arg_wraps = []
, syn_res_wrap = WpHole }
-- don't care about filling in syn_arg_wraps because we're clearly
@@ -274,7 +275,7 @@ information to use is the GlobalRdrEnv itself.
-- | A Haskell expression.
data HsExpr id
- = HsVar (Located id) -- ^ Variable
+ = HsVar (LEmbellished id) -- ^ Variable
-- See Note [Located RdrNames]
@@ -667,12 +668,13 @@ data HsExpr id
-- These constructors only appear temporarily in the parser.
-- The renamer translates them into the Right Thing.
+ -- AZ: TODO: Needs to be embellished too, for backquotes
| EWildPat -- wildcard
-- | - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnAt'
-- For details on above see note [Api annotations] in ApiAnnotation
- | EAsPat (Located id) -- as pattern
+ | EAsPat (LEmbellished id) -- as pattern
(LHsExpr id)
-- | - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnRarrow'
@@ -2242,7 +2244,7 @@ data HsBracket id = ExpBr (LHsExpr id) -- [| expr |]
| DecBrL [LHsDecl id] -- [d| decls |]; result of parser
| DecBrG (HsGroup id) -- [d| decls |]; result of renamer
| TypBr (LHsType id) -- [t| type |]
- | VarBr Bool id -- True: 'x, False: ''T
+ | VarBr Bool (LEmbellished id) -- True: 'x, False: ''T
-- (The Bool flag is used only in pprHsBracket)
| TExpBr (LHsExpr id) -- [|| expr ||]
deriving instance (DataId id) => Data (HsBracket id)
@@ -2261,9 +2263,9 @@ pprHsBracket (PatBr p) = thBrackets (char 'p') (ppr p)
pprHsBracket (DecBrG gp) = thBrackets (char 'd') (ppr gp)
pprHsBracket (DecBrL ds) = thBrackets (char 'd') (vcat (map ppr ds))
pprHsBracket (TypBr t) = thBrackets (char 't') (ppr t)
-pprHsBracket (VarBr True n)
+pprHsBracket (VarBr True (L _ n))
= char '\'' <> pprPrefixOcc n
-pprHsBracket (VarBr False n)
+pprHsBracket (VarBr False (L _ n))
= text "''" <> pprPrefixOcc n
pprHsBracket (TExpBr e) = thTyBrackets (ppr e)