OILS / data_lang / pretty.asdl View on Github | oilshell.org

29 lines, 13 significant
1# Pretty printing "documents". A `doc` encodes printing instructions, including
2# choices between multiple possible layouts.
3
4module pretty
5{
6 # A pretty printing document, together with a measure of its size.
7 MeasuredDoc = (doc doc, Measure measure)
8
9 # The "size" of a document:
10 # - `flat` gives the width of the doc if printed flat (on one line).
11 # - `nonflat` gives the width until the doc's first possible newline,
12 # or -1 if no layout of the doc contains a newline.
13 Measure = (int flat, int nonflat)
14
15 # A pretty printing "document", which encodes a set of possible layouts.
16 # The pretty printer will pick the "best" layout from among this set.
17 # See the docs on the constructors in `pretty.py` for details.
18 doc =
19 Break(str string)
20 | Text(str string)
21 | Indent(int indent, MeasuredDoc mdoc)
22 | Concat(List[MeasuredDoc] mdocs)
23 | Group(MeasuredDoc mdoc)
24 | IfFlat(MeasuredDoc flat_mdoc, MeasuredDoc nonflat_mdoc)
25
26 # Used internally while pretty printing.
27 # See comments in PrettyPrinter._PrintDoc.
28 DocFragment = (MeasuredDoc mdoc, int indent, bool is_flat, Measure measure)
29}