Skip to main content

Module literate_parser

Module literate_parser 

Source
Expand description

Literate Specification Parser for the Kernel.

This module parses English-like “Literate” syntax and emits the same Command and Term structures as the Coq-style parser.

§Supported Syntax

§Inductive Types

A Bool is either Yes or No.
A Nat is either:
    Zero.
    a Successor with pred: Nat.

§Function Definitions (with implicit recursion)

## To add (n: Nat) and (m: Nat) -> Nat:
    Consider n:
        When Zero: Yield m.
        When Successor k: Yield Successor (add k m).

§Pattern Matching

Consider x:
    When Zero: Yield 0.
    When Successor k: Yield k.

Several columns at once, separated by and — Lean’s | 0, _ => … — with the overlap split top-to-bottom by the equation compiler:

Consider a and b:
    When Zero and _: Yield 1.
    When _ and Zero: Yield 2.
    When _ and _: Yield 3.

§Lambda Expressions

given x: Nat yields Successor x
|x: Nat| -> Successor x

Constants§

ONE_SHOT_TACTICS
The closed one-shot tactic vocabulary of the literate Proof: surface: the keyword a mathematician writes, and the reflected tactic it applies to the reified goal. Adding a tactic is a row here — parse_proof_tactic and parse_single_tactic both read this table, so the two doors can never drift apart again.

Functions§

measure_definition
The EXTENT of the ## To block at the front of input — where it ends — read from its syntax alone. See measure_theorem.
measure_theorem
The EXTENT of the ## Theorem: block at the front of input, read from its syntax alone.
parse_definition
Parse “## To [name] (params) -> RetType:” into Command::Definition
parse_definition_in
parse_definition, with the kernel context the equation compiler needs.
parse_definition_scoped
parse_definition_in, reading every name in the namespace scope scope — the door the REPL reads through, so a literate definition’s names mean exactly what they mean to every other door.
parse_inductive
Parse “A [Name] is either…” into Command::Inductive
parse_let_definition
Parse “Let [name] be [term].” into Command::Definition (constant, not function)
parse_theorem
Parse “## Theorem: [name] Statement: [proposition].” into Command::Definition
parse_theorem_in
parse_theorem, with the kernel context.
parse_theorem_scoped
parse_theorem_in, reading every name in the namespace scope scope. The statement is reflected into syntax only after its names are resolved, so a theorem about add in a session that shadows add is a theorem about the session’s add.