diff --git a/pmd-lua/src/main/antlr4/net/sourceforge/pmd/lang/lua/antlr4/Lua.g4 b/pmd-lua/src/main/antlr4/net/sourceforge/pmd/lang/lua/antlr4/Lua.g4 index 2c2603c0a2..fc94fa1b50 100644 --- a/pmd-lua/src/main/antlr4/net/sourceforge/pmd/lang/lua/antlr4/Lua.g4 +++ b/pmd-lua/src/main/antlr4/net/sourceforge/pmd/lang/lua/antlr4/Lua.g4 @@ -469,11 +469,11 @@ CLOSE_PARENS ; NL - : '\r\n' | '\r' | '\n' - | '\u0085' // ' - | '\u2028' //'' - | '\u2029' //'' - ; + : '\r\n' | '\r' | '\n' + | '\u0085' // ' + | '\u2028' //'' + | '\u2029' //'' + ; COMMA : ',' @@ -525,6 +525,11 @@ HexDigit : [0-9a-fA-F] ; +fragment +StartingSingleCommentLineInputCharacter + : ~[[\r\n\u0085\u2028\u2029] + ; + fragment SingleLineInputCharacter : ~[\r\n\u0085\u2028\u2029] @@ -535,7 +540,7 @@ COMMENT ; LINE_COMMENT - : '--' SingleLineInputCharacter* -> channel(HIDDEN) + : '--' (NL | StartingSingleCommentLineInputCharacter SingleLineInputCharacter*) -> channel(HIDDEN) ; WS diff --git a/pmd-lua/src/test/java/net/sourceforge/pmd/cpd/LuaTokenizerTest.java b/pmd-lua/src/test/java/net/sourceforge/pmd/cpd/LuaTokenizerTest.java index 83b39442a1..fb77931286 100644 --- a/pmd-lua/src/test/java/net/sourceforge/pmd/cpd/LuaTokenizerTest.java +++ b/pmd-lua/src/test/java/net/sourceforge/pmd/cpd/LuaTokenizerTest.java @@ -44,4 +44,9 @@ public class LuaTokenizerTest extends CpdTextComparisonTest { public void testRegression() { doTest("luauTypes"); } + + @Test + public void testComment() { + doTest("comment"); + } }