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
Instances For
Constructs a cursor at the start of line (column 0).
Equations
- Lean.Markdown.Cursor.ofLine line = { pos := line.startInclusive, stop := line.endExclusive, col := 0 }
Instances For
The remaining text of the line, from the cursor to its end.
Equations
Instances For
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.
Instances For
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
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
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.