[Git][ghc/ghc][master] Api Annotations: Introduce AnnPercent for HsExplicitMult

Marge Bot gitlab at gitlab.haskell.org
Tue Oct 27 18:04:33 UTC 2020



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
e3fdd419 by Alan Zimmerman at 2020-10-27T14:04:26-04:00
Api Annotations: Introduce AnnPercent for HsExplicitMult

For the case

  foo :: a %p -> b

The location of the '%' is captured, separate from the 'p'

- - - - -


3 changed files:

- compiler/GHC/Parser.y
- compiler/GHC/Parser/Annotation.hs
- compiler/GHC/Parser/PostProcess.hs


Changes:

=====================================
compiler/GHC/Parser.y
=====================================
@@ -2056,17 +2056,18 @@ type :: { LHsType GhcPs }
                                               [mu AnnRarrow $2] }
 
         | btype mult '->' ctype        {% hintLinear (getLoc $2)
-                                       >> ams $1 [mj AnnMult $2,mu AnnRarrow $3] -- See Note [GADT decl discards annotations]
-                                       >> ams (sLL $1 $> $ HsFunTy noExtField ((unLoc $2) (toUnicode $3)) $1 $4)
-                                              [mj AnnMult $2,mu AnnRarrow $3] }
+                                       >> let (arr, ann) = (unLoc $2) (toUnicode $3)
+                                          in (ams $1 [ann,mu AnnRarrow $3] -- See Note [GADT decl discards annotations]
+                                             >> ams (sLL $1 $> $ HsFunTy noExtField arr $1 $4)
+                                                  [ann,mu AnnRarrow $3]) }
 
         | btype '->.' ctype            {% hintLinear (getLoc $2)
                                        >> ams $1 [mu AnnLollyU $2] -- See Note [GADT decl discards annotations]
                                        >> ams (sLL $1 $> $ HsFunTy noExtField (HsLinearArrow UnicodeSyntax) $1 $3)
                                               [mu AnnLollyU $2] }
 
-mult :: { Located (IsUnicodeSyntax -> HsArrow GhcPs) }
-        : PREFIX_PERCENT atype          { sLL $1 $> (\u -> mkMultTy u $2) }
+mult :: { Located (IsUnicodeSyntax -> (HsArrow GhcPs, AddAnn)) }
+        : PREFIX_PERCENT atype          { sLL $1 $> (\u -> mkMultTy u $1 $2) }
 
 btype :: { LHsType GhcPs }
         : infixtype                     {% runPV $1 }


=====================================
compiler/GHC/Parser/Annotation.hs
=====================================
@@ -301,7 +301,7 @@ data AnnKeywordId
     | AnnMdo
     | AnnMinus -- ^ '-'
     | AnnModule
-    | AnnMult -- ^ '%1'
+    | AnnPercentOne -- ^ '%1' -- for HsLinearArrow
     | AnnNewtype
     | AnnName -- ^ where a name loses its location in the AST, this carries it
     | AnnOf
@@ -318,6 +318,7 @@ data AnnKeywordId
     | AnnDollarDollar    -- ^ prefix '$$'  -- TemplateHaskell
     | AnnPackageName
     | AnnPattern
+    | AnnPercent -- ^ '%' -- for HsExplicitMult
     | AnnProc
     | AnnQualified
     | AnnRarrow -- ^ '->'


=====================================
compiler/GHC/Parser/PostProcess.hs
=====================================
@@ -2617,9 +2617,10 @@ mkLHsOpTy x op y =
   let loc = getLoc x `combineSrcSpans` getLoc op `combineSrcSpans` getLoc y
   in L loc (mkHsOpTy x op y)
 
-mkMultTy :: IsUnicodeSyntax -> LHsType GhcPs -> HsArrow GhcPs
-mkMultTy u (L _ (HsTyLit _ (HsNumTy _ 1))) = HsLinearArrow u
-mkMultTy u t = HsExplicitMult u t
+mkMultTy :: IsUnicodeSyntax -> Located Token -> LHsType GhcPs -> (HsArrow GhcPs, AddAnn)
+mkMultTy u tok t@(L _ (HsTyLit _ (HsNumTy _ 1)))
+  = (HsLinearArrow u, AddAnn AnnPercentOne (combineLocs tok t))
+mkMultTy u tok t = (HsExplicitMult u t, AddAnn AnnPercent (getLoc tok))
 
 -----------------------------------------------------------------------------
 -- Token symbols



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e3fdd4197cd9def4af40acb3753843e3e9a74d7e

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e3fdd4197cd9def4af40acb3753843e3e9a74d7e
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20201027/620af8fe/attachment-0001.html>


More information about the ghc-commits mailing list