Documentation

Init.Data.Format.Basic

Determines how groups should have linebreaks inserted when the text would overfill its remaining space.

Instances For
    inductive Std.Format :

    A string with pretty-printing information for rendering in a column-width-aware way.

    The pretty-printing algorithm is based on Wadler's paper A Prettier Printer.

    • nil : Format

      The empty format.

    • line : Format

      A position where a newline may be inserted if the current group does not fit within the allotted column width.

    • align (force : Bool) : Format

      align tells the formatter to pad with spaces to the current indent, or else add a newline if we are already at or past the indent. For example:

      nest 2 <| "." ++ align ++ "a" ++ line ++ "b"
      

      results in:

      . a
        b
      

      If force is true, then it will pad to the indent even if it is in a flattened group.

    • text : StringFormat

      A node containing a plain string.

    • nest (indent : Int) : FormatFormat

      nest n f tells the formatter that f is nested inside something with length n so that it is pretty-printed with the correct indentation on a line break. For example, we can define a formatter for list l : List Format as:

      let f := join <| l.intersperse <| ", " ++ Format.line
      group (nest 1 <| "[" ++ f ++ "]")
      

      This will be written all on one line, but if the text is too large, the formatter will put in linebreaks after the commas and indent later lines by 1.

    • append : FormatFormatFormat

      Concatenation of two Formats.

    • group : Format(behavior : optParam FlattenBehavior FlattenBehavior.allOrNone) → Format

      Creates a new flattening group for the given inner format.

    • tag : NatFormatFormat

      Used for associating auxiliary information (e.g. Exprs) with Format objects.

    Instances For

      Check whether the given format contains no characters.

      Equations
        Instances For

          Alias for a group with FlattenBehavior set to fill.

          Equations
            Instances For
              Equations
                Instances For
                  Equations
                    Instances For

                      A directive indicating whether a given work group is able to be flattened.

                      • allow indicates that the group is allowed to be flattened; its argument is true if there is sufficient space for it to be flattened (and so it should be), or false if not.
                      • disallow means that this group should not be flattened irrespective of space concerns. This is used at levels of a Format outside of any flattening groups. It is necessary to track this so that, after a hard line break, we know whether to try to flatten the next line.
                      Instances For

                        Whether the given directive indicates that flattening should occur.

                        Equations
                          Instances For

                            A monad in which we can pretty-print Format objects.

                            • pushOutput (s : String) : m Unit
                            • pushNewline (indent : Nat) : m Unit
                            • currColumn : m Nat
                            • startTag : Natm Unit

                              Start a scope tagged with n.

                            • endTags : Natm Unit

                              Exit the scope of n-many opened tags.

                            Instances
                              def Std.Format.prettyM {m : TypeType} (f : Format) (w : Nat) (indent : Nat := 0) [Monad m] [MonadPrettyFormat m] :

                              Render the given f : Format with a line width of w. indent is the starting amount to indent each line by.

                              Equations
                                Instances For
                                  @[inline]

                                  Create a format l ++ f ++ r with a flatten group. FlattenBehaviour is allOrNone; for fill use bracketFill.

                                  Equations
                                    Instances For
                                      @[inline]

                                      Creates the format "(" ++ f ++ ")" with a flattening group.

                                      Equations
                                        Instances For
                                          @[inline]

                                          Creates the format "[" ++ f ++ "]" with a flattening group.

                                          Equations
                                            Instances For
                                              @[inline]

                                              Same as bracket except uses the fill flattening behaviour.

                                              Equations
                                                Instances For

                                                  Default indentation.

                                                  Equations
                                                    Instances For
                                                      Equations
                                                        Instances For

                                                          Default width of the targeted output pane.

                                                          Equations
                                                            Instances For

                                                              Nest with the default indentation amount.

                                                              Equations
                                                                Instances For

                                                                  Insert a newline and then f, all nested by the default indent amount.

                                                                  Equations
                                                                    Instances For
                                                                      @[export lean_format_pretty]
                                                                      def Std.Format.pretty (f : Format) (width : Nat := defWidth) (indent column : Nat := 0) :

                                                                      Renders a Format to a string.

                                                                      • width: the total width
                                                                      • indent: the initial indentation to use for wrapped lines (subsequent wrapping may increase the indentation)
                                                                      • column: begin the first line wrap column characters earlier than usual (this is useful when the output String will be printed starting at column)
                                                                      Equations
                                                                        Instances For
                                                                          class Std.ToFormat (α : Type u) :

                                                                          Class for converting a given type α to a Format object for pretty-printing. See also Repr, which also outputs a Format object.

                                                                          Instances
                                                                            def Std.Format.joinSep {α : Type u} [ToFormat α] :
                                                                            List αFormatFormat

                                                                            Intersperse the given list (each item printed with format) with the given sep format.

                                                                            Equations
                                                                              Instances For
                                                                                def Std.Format.prefixJoin {α : Type u} [ToFormat α] (pre : Format) :
                                                                                List αFormat

                                                                                Format each item in items and prepend prefix pre.

                                                                                Equations
                                                                                  Instances For
                                                                                    def Std.Format.joinSuffix {α : Type u} [ToFormat α] :
                                                                                    List αFormatFormat

                                                                                    Format each item in items and append suffix.

                                                                                    Equations
                                                                                      Instances For