tree-sitter-java icon indicating copy to clipboard operation
tree-sitter-java copied to clipboard

Parsing error for unicode escape in char/string literals

Open theawless opened this issue 7 months ago • 0 comments

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

theawless avatar Jun 11 '25 03:06 theawless