[Git][ghc/ghc][wip/or-pats] refactor

David (@knothed) gitlab at gitlab.haskell.org
Sat Oct 14 09:37:24 UTC 2023



David pushed to branch wip/or-pats at Glasgow Haskell Compiler / GHC


Commits:
436f0454 by David Knothe at 2023-10-14T11:37:10+02:00
refactor

- - - - -


1 changed file:

- compiler/GHC/Parser.y


Changes:

=====================================
compiler/GHC/Parser.y
=====================================
@@ -3113,11 +3113,9 @@ texp :: { ECP }
                              mkHsViewPatPV (comb2 $1 $>) $1 $3 [mu AnnRarrow $2] }
 
 orpats :: { [LPat GhcPs] }
---        : texp                  {% do
         : exp %shift         {% do
                                  { pat1 <- (checkPattern <=< runPV) (unECP $1)
                                  ; return [pat1] }}
---        | texp '|' orpats      {% do
         | exp ';' orpats     {% do
                                  { pat1 <- (checkPattern <=< runPV) (unECP $1)
                                  ; pat2 <- addTrailingSemiA pat1 (getLoc $2)
@@ -3388,14 +3386,14 @@ pat_syn_pat :: { LPat GhcPs }
 pat_syn_pat :  exp          {% (checkPattern <=< runPV) (unECP $1) }
 
 pat     :: { LPat GhcPs }
-pat     :  pat_syn_pat      { $1 }
-        |  pat ';' orpats   {%
-                     do { let srcSpan = comb2 (getLocA $1) (getLocA $ last $3)
-                        ; cs <- getCommentsFor srcSpan
-                        ; pat1 <- addTrailingSemiA $1 (getLoc $2)
-                        ; let orpat = sL (noAnnSrcSpan srcSpan) $ OrPat (EpAnn (spanAsAnchor srcSpan) [] cs) (pat1:$3)
-                        ; _ <- hintOrPats orpat
-                        ; return $ orpat }}
+pat     :  orpats      {% case $1 of
+                            [pat] -> return pat
+                            _ -> do { let srcSpan = getLocA $1
+                                    ; cs <- getCommentsFor srcSpan
+                                    ; let orpat = sL (noAnnSrcSpan srcSpan) $ OrPat (EpAnn (spanAsAnchor srcSpan) [] cs) $1
+                                    ; _ <- hintOrPats orpat
+                                    ; return orpat }}
+
 
 -- 'pats1' does the same thing as 'pat', but returns it as a singleton
 -- list so that it can be used with a parameterized production rule



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/436f0454705c93ea0324056d69267a880029cf67
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/20231014/84793814/attachment-0001.html>


More information about the ghc-commits mailing list