This module defines views of the concrete syntax of Verso documents.
The syntax declarations in Lean.DocString.Syntax specify the shapes of the trees that the Verso
parser and quotations produce. Views expose one level of this structure at a time as ordinary Lean
datatypes. Each view node records the syntax it represents, the delimiter atoms that tooling such as
semantic highlighting needs, and decoded values for literal content. Using views allows clients to
avoid needing to check for things like optional brackets at all sites.
An of function returns none when the syntax does not have the specified shape. The parser and
quotations produce only well-formed trees, so a none result indicates a bug. Callers report it as
an error at the syntax in question.
A view of the value of an argument to a role, directive, command, or code block.
- str (lit : StrLit) (value : String) : ArgValView
A string literal.
valueis its decoded contents. - name (x : Ident) : ArgValView
An identifier.
- num (lit : NumLit) (value : Nat) : ArgValView
A numeric literal.
valueis its decoded value.
Instances For
A view of stx, if it is an argument value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of an argument to a role, directive, command, or code block.
- anon (stx : TSyntax `Lean.Doc.Parser.arg) (val : TSyntax `Lean.Doc.Parser.argVal) : ArgView
An anonymous positional argument.
- named (stx : TSyntax `Lean.Doc.Parser.arg) (parens : Option (Syntax × Syntax)) (name : Ident) (assign : Syntax) (val : TSyntax `Lean.Doc.Parser.argVal) : ArgView
A named argument.
parensis the pair of parenthesis atoms when the argument is written in parentheses, andassignis the:=atom. - flag (stx : TSyntax `Lean.Doc.Parser.arg) (sign : Syntax) (name : Ident) (isOn : Bool) : ArgView
A flag.
signis the+or-atom, andisOnindicates which one it is.
Instances For
Returns the syntax underlying an argument view.
Equations
- (Lean.Doc.ArgView.anon stx val).stx = stx
- (Lean.Doc.ArgView.named stx parens name assign val).stx = stx
- (Lean.Doc.ArgView.flag stx sign name isOn).stx = stx
Instances For
A view of a link target, which is either a URL or a reference to a URL defined elsewhere.
- url (stx : TSyntax `Lean.Doc.Parser.linkTarget) (opener : Syntax) (url : VersoLinkUrl) (closer : Syntax) : LinkTargetView
A URL written directly, in parentheses. Use
TSyntax.getVersoLinkUrlto read it. - ref (stx : TSyntax `Lean.Doc.Parser.linkTarget) (opener : Syntax) (name : VersoRefName) (closer : Syntax) : LinkTargetView
A reference to a URL defined elsewhere, in square brackets. Use
TSyntax.getVersoRefNameto read the name.
Instances For
Builds the name of a footnote or link reference containing value, with its position taken from
src.
Equations
- Lean.Doc.mkVersoRefNameFrom src value canonical = { raw := (Lean.Syntax.mkLit Lean.Doc.versoRefKind value (Lean.SourceInfo.fromRef src canonical)).raw }
Instances For
Builds a link URL token containing value, with its position taken from src.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Builds an image's alternate text containing value, with its position taken from src.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Builds the URL of a link reference definition containing value, with its position taken from
src.
Equations
- Lean.Doc.mkVersoLinkRefUrlFrom src value canonical = { raw := (Lean.Syntax.mkLit Lean.Doc.versoLinkRefUrlKind value (Lean.SourceInfo.fromRef src canonical)).raw }
Instances For
Builds a code block's content containing value, with one line token per line and its position
taken from src.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Builds a line break, positioned at the current reference.
Equations
- Lean.Doc.mkVersoLinebreakFromRef canonical = do let __do_lift ← Lean.getRef pure (Lean.Doc.mkVersoLinebreakFrom __do_lift canonical)
Instances For
Builds a text content token containing value, positioned at the current reference.
Equations
- Lean.Doc.mkVersoTextFromRef value canonical = do let __do_lift ← Lean.getRef pure (Lean.Doc.mkVersoTextFrom __do_lift value canonical)
Instances For
Builds a reference name containing value, positioned at the current reference.
Equations
- Lean.Doc.mkVersoRefNameFromRef value canonical = do let __do_lift ← Lean.getRef pure (Lean.Doc.mkVersoRefNameFrom __do_lift value canonical)
Instances For
Builds a link URL containing value, positioned at the current reference.
Equations
- Lean.Doc.mkVersoLinkUrlFromRef value canonical = do let __do_lift ← Lean.getRef pure (Lean.Doc.mkVersoLinkUrlFrom __do_lift value canonical)
Instances For
Builds an image's alternate text containing value, positioned at the current reference.
Equations
- Lean.Doc.mkVersoImageAltFromRef value canonical = do let __do_lift ← Lean.getRef pure (Lean.Doc.mkVersoImageAltFrom __do_lift value canonical)
Instances For
Builds the URL of a link reference definition containing value, positioned at the syntax getRef
returns.
Equations
- Lean.Doc.mkVersoLinkRefUrlFromRef value canonical = do let __do_lift ← Lean.getRef pure (Lean.Doc.mkVersoLinkRefUrlFrom __do_lift value canonical)
Instances For
Builds inline code content containing value, positioned at the current reference.
Equations
- Lean.Doc.mkVersoCodeFromRef value canonical = do let __do_lift ← Lean.getRef pure (Lean.Doc.mkVersoCodeFrom __do_lift value canonical)
Instances For
Builds a code block's content containing value, positioned at the current reference.
Equations
- Lean.Doc.mkVersoCodeBlockFromRef value canonical = do let __do_lift ← Lean.getRef pure (Lean.Doc.mkVersoCodeBlockFrom __do_lift value canonical)
Instances For
A view of stx, if it is a link target.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of ordinary text.
Instances For
Equations
Decodes the Verso text contained in the view, interpreting escape sequences.
Equations
Instances For
Returns the literal representation of the text in the view, without interpreting escape sequences.
Equations
Instances For
A view of emphasized content.
- stx : TSyntax `Lean.Doc.Parser.inline
The original syntax.
- opener : TSyntax `Lean.Doc.Parser.emphDelimiter
The opening run of
_. - content : TSyntaxArray `Lean.Doc.Parser.inline
The emphasized content.
- closer : TSyntax `Lean.Doc.Parser.emphDelimiter
The closing run of
_.
Instances For
A view of bold content.
- stx : TSyntax `Lean.Doc.Parser.inline
The original syntax.
- opener : TSyntax `Lean.Doc.Parser.boldDelimiter
The opening run of
*. - content : TSyntaxArray `Lean.Doc.Parser.inline
The bold content.
- closer : TSyntax `Lean.Doc.Parser.boldDelimiter
The closing run of
*.
Instances For
A view of literal code.
This view is used both for inline code elements and the body of math notation.
- stx : TSyntax `Lean.Doc.Parser.inline
The original syntax.
- opener : TSyntax `Lean.Doc.Parser.codeDelimiter
The opening run of backticks.
- content : VersoCode
The code.
- closer : TSyntax `Lean.Doc.Parser.codeDelimiter
The closing run of backticks.
Instances For
The decoded code contents
Equations
Instances For
The decoded code contents.
Equations
Instances For
A view of a link.
- stx : TSyntax `Lean.Doc.Parser.inline
The original syntax.
- opener : Syntax
The
[that opens the link text. - content : TSyntaxArray `Lean.Doc.Parser.inline
The link text.
- closer : Syntax
The
]that closes the link text. - target : LinkTargetView
Where the link leads.
Instances For
A view of an image.
- stx : TSyntax `Lean.Doc.Parser.inline
The original syntax.
- opener : Syntax
The
![that opens the alternate text. - alt : VersoImageAlt
The alternate text.
- closer : Syntax
The
]that closes the alternate text. - target : LinkTargetView
Where the image is found.
Instances For
The alternate text, with each escape replaced by the character it denotes.
Equations
Instances For
A view of a footnote use site.
- stx : TSyntax `Lean.Doc.Parser.inline
The original syntax.
- opener : Syntax
The
[^that opens the name. - name : VersoRefName
The name that refers to the footnote's definition.
- closer : Syntax
The
]that closes the name.
Instances For
The name that refers to the footnote's definition.
Equations
Instances For
A view of stx, if it is a footnote use site.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a line break.
Instances For
A view of stx, if it is a line break.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of content with a role.
- stx : TSyntax `Lean.Doc.Parser.inline
The original syntax.
- braceOpen : Syntax
The
{that opens the name and arguments. - name : Ident
The name that selects the role's expander.
- args : TSyntaxArray `Lean.Doc.Parser.arg
The arguments to the role.
- braceClose : Syntax
The
}that closes the name and arguments. The brackets around the content, if they are present.
- content : TSyntaxArray `Lean.Doc.Parser.inline
The content that the role applies to.
Instances For
A view of stx, if it is content with a role.
An author may write content that has delimiters of its own without brackets, so the brackets are matched separately from the name and arguments.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of an inline document element.
- text (view : TextView) : InlineView
Ordinary text.
- emph (view : EmphView) : InlineView
Emphasized content.
- bold (view : BoldView) : InlineView
Bold content.
- code (view : CodeView) : InlineView
Literal code.
- math (view : MathView) : InlineView
Mathematical notation.
- link (view : LinkView) : InlineView
A link.
- image (view : ImageView) : InlineView
An image.
- footnote (view : FootnoteView) : InlineView
A footnote use site.
- linebreak (view : LinebreakView) : InlineView
A soft line break.
- role (view : RoleView) : InlineView
A role applied to some content.
Instances For
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Returns the original syntax that an inline view was constructed from.
Equations
- (Lean.Doc.InlineView.text v).stx = v.stx
- (Lean.Doc.InlineView.emph v).stx = v.stx
- (Lean.Doc.InlineView.bold v).stx = v.stx
- (Lean.Doc.InlineView.code v).stx = v.stx
- (Lean.Doc.InlineView.math v).stx = v.stx
- (Lean.Doc.InlineView.link v).stx = v.stx
- (Lean.Doc.InlineView.image v).stx = v.stx
- (Lean.Doc.InlineView.footnote v).stx = v.stx
- (Lean.Doc.InlineView.linebreak v).stx = v.stx
- (Lean.Doc.InlineView.role v).stx = v.stx
Instances For
A view of stx, if it is an inline document element.
Each production has a view of its own, and this tries them in turn. The productions have distinct syntax kinds, so at most one applies and the order does not matter.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of an item of an unordered list.
- stx : TSyntax `Lean.Doc.Parser.ListItem.item
The original syntax.
- marker : TSyntax `Lean.Doc.Parser.listMarker
The marker, which is
*,-, or+. - contents : TSyntaxArray `Lean.Doc.Parser.block
The item's contents.
Instances For
A view of stx, if it is an unordered list's item. Its marker must be a bullet.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of an item of an ordered list.
- stx : TSyntax `Lean.Doc.Parser.ListItem.item
The original syntax.
- marker : TSyntax `Lean.Doc.Parser.listMarker
The marker, which is a number followed by
.or). - contents : TSyntaxArray `Lean.Doc.Parser.block
The item's contents.
Instances For
The number that the item's marker gives it.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of stx, if it is an ordered list's item. Its marker must be a number.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of an item description from a description list.
- stx : TSyntax `Lean.Doc.Parser.DescItem.item
The original syntax.
- marker : Syntax
The
:that introduces the item. - term : TSyntaxArray `Lean.Doc.Parser.inline
The term that the item describes.
- desc : TSyntaxArray `Lean.Doc.Parser.block
The description.
Instances For
A view of stx, if it is a description list item.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a paragraph.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- content : TSyntaxArray `Lean.Doc.Parser.inline
The paragraph's contents.
Instances For
Equations
A view of an unordered list.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- items : Array UnorderedListItemView
The list's items.
Instances For
A view of stx, if it is an unordered list.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of an ordered list.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- start : Nat
The number of the first item, which the first item's marker gives it.
- items : Array OrderedListItemView
The list's items.
Instances For
A view of stx, if it is an ordered list.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a description list.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- items : Array DescItemView
The list's items.
Instances For
A view of stx, if it is a description list.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a block quotation.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- marker : Syntax
The
>that introduces the quotation. - content : TSyntaxArray `Lean.Doc.Parser.block
The quoted blocks.
Instances For
A view of stx, if it is a block quotation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a code block.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- openFence : TSyntax `Lean.Doc.Parser.codeBlockFence
The opening run of backticks.
The name that selects the code block's expander, where the code block invokes one.
- args : TSyntaxArray `Lean.Doc.Parser.arg
The arguments to the expander.
- content : VersoCodeBlock
The code.
- closeFence : TSyntax `Lean.Doc.Parser.codeBlockFence
The closing run of backticks.
Instances For
The code, which is the texts of its lines in order.
Equations
Instances For
A view of stx, if it is a code block.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a directive.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- opener : TSyntax `Lean.Doc.Parser.directiveDelimiter
The opening run of colons.
- name : Ident
The name that selects the directive's expander.
- args : TSyntaxArray `Lean.Doc.Parser.arg
The arguments to the directive.
- content : TSyntaxArray `Lean.Doc.Parser.block
The blocks that the directive contains.
- closer : TSyntax `Lean.Doc.Parser.directiveDelimiter
The closing run of colons.
Instances For
A view of stx, if it is a directive.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a block-level command.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- braceOpen : Syntax
The
{that opens the name and arguments. - name : Ident
The name that selects the command's expander.
- args : TSyntaxArray `Lean.Doc.Parser.arg
The arguments to the command.
- braceClose : Syntax
The
}that closes the name and arguments.
Instances For
A view of stx, if it is a block-level command.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a section header.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- marker : TSyntax `Lean.Doc.Parser.headerMarker
The run of
#characters. - level : Nat
The header's nesting depth, with
0denoting a top-level header. - content : TSyntaxArray `Lean.Doc.Parser.inline
The header's text.
Instances For
A view of stx, if it is a section header.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a named URL that links and images can use.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- opener : Syntax
The
[that opens the name. - name : VersoRefName
The name that a link or image uses to reach the URL.
- closer : Syntax
The
]:that closes the name. - url : VersoLinkRefUrl
The URL.
Instances For
The name that a link or image repeats to reach this URL.
Equations
Instances For
The URL that the reference provides.
Equations
Instances For
A view of stx, if it is a named URL.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a footnote definition.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- opener : Syntax
The
[^that opens the name. - name : VersoRefName
The name of the footnote.
- closer : Syntax
The
]:that closes the name. - content : TSyntaxArray `Lean.Doc.Parser.inline
The footnote's text.
Instances For
The name of the footnote.
Equations
Instances For
A view of stx, if it is a footnote definition.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a metadata block for the preceding header.
- stx : TSyntax `Lean.Doc.Parser.block
The original syntax.
- opener : Syntax
The opening
%%%. - contents : TSyntax `Lean.Parser.Term.structInstFields
The metadata, written as the fields of a Lean structure instance.
- closer : Syntax
The closing
%%%.
Instances For
The individual metadata fields, without their separators.
Instances For
A view of stx, if it is a metadata block.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A view of a block-level document element.
Each view records the syntax it is a view of, the delimiter atoms, and decoded values for literal content. Nested content stays as concrete syntax, for the consumer to view in turn.
- para (view : ParaView) : BlockView
A paragraph.
- ul (view : UnorderedListView) : BlockView
An unordered list.
- ol (view : OrderedListView) : BlockView
An ordered list.
- dl (view : DescListView) : BlockView
A description list.
- blockquote (view : BlockquoteView) : BlockView
A block quotation.
- codeblock (view : CodeBlockView) : BlockView
A code block.
- directive (view : DirectiveView) : BlockView
A directive.
- command (view : CommandView) : BlockView
A block-level command.
- header (view : HeaderView) : BlockView
A section header.
- linkRef (view : LinkRefView) : BlockView
A named URL that links and images can use.
- footnoteRef (view : FootnoteRefView) : BlockView
A footnote definition.
- metadata (view : MetadataView) : BlockView
A metadata block for the preceding header.
Instances For
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Returns the syntax underlying a block view.
Equations
- (Lean.Doc.BlockView.para v).stx = v.stx
- (Lean.Doc.BlockView.ul v).stx = v.stx
- (Lean.Doc.BlockView.ol v).stx = v.stx
- (Lean.Doc.BlockView.dl v).stx = v.stx
- (Lean.Doc.BlockView.blockquote v).stx = v.stx
- (Lean.Doc.BlockView.codeblock v).stx = v.stx
- (Lean.Doc.BlockView.directive v).stx = v.stx
- (Lean.Doc.BlockView.command v).stx = v.stx
- (Lean.Doc.BlockView.header v).stx = v.stx
- (Lean.Doc.BlockView.linkRef v).stx = v.stx
- (Lean.Doc.BlockView.footnoteRef v).stx = v.stx
- (Lean.Doc.BlockView.metadata v).stx = v.stx
Instances For
A view of stx, if it is a block-level document element.
Each production has a view of its own, and this tries them in turn. The productions have distinct syntax kinds, so at most one applies and the order does not matter.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns a view of an inline element of a Verso document.
Returns default if the syntax is malformed.
Equations
- stx.view = (Lean.Doc.InlineView.of stx).getD default
Instances For
Returns a view of a block-level element of a Verso document.
Returns default if the syntax is malformed.
Equations
- stx.view = (Lean.Doc.BlockView.of stx).getD default