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

44 lines, 15 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 # Leaf Value optimization
16 # This affects:
17 # the GC mask for any struct that contains it
18 # C++ uses parent.measure instead of parent->measure
19 #Measure_v = (int flat, int nonflat)
20
21 List_Measured < List[MeasuredDoc]
22
23 # A pretty printing "document", which encodes a set of possible layouts.
24 # The pretty printer will pick the "best" layout from among this set.
25 # See the docs on the constructors in `pretty.py` for details.
26 doc =
27 Break(str string)
28 | Text(str string)
29 | Indent(int indent, MeasuredDoc mdoc)
30 | Group %MeasuredDoc
31 | Flat(MeasuredDoc mdoc)
32 | IfFlat(MeasuredDoc flat_mdoc, MeasuredDoc nonflat_mdoc)
33 | Concat %List_Measured
34
35 # Optimizing allocations
36 # - Concat can be a List subtype
37 # - One of Break or Text can be %Str, when we add it
38 # - All these objects are immutable, so there can be a lot of sharing / hash consing, etc.
39 # - especially for ( : , ) '' etc. and ANSI styles
40
41 # Used internally while pretty printing.
42 # See comments in PrettyPrinter._PrintDoc.
43 DocFragment = (MeasuredDoc mdoc, int indent, bool is_flat, Measure measure)
44}