Documentation

Mathlib.Tactic.Linter.PPRoundtrip

The "ppRoundtrip" linter #

The "ppRoundtrip" linter emits a warning when the syntax of a command differs substantially from the pretty-printed version of itself.

The "ppRoundtrip" linter emits a warning when the syntax of a command differs substantially from the pretty-printed version of itself.

The linter makes an effort to start the highlighting at the first difference. However, it may not always be successful. It also prints both the source code and the "expected code" in a 5-character radius from the first difference.

polishPP s takes as input a String s, assuming that it is the output of pretty-printing a lean command. The main intent is to convert s to a reasonable candidate for a desirable source code format. The function first replaces consecutive whitespace sequences into a single space ( ), in an attempt to side-step line-break differences. After that, it applies some pre-emptive changes:

  • doc-module beginnings tend to have some whitespace following them, so we add a space back in;
  • name quotations such as ``Nat get pretty-printed as `` Nat, so we remove a space after double back-ticks, but take care of adding one more for triple (or more) back-ticks;
  • notation3 is not followed by a pretty-printer space, so we add it here (#15515).
Equations
  • One or more equations did not get rendered due to their size.
Instances For

    polishSource s is similar to polishPP s, but expects the input to be actual source code. For this reason, polishSource s performs more conservative changes: it only replace all whitespace starting from a linebreak (\n) with a single whitespace.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      posToShiftedPos lths diff takes as input an array lths of natural numbers, and one further natural number diff. It adds up the elements of lths occupying the odd positions, as long as the sum of the elements in the even positions does not exceed diff. It returns the sum of the accumulated odds and diff. This is useful to figure out the difference between the output of polishSource s and s itself. It plays a role similar to the fileMap.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def Mathlib.Linter.zoomString (str : String) (centre : Nat) (offset : Nat) :

        zoomString str centre offset returns the substring of str consisting of the offset characters around the centreth character.

        Equations
        • Mathlib.Linter.zoomString str centre offset = { str := str, startPos := { byteIdx := centre - offset }, stopPos := { byteIdx := centre + offset } }
        Instances For

          capSourceInfo s p "shortens" all end-position information in the SourceInfo s to be at most p, trimming down also the relevant substrings.

          Equations
          Instances For

            capSyntax stx p applies capSourceInfo · s to all SourceInfos in all nodes, atoms and idents contained in stx.

            This is used to trim away all "fluff" that follows a command: comments and whitespace after a command get removed with capSyntax stx stx.getTailPos?.get!.

            The "ppRoundtrip" linter emits a warning when the syntax of a command differs substantially from the pretty-printed version of itself.

            The linter makes an effort to start the highlighting at the first difference. However, it may not always be successful. It also prints both the source code and the "expected code" in a 5-character radius from the first difference.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For