Skip to content

Carriage return is not treated as newline #1890

@therootusr

Description

@therootusr

When files having '\r' as newlines are parsed, the line numbers and the character positions in line do not correctly reflect the situation. For instance:

Grammar:

grammar Hello;            // Define a grammar called Hello
r  : 'hello' ID ;         // match keyword hello followed by an identifier
ID : [a-z]+ ;             // match lower-case identifiers
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines, \r (Windows) 

Input file: input.txt

Output:

 grun Hello r -tokens input.txt
 [@0,0:4='hello',<'hello'>,1:0]
 [@1,7:11='parrt',<ID>,1:7]
 [@2,12:11='<EOF>',<EOF>,1:12]

2nd and 3rd token don't lie on the 1st line. The parser is failing to recognize CR as newline.

Seems to relate to this part of the code.

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