tweag / topiary

https://topiary.tweag.io/
MIT License
511 stars 17 forks source link

Named rules #681

Open Xophmeister opened 4 months ago

Xophmeister commented 4 months ago

Is your feature request related to a problem? Please describe. When debugging the formatting queries, it is very difficult to understand which rules are being applied to some subtree. If rules could be given names, which are spewed out in the debug output, that should make things a lot easier.

Describe the solution you'd like Perhaps using predicates, something like:

(
   (#name! "space_between_things")

   (some_node)
   .
   (some_sibling) @prepend_space
)

Using names should be encouraged, but not mandatory. If no name is given for a rule, then one could be generated (e.g., queries/my-language.scm:L20-25).

Additional context Given names must be unique and query parsing should probably fail when this isn't true.

Xophmeister commented 4 months ago

In the debug output there are pattern_index values when there's a match. Presumably these are 0-based in the order in which they appear in the query file.