Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lexer for Lean 4 #2618

Merged
merged 20 commits into from Jan 14, 2024
Merged

Add a lexer for Lean 4 #2618

merged 20 commits into from Jan 14, 2024

Conversation

eric-wieser
Copy link
Contributor

@eric-wieser eric-wieser commented Dec 30, 2023

This is taken from https://github.com/leanprover/lean4/blob/d92948bc20b12f53542814c79469711ceff19fbf/doc/latex/lean4.py, with subsequent commits showing the changes made on top of this file

For that reason, I'd prefer if the history could be preserved; though I'd be happy to rewrite it if you want fewer commits / different message conventions.

The test file I'd added is the lean4 translation of the test file that was being used for Lean 3.

Since lean3 and lean4 files share a file extension, this adds analyse_text methods that discriminate based on import Foo vs import foo; this is the same heuristic used by GitHub linguist.

cc @Kha

Kha and others added 4 commits December 30, 2023 22:53
There is no need for `re.UNICODE` any more, or `u` prefixes.
The version and url information no longer lives in the docstring.
This allows a lean4 version of the lean3 test to be committed
* Use `Whitespace` not `Text` for Whitespace
* Use a single token for an entire multiline comment, not one per character
* Fix brace-matching for `@[attr]` syntax
* Add docstring highlighting
Copy link

@Julian Julian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This looks pretty good. I'm sure I've missed a thing or two, but I tried to double check the keyword list and give a cursory look over the token list which pretty much looks good!

pygments/lexers/lean.py Show resolved Hide resolved
pygments/lexers/lean.py Outdated Show resolved Hide resolved
pygments/lexers/lean.py Outdated Show resolved Hide resolved
pygments/lexers/lean.py Show resolved Hide resolved
@cmarqu
Copy link
Contributor

cmarqu commented Jan 9, 2024

Maybe also add a line to the CHANGES file.

Copy link

@Julian Julian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. This LGTM at this point I think (with or without the operator tweaking)!

pygments/lexers/lean.py Outdated Show resolved Hide resolved
pygments/lexers/lean.py Outdated Show resolved Hide resolved
(r'\d+', Number.Integer),
(r'"', String.Double, 'string'),
(r'[~?][a-z][\w\']*:', Name.Variable),
(r'\S', Name.Builtin.Pseudo),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this rule for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arbitrary notation defined by the user; without it, all such notation would be marked as invalid

@jeanas
Copy link
Contributor

jeanas commented Jan 13, 2024

This looks generally good, only a couple minor questions above.

Copy link
Contributor

@jeanas jeanas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. Thank you!

@jeanas jeanas merged commit 965b7bc into pygments:master Jan 14, 2024
13 checks passed
@eric-wieser
Copy link
Contributor Author

Thanks! I've made a small follow-up in #2626; it would be great if they could both land in the coming release.

@jeanas
Copy link
Contributor

jeanas commented Jan 14, 2024

Sure, this will all be in 2.18.

@Anteru Anteru added this to the 2.18.0 milestone Apr 28, 2024
github-merge-queue bot pushed a commit to leanprover/lean4 that referenced this pull request May 20, 2024
An improved `lean4` lexer is now part of pygments.

This depends on pygments/pygments#2618 (now
merged), and [a subsequent
release](https://github.com/pygments/pygments/milestone/23)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants