tree-sitter-python
tree-sitter-python copied to clipboard
Escaped Unicode string not parsed correctly
trafficstars
Consider
u = f'\N{GREEK CAPITAL LETTER DELTA}'
which is a ascii-only way to get the unicode-glyph with the name in between { and }.
Parse Tree:
expression_statement [0, 0] - [0, 37]
assignment [0, 0] - [0, 37]
left: identifier [0, 0] - [0, 1]
right: string [0, 4] - [0, 37]
interpolation [0, 8] - [0, 36]
ERROR [0, 9] - [0, 29]
identifier [0, 9] - [0, 14]
identifier [0, 15] - [0, 22]
identifier [0, 23] - [0, 29]
identifier [0, 30] - [0, 35]
Does it error without the "f" (making it not an f-string)?
No it does not; the issue report is very sloppily written, I'm sorry.
u = '\N{GREEK CAPITAL LETTER DELTA}'
Parse Tree:
expression_statement [0, 0] - [0, 36]
assignment [0, 0] - [0, 36]
left: identifier [0, 0] - [0, 1]
right: string [0, 4] - [0, 36]
However, there are many situations where one may want to combine f-strings with the unicode specification, for instance to get 0️⃣ ... 9️⃣, one may use
number_emojis = [f"{num}\N{COMBINING ENCLOSING KEYCAP}" for num in range(10)]
Parse Tree:
expression_statement [0, 0] - [0, 77]
assignment [0, 0] - [0, 77]
left: identifier [0, 0] - [0, 13]
right: list_comprehension [0, 16] - [0, 77]
body: string [0, 17] - [0, 55]
interpolation [0, 19] - [0, 24]
identifier [0, 20] - [0, 23]
interpolation [0, 26] - [0, 54]
identifier [0, 27] - [0, 36]
ERROR [0, 37] - [0, 53]
identifier [0, 37] - [0, 46]
identifier [0, 47] - [0, 53]
for_in_clause [0, 56] - [0, 76]
left: identifier [0, 60] - [0, 63]
right: call [0, 67] - [0, 76]
function: identifier [0, 67] - [0, 72]
arguments: argument_list [0, 72] - [0, 76]
integer [0, 73] - [0, 75]