Skip to content

Commit 6d7aca6

Browse files
feat: macros and notations (#147)
Closes #69, #70, #71
1 parent b761ea1 commit 6d7aca6

26 files changed

Lines changed: 3441 additions & 200 deletions

.vale/scripts/rewrite_html.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def process_html_file(filepath, output_filepath):
2727
if code_tag.next_sibling and code_tag.next_sibling.string and code_tag.next_sibling.string.startswith('th'):
2828
# Replace <code>XYZ</code>th with '5th'
2929
code_tag.replace_with("5")
30+
elif code_tag.attrs and 'class' in code_tag.attrs and 'hl' in code_tag['class'] and 'lean' in code_tag['class']:
31+
code_tag.decompose()
3032

3133
# Delete docstring content (for now)
3234
for element in soup.find_all(class_="namedocs"):

.vale/styles/Lean/TechnicalTerms.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ extends: substitution
22
message: Use '%s' instead of '%s'
33
level: error
44
ignorecase: true
5+
capitalize: true
56
swap:
67
'typeclass': 'type class'
78
'typeclasses': 'type classes'
@@ -19,3 +20,8 @@ swap:
1920
'semireducible': 'semi-reducible'
2021
'\b(.+)\b simps': 'non-terminal simps'
2122
'\babelian\b': 'Abelian'
23+
'context free grammar': 'context-free grammar'
24+
'left associative': 'left-associative'
25+
'right associative': 'right-associative'
26+
'pretty-printer': 'pretty printer'
27+
'pretty printed': 'pretty-printed'

.vale/styles/config/ignore/terms.txt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ Abelian
22
Packrat
33
accessor
44
accessors
5+
antiquotation
6+
antiquotation's
7+
antiquotations
8+
antiquotations'
59
bitvector
610
bitvectors
711
bitwise
@@ -15,6 +19,11 @@ cumulative
1519
cumulativity
1620
declaratively
1721
definitionally
22+
delaborate
23+
delaborated
24+
delaborates
25+
delaborating
26+
delaboration
1827
desugar
1928
desugared
2029
desugaring
@@ -28,6 +37,9 @@ enum
2837
equational
2938
extensional
3039
extensionality
40+
functor
41+
functor's
42+
functors
3143
guillemet
3244
guillemets
3345
hoc
@@ -38,6 +50,7 @@ initializers
3850
injectivity
3951
interoperate
4052
interoperates
53+
interrobang
4154
iterator
4255
iterator's
4356
iterators
@@ -53,21 +66,33 @@ metatheoretic
5366
metavariable
5467
metavariable's
5568
metavariables
69+
mixfix
5670
monoid
5771
monomorphic
5872
monomorphism
5973
multiset
6074
multisets
6175
namespace
6276
namespaces
77+
nonterminal
78+
nonterminals
6379
nullary
6480
parameters'
81+
parenthesization
82+
parenthesizer
83+
parenthesizers
84+
parser's
6585
polymorphic
6686
polymorphically
87+
postfix
6788
predicative
6889
predicativity
6990
prepending
7091
propositionally
92+
quasiquotation
93+
quasiquotations
94+
quasiquote
95+
quasiquoted
7196
recursor
7297
recursor's
7398
recursors
@@ -77,9 +102,9 @@ se
77102
semigroup
78103
semireducible
79104
simp
80-
simps
81105
simproc
82106
simprocs
107+
simps
83108
subgoal
84109
subgoals
85110
subproblem
@@ -100,4 +125,7 @@ toolchain's
100125
toolchains
101126
unary
102127
unescaped
128+
unexpander
129+
unexpanders
103130
uninstantiated
131+
unparenthesized

Manual.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ tag := "monads-and-do"
4444

4545
:::planned 102
4646
This chapter will describe `do`-notation in Lean:
47+
* Overview of {deftech}[monads]
4748
* Desugaring of `do` and its associated control structures
4849
* Comprehensive description of the syntax of `do`-notation
4950
* Definition of being in the "same `do`-block"
@@ -85,6 +86,14 @@ Describe {name}`Option`, including the default coercions and its API.
8586

8687
{include 0 Manual.NotationsMacros}
8788

89+
# Output from Lean
90+
91+
:::planned 122
92+
* {deftech}[Unexpanders]
93+
* {deftech key:="delaborate"}[Delaboration]
94+
* {deftech}[Pretty printing]
95+
* Parenthesizers
96+
:::
8897

8998
# Elan
9099
%%%

Manual/Elaboration.lean

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Author: David Thrane Christiansen
66
import VersoManual
77

88
import Manual.Meta
9+
import Manual.Papers
910

1011
open Verso.Genre Manual
1112

@@ -14,27 +15,6 @@ set_option pp.rawOnError true
1415
open Lean (Syntax SourceInfo)
1516

1617

17-
def pratt73 : InProceedings where
18-
title := .concat (inlines!"Top down operator precedence")
19-
authors := #[.concat (inlines!"Vaughan Pratt")]
20-
year := 1973
21-
booktitle := .concat (inlines!"Proceedings of the 1st Annual ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages")
22-
23-
def carneiro19 : Thesis where
24-
title := .concat (inlines!"The Type Theory of Lean")
25-
author := .concat (inlines!"Mario Carneiro")
26-
year := 2019
27-
university := .concat (inlines!"Carnegie Mellon University")
28-
url := some "https://github.com/digama0/lean-type-theory/releases/download/v1.0/main.pdf"
29-
degree := .concat (inlines!"Masters thesis")
30-
31-
def ullrich23 : Thesis where
32-
title := .concat (inlines!"An Extensible Theorem Proving Frontend")
33-
author := .concat (inlines!"Sebastian Ullrich")
34-
year := 2023
35-
university := .concat (inlines!"Karlsruhe Institute of Technology")
36-
url := some "https://www.lean-lang.org/papers/thesis-sebastian.pdf"
37-
degree := .concat (inlines!"Dr. Ing. dissertation")
3818

3919
#doc (Manual) "Elaboration and Compilation" =>
4020
%%%
@@ -92,7 +72,7 @@ tag := "parser"
9272
Lean's parser is a recursive-descent parser that uses dynamic tables based on Pratt parsing{citep pratt73}[] to resolve operator precedence and associativity.
9373
When grammars are unambiguous, the parser does not need to backtrack; in the case of ambiguous grammars, a memoization table similar to that used in Packrat parsing avoids exponential blowup.
9474
Parsers are highly extensible: users may define new syntax in any command, and that syntax becomes available in the next command.
95-
The open namespaces in the current {tech}[scope] also influences which parsing rules are used, because parser extensions may be set to be active only when a given namespace is open.
75+
The open namespaces in the current {tech}[section scope] also influence which parsing rules are used, because parser extensions may be set to be active only when a given namespace is open.
9676

9777
When ambiguity is encountered, the longest matching parse is selected.
9878
If there is no unique longest match, then both matching parses are saved in the syntax tree in a {deftech}[choice node] to be resolved later by the elaborator.
@@ -127,7 +107,7 @@ Elaboration of both commands and terms may be recursive, both because of command
127107
Command and term elaboration have different capabilities.
128108
Command elaboration may have side effects on an environment, and it has access to run arbitrary computations in {lean}`IO`.
129109
Lean environments contain the usual mapping from names to definitions along with additional data defined in {deftech}[environment extensions], which are additional tables associated with an environment; environment extensions are used to track most other information about Lean code, including {tactic}`simp` lemmas, custom pretty printers, and internals such as the compiler's intermediate representations.
130-
Command elaboration also maintains a message log with the contents of the compiler's informational output, warnings, and errors, a set of {tech}[info trees] that associate metadata with the original syntax (used for interactive features such as displaying proof states, identifier completion, and showing documentation), accumulated debugging traces, the open {tech}[scopes], and some internal state related to macro expansion.
110+
Command elaboration also maintains a message log with the contents of the compiler's informational output, warnings, and errors, a set of {tech}[info trees] that associate metadata with the original syntax (used for interactive features such as displaying proof states, identifier completion, and showing documentation), accumulated debugging traces, the open {tech}[section scopes], and some internal state related to macro expansion.
131111
Term elaboration may modify all of these fields except the open scopes.
132112
Additionally, it has access to all the machinery needed to create fully-explicit terms in the core language from Lean's terse, friendly syntax, including unification, type class instance synthesis, and type checking.
133113

Manual/Intro.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ skip
153153

154154
Identifiers in code examples are hyperlinked to their documentation.
155155

156+
Examples of code with syntax errors are shown with an indicator of where the parser stopped, along with the error message:
157+
```syntaxError intro
158+
def f : Option Nat → Type
159+
| some 0 => Unit
160+
| => Option (f t)
161+
| none => Empty
162+
```
163+
```leanOutput intro
164+
<example>:3:4: expected term
165+
```
166+
156167
## Examples
157168
%%%
158169
tag := "example-boxes"

Manual/Language.lean

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ unknown universe level 'v'
468468
```
469469
:::
470470

471-
In addition to using `autoImplicit`, particular identifiers can be declared as universe variables in a particular {tech}[scope] using the `universe` command.
471+
In addition to using `autoImplicit`, particular identifiers can be declared as universe variables in a particular {tech}[section scope] using the `universe` command.
472472

473473
:::syntax Lean.Parser.Command.universe
474474
```grammar
@@ -712,19 +712,36 @@ tag := "scopes"
712712

713713
::: planned 54
714714

715-
Many commands have an effect for the current {deftech key:="scope"}[_section scope_] (sometimes just called "scope" when clear).
715+
Many commands have an effect for the current {deftech}[_section scope_] (sometimes just called "scope" when clear).
716716
A section scope ends when a namespace ends, a section ends, or a file ends.
717717
They can also be anonymously and locally created via `in`.
718718
Section scopes track the following:
719719
* The {deftech}_current namespace_
720-
* The {deftech}_open namespaces_
720+
* The {deftech key:="open namespace"}_open namespaces_
721721
* The values of all {deftech}_options_
722722
* Variable and universe declarations
723723

724724
This section will describe this mechanism.
725725

726726
:::
727727

728+
:::syntax attrKind (open := false)
729+
Globally-scoped declarations (the default) are in effect whenever the {tech}[module] in which they're established is transitively imported.
730+
They are indicated by the absence of another scope modifier.
731+
```grammar
732+
```
733+
734+
Locally-scoped declarations are in effect only for the extent of the {tech}[section scope] in which they are established.
735+
```grammar
736+
local
737+
```
738+
739+
Scoped declarations are in effect whenever the {tech key:="open namespace"}[namespace] in which they are established is opened.
740+
```grammar
741+
scoped
742+
```
743+
:::
744+
728745
# Axioms
729746

730747
:::planned 78
@@ -774,6 +791,18 @@ This section will describe `partial` and `unsafe` definitions:
774791

775792
:::
776793

794+
# Attributes
795+
%%%
796+
tag := "attributes"
797+
%%%
798+
799+
:::planned 144
800+
* Concrete syntax of {deftech}[attributes]
801+
* Use cases
802+
* Scope
803+
* When can they be added?
804+
:::
805+
777806
{include 0 Manual.Language.Classes}
778807

779808
# Dynamic Typing
@@ -785,3 +814,15 @@ This section will describe `partial` and `unsafe` definitions:
785814
{docstring Dynamic.mk}
786815

787816
{docstring Dynamic.get?}
817+
818+
# Coercions
819+
%%%
820+
tag := "coercions"
821+
%%%
822+
823+
:::planned 146
824+
* {deftech}[Coercions]
825+
* When they are inserted
826+
* Varieties of coercions
827+
* When should each be used?
828+
:::

Manual/Language/Classes.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Here are some typical use cases for type classes:
8282
* A type class can represent a relation between two types that allows them to be used together in some novel way by a library.
8383
The {lean}`Coe` class represents automatically-inserted coercions from one type to another, and {lean}`MonadLift` represents a way to run operations with one kind of effect in a context that expects another kind.
8484
* Type classes can represent a framework of type-driven code generation, where instances for polymorphic types each contribute some portion of a final program.
85-
The {name}`Repr` class defines a canonical pretty-printer for a type, and polymorphic types end up with polymorphic {name}`Repr` instances.
85+
The {name}`Repr` class defines a canonical pretty printer for a type, and polymorphic types end up with polymorphic {name}`Repr` instances.
8686
When pretty printing is finally invoked on an expression with a known concrete type, such as {lean}`List (Nat × (String ⊕ Int))`, the resulting pretty printer contains code assembled from the {name}`Repr` instances for {name}`List`, {name}`Prod`, {name}`Nat`, {name}`Sum`, {name}`String`, and {name}`Int`.
8787

8888
# Class Declarations
@@ -285,7 +285,6 @@ The problem is that a heap constructed with one {name}`Ord` instance may later b
285285

286286
One way to correct this is to making the heap type depend on the selected `Ord` instance:
287287
```lean
288-
289288
structure Heap' (α : Type u) [Ord α] where
290289
contents : Array α
291290

Manual/Language/Classes/InstanceSynth.lean

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ Author: David Thrane Christiansen
77
import VersoManual
88

99
import Manual.Meta
10+
import Manual.Papers
1011

1112

1213
open Manual
1314
open Verso.Genre
1415
open Verso.Genre.Manual
1516

16-
def tabledRes : ArXiv where
17-
title := .concat (inlines!"Tabled typeclass resolution")
18-
authors := #[.concat (inlines!"Daniel Selsam"), .concat (inlines!"Sebastian Ullrich"), .concat (inlines!"Leonardo de Moura")]
19-
year := 2020
20-
id := "2001.04301"
17+
2118

2219
#doc (Manual) "Instance Synthesis" =>
2320
%%%

Manual/Language/Files.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ tag := "keywords-and-identifiers"
8787
%%%
8888
8989
90-
An {deftech}[identifier] consists of one or more identifier components, separated by `'.'`.{index}[identifier]
90+
An {tech}[identifier] consists of one or more identifier components, separated by `'.'`.{index}[identifier]
9191
9292
{deftech}[Identifier components] consist of a letter or letter-like character or an underscore (`'_'`), followed by zero or more identifier continuation characters.
9393
Letters are English letters, upper- or lowercase, and the letter-like characters include a range of non-English alphabetic scripts, including the Greek script which is widely used in Lean, as well as the members of the Unicode letter-like symbol block, which contains a number of double-struck characters (including `ℕ` and `ℤ`) and abbreviations.

0 commit comments

Comments
 (0)