Documentation

Lean.DocString.Syntax

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:

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.

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

      Anonymous positional arguments

      Equations
      Instances For

        Named arguments

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

          Named arguments, without parentheses.

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

            Boolean flags, turned on

            Equations
            Instances For

              Boolean flags, turned off

              Equations
              Instances For

                A reference to a URL

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

                  A named reference

                  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

                        Emphasis (often rendered as italics)

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

                          Bold emphasis

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

                            Image

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

                              A footnote use

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

                                Literal code. 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.

                                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

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

                                    Inline mathematical notation (equivalent to LaTeX's $ notation)

                                    Equations
                                    Instances For

                                      Display-mode mathematical notation

                                      Equations
                                      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

                                                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
                                                        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

                                                            Definition 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

                                                                Literal code

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

                                                                  Quotation

                                                                  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

                                                                      Custom directive

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

                                                                        A header

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

                                                                          Metadata for this section, defined by the current genre

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

                                                                            A block-level command

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