Pius Arhanbhunde
Pius Arhanbhunde

Reputation: 193

Automated generation of pretty-printer in Rascal

Can RascalMPL automatically generate pretty printer for a language? if not, what is the feasibility of this functionality within RascalMPL?

Upvotes: 1

Views: 67

Answers (1)

Jurgen Vinju
Jurgen Vinju

Reputation: 6696

We have a number of ways to generate or construct pretty printers. Each with different ins and outs.

  1. Write a recursive function with overloaded alternatives for every abstract or concrete syntax rule and use a string template on the right hand side. Use for-templates for lists, recursion for child nodes.
  • String templates have auto-indentation for interpolated (recursive) variables.
  1. The same, but map to the Box language for declarative two dimensional text layout.
  • Box is a generalization of string templates that solves layout constraints in a similar way that CSS does paragraph layout and box layout. It can be found in the standard library.
  1. Number 1. can be learned from a corpus of example syntax trees. The clair library (see packages on rascal-mpl.org) contains the code for this prototype.
  • This works only on well-behaved ASTs, where the order of children is preserved correctly, for example.
  1. Number 2 could also be learned but we should make a clone of 3. for that.
  2. We are working on a codebuff clone but it has been a while we could find time for it. If you are interested to help out, please don't hesitate.

Upvotes: 0

Related Questions