Commit 63bee39
authored
Tweak macro name representation (#572)
The current representation for macro names is a bit peculiar. When
the parser encounters `@a`, it treats `@` as notation for the
macrocall and then `reset_node!`'s (which itself may be considered
a bit of a code smell) the `a` to a special MacroName
token kind that (when translated back to julia Expr) implicitly
adds back the `@`. Things get even more peculiar with `@var"a"`
where only the token inside the string macro gets reset.
One particular consequence of this is JuliaLang/julia#58885,
because our translation back to Expr does not check the RAW_STRING_FLAG
(whereas the translation for K"Identifier" does).
A second issue is that we currently parse `@A.b.c` and `A.b.@c` to the
same SyntaxTree (of course the green tree is different). We aren't
currently being super precise about the required invariants for syntax
trees, but in general it would be desirable for non-trivia notation
(like `@`) to be precisely recoverable from the tree, which is not
the case here. This is especially annoying because there are syntax
cases that are errors for one of these, but not the other (e.g.
`@A.b.$` is an error, but `A.B.@$` is allowed). Now, I think the wisdom
of some of those syntax choices can be debated, but that is the situation
we face.
So this PR tries to clean that all up a bit by:
- Replacing the terminal K"MacroName" by a non-terminal K"macro_name".
With this form, `@A.c` parses as `(macro_name (. A c))` while
`A.@c` parses as `(. A (macro_name c))`.
- (In particular the `@` notation is now always associated with the
macro_name).
- Emitting the dots in `@..` and `@...` as direct identifier tokens
rather than having to reset them back.
- Adjusting everything else accordingly.
Partially written by Claude Code, though it had some trouble with
the actual code changes.1 parent e02f29f commit 63bee39
File tree
9 files changed
+271
-253
lines changed- src
- integration
- julia
- test
9 files changed
+271
-253
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
250 | | - | |
251 | 249 | | |
252 | 250 | | |
253 | 251 | | |
| |||
296 | 294 | | |
297 | 295 | | |
298 | 296 | | |
299 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
300 | 322 | | |
301 | 323 | | |
302 | 324 | | |
| |||
312 | 334 | | |
313 | 335 | | |
314 | 336 | | |
| 337 | + | |
| 338 | + | |
315 | 339 | | |
316 | 340 | | |
317 | 341 | | |
| |||
331 | 355 | | |
332 | 356 | | |
333 | 357 | | |
334 | | - | |
| 358 | + | |
335 | 359 | | |
336 | 360 | | |
337 | 361 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | 197 | | |
207 | 198 | | |
208 | 199 | | |
| |||
1048 | 1039 | | |
1049 | 1040 | | |
1050 | 1041 | | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
1051 | 1046 | | |
1052 | 1047 | | |
1053 | 1048 | | |
| |||
1111 | 1106 | | |
1112 | 1107 | | |
1113 | 1108 | | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
1117 | | - | |
1118 | 1109 | | |
1119 | 1110 | | |
1120 | 1111 | | |
| |||
1201 | 1192 | | |
1202 | 1193 | | |
1203 | 1194 | | |
1204 | | - | |
1205 | 1195 | | |
1206 | 1196 | | |
1207 | 1197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | 433 | | |
440 | 434 | | |
441 | 435 | | |
| |||
0 commit comments