Skip to content

Parsing error for unicode escape in char/string literals #209

Open
@theawless

Description

@theawless
class Scratch {
    public static void main(String[] args) {
        char c = '\u005c'';
        String s = "\u005c"";
        System.out.println(c);
        System.out.println(s);
    }
}

This is a working java code snippet. The output is

'
"

But tree-sitter-java doesn't accept these:

'\u005c''
program [0, 0] - [1, 0]
  ERROR [0, 0] - [0, 9]
    character_literal [0, 0] - [0, 8]
    ERROR [0, 8] - [0, 9]
"\u005c""
program [0, 0] - [1, 0]
  ERROR [0, 0] - [0, 9]
    string_literal [0, 0] - [0, 8]
      " [0, 0] - [0, 1]
      escape_sequence [0, 1] - [0, 7]
      " [0, 7] - [0, 8]
    " [0, 8] - [0, 9]

I read through https://docs.oracle.com/javase/specs/jls/se23/html/jls-3.html#jls-3.2 and I think this is what's happening:

Original: '\u005c''
After Unicode escape processing: '\''
Final interpretation: a char literal containing a single quote character

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