Brand_Visser Box Meta model - mn-mikke/Model-driven-Pretty-Printer-for-Xtext-Framework GitHub Wiki

Brand-Visser Box Meta-model

The box meta-model was published in the Generation of Formatters for Context Free Languages paper written by Mark van den Brand and Eelco Visser. The paper deals with the theory of generic pretty printers. The purpose of pretty printers and theirs relationship with a grammar is formally explained in the paper. The paper also includes considerations on the division of generic pretty printers into front-ends and back-ends with use of the box representation as an intermediate language.

The paper defines the same syntax for textual usages of operators as was introduced with the Stratego/XT box meta-model and also there are some same operators with the same corresponding parameters. The operators were mentioned that defines relative positions between boxes in previous box meta-models. This box meta-model brings another kind of operators, where operators do not define positions but determine what font and font parameters will be associated with the text of input boxes. The meta-model contains the following list of positional and non-positional operators.

Positional Operators

  • H - The operator aligns inner boxes horizontally exactly like the H operator from the Stratego/XT box meta-model. The hs parameter also belongs to the operator with the same functionality.

Operator H

  • V - The operator aligns inner boxes vertically exactly like the V operator from the Stratego/XT box meta-model with an exception that the operator does not indent the second and other boxes against the first. The parameter vs belongs to the operator with the same functionality.

Operator V

  • HV - The operator aligns boxes as follows. The result formatting depends on whether the total length of boxes including horizontal spacing exceeds the maximal length of line, which is fixed. When the length of all boxes including horizontal spacing is smaller than the maximum length of line, then the boxes are aligned horizontally with spacing defined in the hs parameter. Otherwise, the first line is filled as much as possible and the rest of the boxes is filled into the second line applying the same rule as for the first line. Two consecutive lines are separated by blank lines, whose count is defined in the vs parameter.

Operator HV

  • HOV - The operator behaves like the operator H when the total length of boxes including horizontal spacing does not exceed the maximal line length. Otherwise, the operator behaves like the V operator. The parameters of the operator have the same significance as with the previous operators.
  • I - The parameter increases the indentation of inner boxes by the value defined in the is parameter. The indentation is applied when the box is vertically aligned against some other boxes. In other words, the operator has its effect when it is contained in another operator with vertical alignment as an inner box.

Operator I

  • WD - The operator translates inner boxes into an empty boxes with dimensions equal to those of inner boxes.

Operator WD

  • A - The operator aligns inner boxes into a table exactly like the A operator from the Stratego/XT box meta-model. The operator also exploits the operator R in order to define rows of the table and it is also tied with the parameters hs, vs and is, which perform the same function like in the Stratego/XT box meta-model. This version of the operators A additionally provides possibility to align columns to left, center or right by signs l, c, r enclosed in parentheses. The parentheses should enclose the same number of signs as is the number of columns. In other words, each column should have a sign expressing its alignment.

Operator A

  • R - This operator serves as subsidiary operator for the A operator. The operator R defines rows of a table exactly like in the Stratego/XT box meta-model.

Non-positional Operators

  • F - The operator is dedicated to specify a font configuration. and associate it with the text of inner boxes. The font configuration can be defined by the operator fn specifying a font name, fm specifying a font family, se specifying font series, sh specifying a font shape, sz specifying a font size and cl specifying a font color.
  • KW - The operator associates a font indicating keywords with the text of inner boxes.
  • VAR - The operator associates a font indicating variables with the text of inner boxes.
  • NUM - The operator associates a font indicating numbers with the text of inner boxes.
  • MATH - The operator associates a font indicating mathematical symbols with the text of inner boxes.
  • COMM - The operator associates a font indicating comments with the text of inner boxes.
  • ESC - The operator represents an escape mechanism to obtain special symbols in the formatted text.