New Issue: dyno: expose a universal 'pretty print document' representation

24716, "DanilaFe", "dyno: expose a universal 'pretty print document' representation", "2024-03-29T17:21:22Z"

A variety of Dyno tooling uses some form of pretty printing. This includes:

  • The query system's own stringify functions
  • Dyno detailed errors
  • chpldoc signatures etc. for Sphinx output
  • chpl-language-server node printing to support hover info
  • more

However, currently, each of these tools implements a different approach for pretty-printing, some of which are similar to each other. In particular, The stringify functions, chpldoc, and CLS all use some sort of AST walking to generate output. However, each of them has a slightly different version of this AST traversal, and therefore its own implementation. This leads to the need for duplicate logic for things like precedence, spacing, and more.

My question is: can Dyno expose a universal "pretty printed AST" document format? Perhaps something like the Document type described in Philip Wadler's famous paper. Tools such as chpldoc can then ask for this document to be laid out in whatever way they want. The document might include additional information to help stop the layout early as some tools require.

A universal representation can save AST traversal logic, ensure consistency across tools, and make it easier to develop new tooling that might rely on pretty printing.

As our support for including tokens and comment locations improves (we hope!), it'll only need to improve where we produce the Document, and other tools will immediately benefit.