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

David (@knothed) gitlab at gitlab.haskell.org
Wed Oct 11 14:17:02 UTC 2023



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


Commits:
57b67319 by David Knothe at 2023-10-11T16:16:52+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,15 @@ 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/57b67319bc750d2b8fd31ad95ae90a20ba88947d

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/57b67319bc750d2b8fd31ad95ae90a20ba88947d
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/20231011/1a0d47a0/attachment-0001.html>


More information about the ghc-commits mailing list