Stratego Box

Stratego -- Strategies for Program Transformation
StrategoBox is a syntax defintion for using ConcreteSyntax for the BoxLanguage inside the StrategoLanguage. With StrategoBox you can write powerful PrettyPrinters that target the BoxLanguage. You can use this approach when you need more control over pretty-printing than provided by PrettyPrintTables .

To use the StrategoBox language you have to declare in a .meta file that you want to use the StrategoBox grammar:

  Meta([Syntax("Stratego-Box")])

In your Makefile.am you also have to include the directory $(GPP)/share/sdf/gpp in STRINCLUDES.

This is an example pretty print rule in Stratego. It rewrites an empty XML element to a Box.

  simple-element-to-box:
    EmptyElement(qname, []) -> box |[ H hs=0 [KW["<"] ~qname KW["/>"]] ]|

In general using StrategoBox is more verbose than using PrettyPrintTables. StrategoBox becomes interesting when you want different pretty-printing, depending on the structure of a term. The following rules rewrite an start tag in XML to Boxes. If there are no attributes in the element we can pretty print the tag more attractive by leaving out the space between the element name and the attributes.

  open-tag-to-box:
    (qname, []) -> box |[ H hs=0 [KW["<"] ~qname KW[">"]] ]|
      
  open-tag-to-box:
    (qname, atts) -> box |[ H hs=0 [KW["<"] H hs=1 [ ~qname ~*atts ] KW[">"]] ]|
       where <gt> (<length> atts, 0)