This module contains an internal syntax that's used to represent documents.
Ordinarily, a syntax declaration is used to extend the Lean parser. The parser produces Syntax,
which is flexible enough to represent essentially anything. However, each syntax declaration will
produce parsed syntax trees with a predictable form, and these syntax trees can be matched using
quasiquotation patterns. In other words, syntax declarations really do all of the following:
- They extend Lean's parser
- They establish expectations for valid subsets of
Syntax - They provide a way to pattern-match against the valid
Syntaxthat they induce
The syntax declarations in this module are used somewhat differently. They're not generally intended
for direct use with the Lean parser, because the concrete syntax of Verso documents falls outside
what can be implemented with Lean's parsing framework. Thus, Verso has a separate parser, written
using the lower-level parts of Lean's parser. These syntax declarations are, however, a
specification for the syntax trees produced by said parser. The Verso parser is in the module
Lean.DocString.Parser. Specifying the Verso document syntax as is done here also allows
quasiquotation patterns that match against the output of the Verso parser.
Importantly, Lean quasiquotation patterns do not match the string contents of atoms. This means that
the Verso parser may produce a node of kind `Lean.Doc.Syntax.li in which the first atom is
"1." rather than "*' when parsing an ordered list.
Parsed Verso documents are transformed into Lean syntax that represents Verso document ASTs (see
module Lean.DocString.Types). This process potentially invokes user-written metaprograms - while
Verso's concrete syntax is not extensible, roles, directives and code blocks all contain explicit
hooks for extensibility. This translation step is defined in the module Lean.DocString.Elab.
Argument values
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Doc.Syntax.arg_str = Lean.ParserDescr.node `Lean.Doc.Syntax.arg_str 1022 (Lean.ParserDescr.const `str)
Instances For
Equations
- Lean.Doc.Syntax.arg_ident = Lean.ParserDescr.node `Lean.Doc.Syntax.arg_ident 1022 (Lean.ParserDescr.const `ident)
Instances For
Equations
- Lean.Doc.Syntax.arg_num = Lean.ParserDescr.node `Lean.Doc.Syntax.arg_num 1022 (Lean.ParserDescr.const `num)
Instances For
Arguments
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Anonymous positional argument
Equations
- Lean.Doc.Syntax.anon = Lean.ParserDescr.node `Lean.Doc.Syntax.anon 1022 (Lean.ParserDescr.cat `arg_val 0)
Instances For
Named argument
Equations
- One or more equations did not get rendered due to their size.
Instances For
Named argument
Equations
- One or more equations did not get rendered due to their size.
Instances For
Boolean flag, turned on
Equations
- Lean.Doc.Syntax.flag_on = Lean.ParserDescr.node `Lean.Doc.Syntax.flag_on 1022 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "+") (Lean.ParserDescr.const `ident))
Instances For
Boolean flag, turned off
Equations
- Lean.Doc.Syntax.flag_off = Lean.ParserDescr.node `Lean.Doc.Syntax.flag_off 1022 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "-") (Lean.ParserDescr.const `ident))
Instances For
Link targets, which may be URLs or named references
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
A URL target, written explicitly. Use square brackets for a named target.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A named reference to a URL defined elsewhere. Use parentheses to write the URL here.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Verso inline objects. These are part of the ordinary text flow of a paragraph.
This syntax uses the following conventions:
- Sequences of inline items are in square brackets
- Literal data, like strings or numbers, are in parentheses
- Verso metaprogram names and arguments are in curly braces
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Doc.Syntax.text = Lean.ParserDescr.node `Lean.Doc.Syntax.text 1022 (Lean.ParserDescr.const `str)
Instances For
Emphasis, often rendered as italics.
Emphasis may be nested by using longer sequences of _ for the outer delimiters. For example:
Remember: __always butter the _rugbrød_ before adding toppings!__
Here, the outer __ is used to emphasize the instructions, while the inner _ indicates the use of
a non-English word.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bold emphasis.
A single * suffices to make text bold. Using _ for emphasis.
Bold text may be nested by using longer sequences of * for the outer delimiters.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A link. The link's target may either be a concrete URL (written in parentheses) or a named URL (written in square brackets).
Equations
- One or more equations did not get rendered due to their size.
Instances For
An image, with alternate text and a URL.
The alternate text is a plain string, rather than Verso markup.
The image URL may either be a concrete URL (written in parentheses) or a named URL (written in square brackets).
Equations
- One or more equations did not get rendered due to their size.
Instances For
A footnote use site.
Footnotes must be defined elsewhere using the [^NAME]: TEXT syntax.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Doc.Syntax.linebreak = Lean.ParserDescr.node `Lean.Doc.Syntax.linebreak 1022 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "line!") (Lean.ParserDescr.const `str))
Instances For
Literal code.
Code may begin with any non-zero number of backticks. It must be terminated with the same number, and it may not contain a sequence of backticks that is at least as long as its starting or ending delimiters.
If the first and last characters are space, and it contains at least one non-space character, then
the resulting string has a single space stripped from each end. Thus, `` `x `` represents
"`x", not " `x ".
Equations
- One or more equations did not get rendered due to their size.
Instances For
A role: an extension to the Verso document language in an inline position.
Text is given a role using the following syntax: {NAME ARGS*}[CONTENT]. The NAME is an
identifier that determines which role is being used, akin to a function name. Each of the ARGS may
have the following forms:
- A value, which is a string literal, natural number, or identifier
- A named argument, of the form
(NAME := VALUE) - A flag, of the form
+NAMEor-NAME
The CONTENT is a sequence of inline content. If there is only one piece of content and it has
beginning and ending delimiters (e.g. code literals, links, or images, but not ordinary text), then
the [ and ] may be omitted. In particular, {NAME ARGS*}`x` is equivalent to
{NAME ARGS*}[`x`].
Equations
- One or more equations did not get rendered due to their size.
Instances For
Inline mathematical notation (equivalent to LaTeX's $ notation)
Equations
- Lean.Doc.Syntax.inline_math = Lean.ParserDescr.node `Lean.Doc.Syntax.inline_math 1022 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "\\math") Lean.Doc.Syntax.code)
Instances For
Display-mode mathematical notation
Equations
- Lean.Doc.Syntax.display_math = Lean.ParserDescr.node `Lean.Doc.Syntax.display_math 1022 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "\\displaymath") Lean.Doc.Syntax.code)
Instances For
Block-level elements, such as paragraphs, headers, and lists.
Conventions:
- When there's concrete syntax that can be written as Lean atoms, do so (code blocks are
```, directives:::) - When Verso's syntax requires a newline, use
|because"\n"is not a valid Lean token - Directive bodies are in
{and}to avoid quotation parsing issues with:::...::: - If there's no concrete syntax per se, such as for paragraphs or lists, use a name with brackets and braces
- Use parentheses around required literals, such as the starting number of an ordered list
- Use square brackets around sequences of literals
- Use curly braces around blocks or lists items (because names and arguments a la roles are always newline-separated for directives and code)
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Items from both ordered and unordered lists
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
A list item
Equations
- One or more equations did not get rendered due to their size.
Instances For
A description of an item
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
A description of an item
Equations
- One or more equations did not get rendered due to their size.
Instances For
Paragraph
Equations
- One or more equations did not get rendered due to their size.
Instances For
Unordered List
Equations
- One or more equations did not get rendered due to their size.
Instances For
Description list
Equations
- One or more equations did not get rendered due to their size.
Instances For
Ordered list
Equations
- One or more equations did not get rendered due to their size.
Instances For
A code block that contains literal code.
Code blocks have the following syntax:
```(NAME ARGS*)?
CONTENT
```
CONTENT is a literal string. If the CONTENT contains a sequence of three or more backticks, then
the opening and closing ``` (called fences) should have more backticks than the longest
sequence in CONTENT. Additionally, the opening and closing fences should have the same number of
backticks.
If NAME and ARGS are not provided, then the code block represents literal text. If provided, the
NAME is an identifier that selects an interpretation of the block. Unlike Markdown, this name is
not necessarily the language in which the code is written, though many custom code blocks are, in
practice, named after the language that they contain. NAME is more akin to a function name. Each
of the ARGS may have the following forms:
- A value, which is a string literal, natural number, or identifier
- A named argument, of the form
(NAME := VALUE) - A flag, of the form
+NAMEor-NAME
The CONTENT is interpreted according to the indentation of the fences. If the fences are indented
n spaces, then n spaces are removed from the start of each line of CONTENT.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A quotation, which contains a sequence of blocks that are at least as indented as the >.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A named URL that can be used in links and images.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A footnote definition.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A directive, which is an extension to the Verso language in block position.
Directives have the following syntax:
:::NAME ARGS*
CONTENT*
:::
The NAME is an identifier that determines which directive is being used, akin to a function name.
Each of the ARGS may have the following forms:
- A value, which is a string literal, natural number, or identifier
- A named argument, of the form
(NAME := VALUE) - A flag, of the form
+NAMEor-NAME
The CONTENT is a sequence of block content. Directives may be nested by using more colons in
the outer directive. For example:
::::outer +flag (arg := 5)
A paragraph.
:::inner "label"
* 1
* 2
:::
::::
Equations
- One or more equations did not get rendered due to their size.
Instances For
A header
Headers must be correctly nested to form a tree structure. The first header in a document must
start with #, and subsequent headers must have at most one more # than the preceding header.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Metadata for the preceding header.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A block-level command, which invokes an extension during documentation processing.
The NAME is an identifier that determines which command is being used, akin to a function name.
Each of the ARGS may have the following forms:
- A value, which is a string literal, natural number, or identifier
- A named argument, of the form
(NAME := VALUE) - A flag, of the form
+NAMEor-NAME
Equations
- One or more equations did not get rendered due to their size.