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.
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.
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.
Instances For
Builds a link URL token containing value, with its position taken from src.
Instances For
Builds an image's alternate text containing value, with its position taken from src.
Instances For
Builds the URL of a link reference definition containing value, with its position taken from
src.
Instances For
Builds a code block's content containing value, with one line token per line and its position
taken from src.
Instances For
A view of stx, if it is a link target.
Instances For
A view of ordinary text.
Instances For
Decodes the Verso text contained in the view, interpreting escape sequences.
Instances For
Returns the literal representation of the text in the view, without interpreting escape sequences.
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
Instances For
The decoded code contents.
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.
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.
Instances For
A view of stx, if it is a footnote use site.
Instances For
A view of a line break.
Instances For
A view of stx, if it is a line break.
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 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
Returns the original syntax that an inline view was constructed from.
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.
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.
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.
Instances For
A view of stx, if it is an ordered list's item. Its marker must be a number.
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.
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
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.
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.
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.
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.
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.
Instances For
A view of stx, if it is a code block.
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.
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.
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.
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.
Instances For
The URL that the reference provides.
Instances For
A view of stx, if it is a named URL.
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.
Instances For
A view of stx, if it is a footnote definition.
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.
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
Returns the syntax underlying a block view.
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.
Instances For
Returns a view of an inline element of a Verso document.
Returns default if the syntax is malformed.
Instances For
Returns a view of a block-level element of a Verso document.
Returns default if the syntax is malformed.