diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2021-05-09 15:19:45 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-05-11 05:36:02 -0400 |
commit | 32367cac4e586fb5aedaa021b257388392d976c4 (patch) | |
tree | 059b555f27488b9d80bcd2fb566bc1d8969f7579 /compiler/GHC/Parser.y | |
parent | 087ac4ebee39bacd90529cab0e88af85a903448b (diff) | |
download | haskell-32367cac4e586fb5aedaa021b257388392d976c4.tar.gz |
EPA: Use custom AnnsIf structure for HsIf and HsCmdIf
This clearly identifies the presence and location of optional
semicolons in an if statement.
Closes #19813
Diffstat (limited to 'compiler/GHC/Parser.y')
-rw-r--r-- | compiler/GHC/Parser.y | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/compiler/GHC/Parser.y b/compiler/GHC/Parser.y index 483fb06e97..f9a4d10a4d 100644 --- a/compiler/GHC/Parser.y +++ b/compiler/GHC/Parser.y @@ -2679,9 +2679,9 @@ exp10 :: { ECP } -- See Note [%shift: exp10 -> fexp] | fexp %shift { $1 } -optSemi :: { ([Located Token],Bool) } - : ';' { ([$1],True) } - | {- empty -} { ([],False) } +optSemi :: { (Maybe EpaLocation,Bool) } + : ';' { (msemim $1,True) } + | {- empty -} { (Nothing,False) } {- Note [Pragmas and operator fixity] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -2801,10 +2801,12 @@ aexp :: { ECP } unECP $5 >>= \ $5 -> unECP $8 >>= \ $8 -> mkHsIfPV (comb2A $1 $>) $2 (snd $3) $5 (snd $6) $8 - (mj AnnIf $1:mj AnnThen $4 - :mj AnnElse $7 - :(concatMap (\l -> mz AnnSemi l) (fst $3)) - ++(concatMap (\l -> mz AnnSemi l) (fst $6))) } + (AnnsIf + { aiIf = glAA $1 + , aiThen = glAA $4 + , aiElse = glAA $7 + , aiThenSemi = fst $3 + , aiElseSemi = fst $6})} | 'if' ifgdpats {% hintMultiWayIf (getLoc $1) >>= \_ -> fmap ecpFromExp $ @@ -4161,6 +4163,9 @@ mz a l = if isZeroWidthSpan (gl l) then [] else [AddEpAnn a (EpaSpan $ rs $ gl l msemi :: Located e -> [TrailingAnn] msemi l = if isZeroWidthSpan (gl l) then [] else [AddSemiAnn (EpaSpan $ rs $ gl l)] +msemim :: Located e -> Maybe EpaLocation +msemim l = if isZeroWidthSpan (gl l) then Nothing else Just (EpaSpan $ rs $ gl l) + -- |Construct an AddEpAnn from the annotation keyword and the Located Token. If -- the token has a unicode equivalent and this has been used, provide the -- unicode variant of the annotation. |