[ 
https://issues.apache.org/jira/browse/GROOVY-12435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18135379#comment-18135379
 ] 

ASF GitHub Bot commented on GROOVY-12435:
-----------------------------------------

eric-milles commented on PR #3070:
URL: https://github.com/apache/groovy/pull/3070#issuecomment-6531977529

   Was a fix within antlr4 considered?  Any concerns over the amount of code 
from antlr that must be duplicated in order to address this?  The optimization 
for consume within a recent version made this more difficult to fix.  I was 
able to repair on me.sunlan:antlr4:4.13.2.15 with a small consume override:
   
   ```java
       private static class PositionAdjustingLexerATNSimulator extends 
LexerATNSimulator {
           //...
           // add
           @Override
           public void consume(CharStream input) {
               if (input.LA(1) == '\r' && input.LA(2) != '\n') {
                   this.line += 1; this.charPositionInLine = -1;
               }
               super.consume(input);
           }
           // end
       }
   }
   ```




> carriage-return only line ending does not increment line number
> ---------------------------------------------------------------
>
>                 Key: GROOVY-12435
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12435
>             Project: Groovy
>          Issue Type: Bug
>          Components: parser-antlr4
>    Affects Versions: 3.0.25, 4.0.33, 5.1.3, 6.0.0
>            Reporter: Eric Milles
>            Assignee: Daniel Sun
>            Priority: Major
>         Attachments: LineEndings.groovy, image-2026-09-30-09-41-06-973.png
>
>
> [^LineEndings.groovy]I had a source file with mixed line endings that caused 
> a lot of trouble with the editor. I traced this back to the parser's handling 
> of line endings. It seems when a line ending is just a carriage-return (\r) 
> the line number is not incremented.
> !image-2026-09-30-09-41-06-973.png!
> In this example, the import and script statement have lines 2 and 6 
> respectively. They should be at lines 3 and 7 as can be seen by the line 
> numbering in the editor's gutter. The antlr2 parser handled this case 
> properly.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to