Commit 287e18d
committed
Python: Add parser support for template strings
- Extends the scanner with a new token kind representing the start of a
template string. This is used to distinguish template strings from
regular strings (because only a template string will start with a
`_template_string_start` external token).
- Cleans up the logic surrounding interpolations (and the method names)
so that format strings and template strings behave the same in this
case.
Finally, we add two new node types in the tree-sitter grammar:
- `template_string` behaves like format strings, but is a distinct type
(mainly so that an implicit concatenation between template strings and
regular strings becomes a syntax error).
- `concatenated_template_string` is the counterpart of
`concatenated_string`.
However, internally, the string parts of a template strings are just the
same `string_content` nodes that are used in regular format strings. We
will disambiguate these inside `tsg-python`.1 parent 8b89e15 commit 287e18d
2 files changed
+40
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
423 | 424 | | |
424 | 425 | | |
425 | 426 | | |
| 427 | + | |
| 428 | + | |
426 | 429 | | |
427 | 430 | | |
428 | 431 | | |
| |||
765 | 768 | | |
766 | 769 | | |
767 | 770 | | |
| 771 | + | |
| 772 | + | |
768 | 773 | | |
769 | 774 | | |
770 | 775 | | |
| |||
1099 | 1104 | | |
1100 | 1105 | | |
1101 | 1106 | | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
1102 | 1121 | | |
1103 | 1122 | | |
1104 | 1123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
39 | 49 | | |
40 | 50 | | |
41 | 51 | | |
| |||
59 | 69 | | |
60 | 70 | | |
61 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
62 | 76 | | |
63 | 77 | | |
64 | 78 | | |
| |||
154 | 168 | | |
155 | 169 | | |
156 | 170 | | |
157 | | - | |
| 171 | + | |
158 | 172 | | |
159 | 173 | | |
160 | 174 | | |
| |||
322 | 336 | | |
323 | 337 | | |
324 | 338 | | |
325 | | - | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
326 | 342 | | |
327 | 343 | | |
328 | 344 | | |
329 | 345 | | |
330 | 346 | | |
331 | 347 | | |
| 348 | + | |
| 349 | + | |
332 | 350 | | |
333 | 351 | | |
334 | 352 | | |
| |||
372 | 390 | | |
373 | 391 | | |
374 | 392 | | |
375 | | - | |
| 393 | + | |
376 | 394 | | |
377 | 395 | | |
378 | 396 | | |
| |||
0 commit comments