Commit graph

41 commits

Author SHA1 Message Date
David Thrane Christiansen
84e46162b5
feat: more infrastructure for tactic documentation (#4490)
This is the groundwork for a tactic index in generated documentation, as
there was in Lean 3. There are a few challenges to getting this to work
well in Lean 4:
* There's no natural notion of *tactic identity* - a tactic may be
specified by multiple syntax rules (e.g. the pattern-matching version of
`intro` is specified apart from the default version, but both are the
same from a user perspective)
* There's no natural notion of *tactic name* - here, we take the
pragmatic choice of using the first keyword atom in the tactic's syntax
specification, but this may need to be overridable someday.
* Tactics are extensible, but we don't want to allow arbitrary imports
to clobber existing tactic docstrings, which could become unpredictable
in practice.

For tactic identity, this PR introduces the notion of a *tactic
alternative*, which is a `syntax` specification that is really "the same
as" an existing tactic, but needs to be separate for technical reasons.
This provides a notion of tactic identity, which we can use as the basis
of a tactic index in generated documentation. Alternative forms of
tactics are specified using a new `@[tactic_alt IDENT]` attribute,
applied to the new tactic syntax. It is an error to declare a tactic
syntax rule to be an alternative of another one that is itself an
alternative. Documentation hovers now take alternatives into account,
and display the docs for the canonical name.

*Tactic tags*, created with the `register_tactic_tag` command, specify
tags that may be applied to tactics. This is intended to be used by
doc-gen and Verso. Tags may be applied using the `@[tactic_tag TAG1 TAG2
...]` attribute on a canonical tactic parser, which may be used in any
module to facilitate downstream projects introducing tags that apply to
pre-existing tactics. Tags may not be removed, but it's fine to
redundantly add them. The collection of tags, and the tactics to which
they're applied, can be seen using the `#print tactic tags` command.

*Extension documentation* provides a structured way to document
extensions to tactics. The resulting documentation is gathered into a
bulleted list at the bottom of the tactic's docstring. Extensions are
added using the `tactic_extension TAC` command. This can be used when
adding new interpretations of a tactic via `macro_rules`, when extending
some table or search index used by the tactic, or in any other way. It
is a command to facilitate its flexible use with various extension
mechanisms.
2024-06-21 12:49:30 +00:00
David Thrane Christiansen
966fa800f8
chore: remove the coercion from String to Name (#3589)
This coercion caused difficult-to-diagnose bugs sometimes. Because there
are some situations where converting a string to a name should be done
by parsing the string, and others where it should not, an explicit
choice seems better here.

---------

Co-authored-by: Mac Malone <tydeu@hatpress.net>
2024-03-21 23:46:03 +00:00
David Thrane Christiansen
74e7886ce7
feat: custom error recovery in parser (#3413)
Adds a simple error-recovery mechanism to Lean's parser, similar to
those used in other combinator parsing libraries.

Lean itself isn't very amenable to error recovery with this mechanism,
as it requires global knowledge of the grammar in question to write
recovery rules that don't break backtracking or `<|>`. I only found a
few opportunities.

But for DSLs, this is really important. In particular, Verso parse
errors interacted very badly with Lean parse errors in a way that
required frequent "restart file" commands, but this mechanism allows me
to both recover from Verso parse errors and to have Lean skip the rest
of the file rather than repeatedly trying to parse it as Lean commands.
2024-02-21 14:29:54 +00:00
Henrik Böving
23e49eb519 perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Mario Carneiro
c20a7bf305 feat: hygieneInfo parser (aka this 2.0) 2023-06-02 16:19:02 +02:00
Sebastian Ullrich
b8ebfbfecc chore: improve pretty printer antiquotation support 2022-10-28 21:25:47 +02:00
Mario Carneiro
765ebcdbf0 feat: use withoutPosition consistently 2022-10-24 12:51:32 -07:00
Mario Carneiro
583e023314 chore: snake-case attributes (part 2) 2022-10-19 09:28:08 -07:00
Gabriel Ebner
b1bef71d59 feat: colEq parser 2022-09-19 12:44:43 -07:00
Mario Carneiro
0738136446 feat: add lineEq parser alias 2022-08-12 08:15:28 -07:00
Mario Carneiro
59b32da2d9 feat: go to def on parser aliases 2022-08-06 12:44:14 +02:00
Sebastian Ullrich
29bdc0ceac fix: bound syntax kind at v:(ppSpace ident) etc. 2022-07-07 11:49:35 +02:00
Sebastian Ullrich
eab64997cd fix: auto-group syntax parsers where necessary 2022-06-28 11:50:59 +02:00
Sebastian Ullrich
7d48d125da fix: store syntax kinds of parser aliases in order to construct correct antiquotations in macro and elab 2022-06-27 22:37:02 +02:00
Sebastian Ullrich
292d24ba19 feat: always store quoted kind in antiquotation kind 2022-06-27 22:37:02 +02:00
Leonardo de Moura
041827bed5 chore: unused variables 2022-06-07 17:54:10 -07:00
Sebastian Ullrich
ae7b895f7a refactor: unname some unused variables 2022-06-07 16:37:45 -07:00
Sebastian Ullrich
24697026e8 feat: always accept antiquotations, simplify quotDepth code 2022-04-06 19:43:07 +02:00
Leonardo de Moura
48a3668780 chore: fix repo 2022-04-01 11:24:30 -07:00
Sebastian Ullrich
e9b8e54dcc feat: scientific parser alias for scientificLit 2022-03-08 18:54:05 +01:00
Sebastian Ullrich
585fba69e8 refactor: remove redundancy from common register_parser_alias case
/cc @leodemoura
2021-09-20 13:20:23 +02:00
Sebastian Ullrich
83c2e8bf75 feat: expose many(1)Indent as parser aliases 2021-09-20 13:20:23 +02:00
Sebastian Ullrich
5866e2bbb7 chore: use register_parser_alias where possible
Fixes #494
2021-07-22 16:28:06 +02:00
Sebastian Ullrich
f0960b7f89 fix: ignore antiquotations outside quotations 2021-04-29 13:33:48 +02:00
Sebastian Ullrich
725c0c1911 chore: implement lhs prec 2021-03-22 16:33:37 +01:00
Leonardo de Moura
9daed5e91d chore: add checkLinebreakBefore 2021-03-18 06:43:03 -07:00
Sebastian Ullrich
4dfa7e1187 feat: use actual separator in sepBy antiquotation scope 2020-12-09 17:48:05 +01:00
Sebastian Ullrich
92cbe27810 refactor: clean up & delay registering parser aliases 2020-12-04 19:24:32 +01:00
Leonardo de Moura
b95c4788c1 refactor: OfDecimal ==> OfScientific
`decimalLit` ==> `scientificLit`
2020-12-03 08:08:19 -08:00
Leonardo de Moura
85c9ab072c feat: elaborate and delaborate decimals 2020-12-02 15:31:06 -08:00
Leonardo de Moura
13c2a8ff51 chore: remove #lang lean4 header 2020-10-25 09:54:07 -07:00
Sebastian Ullrich
997365b622 chore: remove lone #check 2020-10-22 15:58:53 +02:00
Leonardo de Moura
21e6ae645a chore: move to new frontend 2020-10-21 15:14:13 -07:00
Leonardo de Moura
2d8506b7c6 feat: add doElem parser category 2020-09-26 06:18:44 -07:00
Sebastian Ullrich
4f5d1cf369 chore: finish formatter refactoring 2020-08-20 15:47:43 +02:00
Sebastian Ullrich
aa452b795d refactor: make formatter precompiled as well 2020-08-20 15:29:33 +02:00
Sebastian Ullrich
1840b4b1ff fix: pretty printer with new syntax 2020-08-19 09:56:23 -07:00
Sebastian Ullrich
46f5670ba3 chore: Lean.Parser.Parser ~> Lean.Parser.Basic 2020-08-13 18:44:13 +02:00
Sebastian Ullrich
aefe710caf feat: close the loop 2020-08-12 09:15:59 -07:00
Leonardo de Moura
249bda16c0 chore: remove prelude commands from Lean package 2020-06-25 11:21:17 -07:00
Leonardo de Moura
4ccc3fef52 chore: move Init.Lean files to Lean package 2020-05-26 15:04:35 -07:00