summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/GHC/Parser.y6
-rw-r--r--testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs1
-rw-r--r--testsuite/tests/ghc-api/exactprint/Test20239.stderr19
-rw-r--r--testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.hs8
-rw-r--r--testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr134
-rw-r--r--testsuite/tests/ghc-api/exactprint/all.T1
-rw-r--r--testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr20
-rw-r--r--testsuite/tests/parser/should_compile/T20718.stderr34
-rw-r--r--testsuite/tests/printer/Test20297.stdout18
9 files changed, 192 insertions, 49 deletions
diff --git a/compiler/GHC/Parser.y b/compiler/GHC/Parser.y
index a64ee3f07e..c56fae7b29 100644
--- a/compiler/GHC/Parser.y
+++ b/compiler/GHC/Parser.y
@@ -1076,8 +1076,10 @@ qcname :: { LocatedN RdrName } -- Variable or type constructor
-- One or more semicolons
semis1 :: { Located [TrailingAnn] }
-semis1 : semis1 ';' { sLL $1 $> $ if isZeroWidthSpan (gl $2) then (unLoc $1) else (AddSemiAnn (glAA $2) : (unLoc $1)) }
- | ';' { sL1 $1 $ msemi $1 }
+semis1 : semis1 ';' { if isZeroWidthSpan (gl $2) then (sL1 $1 $ unLoc $1) else (sLL $1 $> $ AddSemiAnn (glAA $2) : (unLoc $1)) }
+ | ';' { case msemi $1 of
+ [] -> noLoc []
+ ms -> sL1 $1 $ ms }
-- Zero or more semicolons
semis :: { [TrailingAnn] }
diff --git a/testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs b/testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs
index 9a36673062..e7c71dbd08 100644
--- a/testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs
+++ b/testsuite/tests/ghc-api/exactprint/RmDecl4.expected.hs
@@ -7,5 +7,4 @@ ff y = y + zz + xx
zz = 1
-
-- EOF
diff --git a/testsuite/tests/ghc-api/exactprint/Test20239.stderr b/testsuite/tests/ghc-api/exactprint/Test20239.stderr
index 8bfb5085ce..b89a29fbf2 100644
--- a/testsuite/tests/ghc-api/exactprint/Test20239.stderr
+++ b/testsuite/tests/ghc-api/exactprint/Test20239.stderr
@@ -24,7 +24,14 @@
{ Test20239.hs:7:34-63 })))
(EpaCommentsBalanced
[]
- []))
+ [(L
+ (Anchor
+ { Test20239.hs:7:34-63 }
+ (UnchangedAnchor))
+ (EpaComment
+ (EpaLineComment
+ "-- ^ Run any arbitrary IO code")
+ { Test20239.hs:6:86 }))]))
(VirtualBraces
(1))
(Nothing)
@@ -50,15 +57,7 @@
(EpaComment
(EpaLineComment
"-- | Leading Haddock Comment")
- { Test20239.hs:1:18-22 }))
- ,(L
- (Anchor
- { Test20239.hs:7:34-63 }
- (UnchangedAnchor))
- (EpaComment
- (EpaLineComment
- "-- ^ Run any arbitrary IO code")
- { Test20239.hs:6:86 }))])) { Test20239.hs:(4,1)-(6,86) })
+ { Test20239.hs:1:18-22 }))])) { Test20239.hs:(4,1)-(6,86) })
(InstD
(NoExtField)
(DataFamInstD
diff --git a/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.hs b/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.hs
new file mode 100644
index 0000000000..6c3de63737
--- /dev/null
+++ b/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.hs
@@ -0,0 +1,8 @@
+module ZeroWidthSemi where
+
+-- leading comments
+
+-- Function comment
+a = 0
+
+-- Trailing comment, should be in HsModule extension point
diff --git a/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr b/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr
new file mode 100644
index 0000000000..13937cd36b
--- /dev/null
+++ b/testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr
@@ -0,0 +1,134 @@
+
+==================== Parser AST ====================
+
+(L
+ { ZeroWidthSemi.hs:1:1 }
+ (HsModule
+ (XModulePs
+ (EpAnn
+ (Anchor
+ { ZeroWidthSemi.hs:1:1 }
+ (UnchangedAnchor))
+ (AnnsModule
+ [(AddEpAnn AnnModule (EpaSpan { ZeroWidthSemi.hs:1:1-6 }))
+ ,(AddEpAnn AnnWhere (EpaSpan { ZeroWidthSemi.hs:1:22-26 }))]
+ (AnnList
+ (Nothing)
+ (Nothing)
+ (Nothing)
+ []
+ [])
+ (Just
+ ((,)
+ { ZeroWidthSemi.hs:9:1 }
+ { ZeroWidthSemi.hs:8:1-58 })))
+ (EpaCommentsBalanced
+ [(L
+ (Anchor
+ { ZeroWidthSemi.hs:3:1-19 }
+ (UnchangedAnchor))
+ (EpaComment
+ (EpaLineComment
+ "-- leading comments")
+ { ZeroWidthSemi.hs:1:22-26 }))]
+ [(L
+ (Anchor
+ { ZeroWidthSemi.hs:8:1-58 }
+ (UnchangedAnchor))
+ (EpaComment
+ (EpaLineComment
+ "-- Trailing comment, should be in HsModule extension point")
+ { ZeroWidthSemi.hs:6:5 }))]))
+ (VirtualBraces
+ (1))
+ (Nothing)
+ (Nothing))
+ (Just
+ (L
+ (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:1:8-20 })
+ {ModuleName: ZeroWidthSemi}))
+ (Nothing)
+ []
+ [(L
+ (SrcSpanAnn (EpAnn
+ (Anchor
+ { ZeroWidthSemi.hs:6:1-5 }
+ (UnchangedAnchor))
+ (AnnListItem
+ [])
+ (EpaComments
+ [(L
+ (Anchor
+ { ZeroWidthSemi.hs:5:1-19 }
+ (UnchangedAnchor))
+ (EpaComment
+ (EpaLineComment
+ "-- Function comment")
+ { ZeroWidthSemi.hs:3:1-19 }))])) { ZeroWidthSemi.hs:6:1-5 })
+ (ValD
+ (NoExtField)
+ (FunBind
+ (NoExtField)
+ (L
+ (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:6:1 })
+ (Unqual
+ {OccName: a}))
+ (MG
+ (FromSource)
+ (L
+ (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:6:1-5 })
+ [(L
+ (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:6:1-5 })
+ (Match
+ (EpAnn
+ (Anchor
+ { ZeroWidthSemi.hs:6:1-5 }
+ (UnchangedAnchor))
+ []
+ (EpaComments
+ []))
+ (FunRhs
+ (L
+ (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:6:1 })
+ (Unqual
+ {OccName: a}))
+ (Prefix)
+ (NoSrcStrict))
+ []
+ (GRHSs
+ (EpaComments
+ [])
+ [(L
+ (SrcSpanAnn
+ (EpAnnNotUsed)
+ { ZeroWidthSemi.hs:6:3-5 })
+ (GRHS
+ (EpAnn
+ (Anchor
+ { ZeroWidthSemi.hs:6:3-5 }
+ (UnchangedAnchor))
+ (GrhsAnn
+ (Nothing)
+ (AddEpAnn AnnEqual (EpaSpan { ZeroWidthSemi.hs:6:3 })))
+ (EpaComments
+ []))
+ []
+ (L
+ (SrcSpanAnn (EpAnnNotUsed) { ZeroWidthSemi.hs:6:5 })
+ (HsOverLit
+ (EpAnn
+ (Anchor
+ { ZeroWidthSemi.hs:6:5 }
+ (UnchangedAnchor))
+ (NoEpAnns)
+ (EpaComments
+ []))
+ (OverLit
+ (NoExtField)
+ (HsIntegral
+ (IL
+ (SourceText 0)
+ (False)
+ (0))))))))]
+ (EmptyLocalBinds
+ (NoExtField)))))])))))]))
diff --git a/testsuite/tests/ghc-api/exactprint/all.T b/testsuite/tests/ghc-api/exactprint/all.T
index 97d94b566c..825d57c339 100644
--- a/testsuite/tests/ghc-api/exactprint/all.T
+++ b/testsuite/tests/ghc-api/exactprint/all.T
@@ -37,3 +37,4 @@ test('RmTypeSig2', ignore_stderr, makefile_test, ['RmTypeSig2'])
test('AddHiding1', ignore_stderr, makefile_test, ['AddHiding1'])
test('AddHiding2', ignore_stderr, makefile_test, ['AddHiding2'])
test('Test20239', normal, compile_fail, ['-dsuppress-uniques -ddump-parsed-ast -dkeep-comments'])
+test('ZeroWidthSemi', normal, compile, ['-dsuppress-uniques -ddump-parsed-ast -dkeep-comments'])
diff --git a/testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr b/testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr
index 6050639d73..4eb1a179db 100644
--- a/testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr
+++ b/testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr
@@ -82,15 +82,7 @@
(EpaComment
(EpaLineComment
"-- comment 2 for foo")
- { DumpParsedAstComments.hs:9:1-20 }))
- ,(L
- (Anchor
- { DumpParsedAstComments.hs:15:1-20 }
- (UnchangedAnchor))
- (EpaComment
- (EpaLineComment
- "-- | Haddock comment")
- { DumpParsedAstComments.hs:13:3
+ { DumpParsedAstComments.hs:9:1-20
}))])) { DumpParsedAstComments.hs:(11,1)-(13,3) })
(ValD
(NoExtField)
@@ -219,7 +211,15 @@
(AnnListItem
[])
(EpaComments
- [])) { DumpParsedAstComments.hs:16:1-23 })
+ [(L
+ (Anchor
+ { DumpParsedAstComments.hs:15:1-20 }
+ (UnchangedAnchor))
+ (EpaComment
+ (EpaLineComment
+ "-- | Haddock comment")
+ { DumpParsedAstComments.hs:13:3
+ }))])) { DumpParsedAstComments.hs:16:1-23 })
(ValD
(NoExtField)
(FunBind
diff --git a/testsuite/tests/parser/should_compile/T20718.stderr b/testsuite/tests/parser/should_compile/T20718.stderr
index bd071a0227..16eeaa4e69 100644
--- a/testsuite/tests/parser/should_compile/T20718.stderr
+++ b/testsuite/tests/parser/should_compile/T20718.stderr
@@ -55,7 +55,22 @@
(EpaLineComment
"-- before 2")
{ T20718.hs:5:1-11 }))]
- []))
+ [(L
+ (Anchor
+ { T20718.hs:10:1-8 }
+ (UnchangedAnchor))
+ (EpaComment
+ (EpaLineComment
+ "-- end 1")
+ { T20718.hs:8:5 }))
+ ,(L
+ (Anchor
+ { T20718.hs:11:1-8 }
+ (UnchangedAnchor))
+ (EpaComment
+ (EpaLineComment
+ "-- end 2")
+ { T20718.hs:10:1-8 }))]))
(VirtualBraces
(1))
(Nothing)
@@ -74,22 +89,7 @@
(AnnListItem
[])
(EpaComments
- [(L
- (Anchor
- { T20718.hs:10:1-8 }
- (UnchangedAnchor))
- (EpaComment
- (EpaLineComment
- "-- end 1")
- { T20718.hs:8:5 }))
- ,(L
- (Anchor
- { T20718.hs:11:1-8 }
- (UnchangedAnchor))
- (EpaComment
- (EpaLineComment
- "-- end 2")
- { T20718.hs:10:1-8 }))])) { T20718.hs:8:1-5 })
+ [])) { T20718.hs:8:1-5 })
(ValD
(NoExtField)
(FunBind
diff --git a/testsuite/tests/printer/Test20297.stdout b/testsuite/tests/printer/Test20297.stdout
index df6f3347f9..180078c16a 100644
--- a/testsuite/tests/printer/Test20297.stdout
+++ b/testsuite/tests/printer/Test20297.stdout
@@ -50,14 +50,7 @@
(AnnListItem
[])
(EpaComments
- [(L
- (Anchor
- { Test20297.hs:7:9-19 }
- (UnchangedAnchor))
- (EpaComment
- (EpaLineComment
- "-- comment1")
- { Test20297.hs:7:3-7 }))])) { Test20297.hs:(5,1)-(7,7) })
+ [])) { Test20297.hs:(5,1)-(7,7) })
(ValD
(NoExtField)
(FunBind
@@ -150,7 +143,14 @@
(AnnListItem
[])
(EpaComments
- [])) { Test20297.hs:(9,1)-(11,26) })
+ [(L
+ (Anchor
+ { Test20297.hs:7:9-19 }
+ (UnchangedAnchor))
+ (EpaComment
+ (EpaLineComment
+ "-- comment1")
+ { Test20297.hs:7:3-7 }))])) { Test20297.hs:(9,1)-(11,26) })
(ValD
(NoExtField)
(FunBind