Documentation

Lean.Data.Markdown.Parser.Cursor

Line Cursors #

The block parser processes one line at a time, and within each line it is constantly asking “what's at column N relative to the parent container's indent?”. Because CommonMark counts indentation in columns but the underlying source is characters, and a single tab can advance the column by 1–4 (CommonMark §2.2's partial tab rule), position and column are not in lockstep. The cursor is a structure that tracks both.

A position within a single source line, together with the line's end and the visual column of the position.

The pair (pos, col) is the parser's working position. They are kept in sync by the column-aware advancement primitives below. Direct field updates should preserve the invariant that col is the visual column of pos.

  • pos : s.Pos

    The current position.

  • stop : s.Pos

    The end of the line.

  • col : Columns

    The visual column of pos.

  • partialTab : Bool

    Whether pos is at a tab of which some columns, up to col, belong to a container prefix or to a block's indentation. The remaining columns belong to the line's content.

Instances For
    @[inline]

    Constructs a cursor at the start of line (column 0).

    Equations
    Instances For
      @[inline]

      Whether the cursor is at the end of the line.

      Equations
      Instances For
        @[inline]

        The remaining text of the line, from the cursor to its end.

        Equations
        Instances For
          @[inline]

          Consumes cols columns of the tab at the cursor, leaving the position at the tab (CommonMark §2.2's partial tab rule). The caller is responsible for ensuring that the tab has that many columns left.

          Equations
          Instances For
            @[inline]

            The character at the cursor, if the cursor is not at the end of the line.

            Equations
            Instances For
              @[inline]

              The cursor advanced by one character, or is unchanged at the end of the line.

              The column advances by one, which is correct for every character but a tab. For tabs use countIndentCols or consumeIndentCapped.

              Equations
              Instances For
                @[inline]

                Advances the cursor over the longest prefix of characters that satisfy pred, returning the resulting cursor and the number of characters that it consumes.

                The column is incremented by the consumed count, which is correct only when pred rejects the tab character (each matched char then advances the column by exactly one). For tab-aware whitespace skipping use countIndentCols or consumeIndentCapped.

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

                  Whether the rest of the line is blank (only spaces or tabs).

                  Equations
                  Instances For

                    The rest of the line as a line of verbatim block content.

                    A partly consumed tab at the cursor is excluded from the source, with its remaining columns becoming the line's leading spaces.

                    Equations
                    Instances For