I think it could indeed be used to create a formatter. Say you wanted to write a rule where:
op == /\ A
should be formatted as:
this would be quite easy; you would write a query for all operator definitions with conjunction lists as a top-level _expression_, so:
(operator_definition (def_eq) @eq definition: (conj_list) @list)
where the @eq capture gets the == node, and the @list capture gets the conjunction list node. Then you check whether the two nodes are on the same line (easy, info readily available in node object) and if so you insert a newline then dedent all lines included within the conjunction list node. This should preserve vertical alignment for any nested conjunction/disjunction lists.
On Tuesday, September 14, 2021 at 2:49:23 PM UTC-4 Alexander Niederbühl wrote:
I think this would be very useful, I find the ASCII representation a bit verbose and distracting. I know of several people who feel the same, e.g. https://matklad.github.io/2020/11/01/notes-on-paxos.html as another data point. Currently I'm using a VSCode extension together with FiraCode as workaround.
A bit unrelated but since in TLA+ there are many ways to write the same thing like \cup, \union or /= , # and different ways to format the code in terms of line breaks etc. I wish there would be a tool to get a canonically formatted Unicode representation which ideally TLC would be able to check. Do you think the treesitter grammar could be utilized to build a code formatter similar to prettier