Skip to content

Incorrect tokens line number for files with '\r' newline. #1098

@KvanTTT

Description

@KvanTTT

I have the following grammar:

lexer grammar T;
ID: [a-z]+;
WS: [ \n] -> skip;

And the following input: "a" + newLine + "b" + newLine + "c"

  • If newLine is \r\n, I got this:
[@0,0:0='a',<1>,1:0]
[@1,3:3='b',<1>,2:0]
[@2,6:6='c',<1>,3:0]
[@3,7:6='<EOF>',<-1>,3:1]

newLine == \n:

[@0,0:0='a',<1>,1:0]
[@1,2:2='b',<1>,2:0]
[@2,4:4='c',<1>,3:0]
[@3,5:4='<EOF>',<-1>,3:1]

newLine == \r:

[@0,0:0='a',<1>,1:0]
[@1,2:2='b',<1>,1:2]
[@2,4:4='c',<1>,1:4]
[@3,5:4='<EOF>',<-1>,1:5]

In last case line numer for all tokens is 1 and it's wrong. I suggest to support '\r' newLine character. Another variants described at Wikipedia, but they are too rarely used. Moreover '\r' newline supported by most part of modern editors (IDEA, Visual Studio, Notepad++ etc.).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions