Skip to content

Commit

Permalink
update the name regex too
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-wieser committed Dec 30, 2023
1 parent 5597cdb commit d0e9946
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pygments/lexers/lean.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ class Lean4Lexer(RegexLexer):
mimetypes = ['text/x-lean4']
version_added = '2.18'

# TODO: update this regex for Lean 4
_name = Lean3Lexer._name
_name_segment = Lean3Lexer._name_segment

keywords1 = (
'import', 'abbreviation', 'opaque_hint', 'tactic_hint', 'definition',
'renaming', 'inline', 'hiding', 'parameter', 'lemma', 'variable',
Expand All @@ -163,7 +167,7 @@ class Lean4Lexer(RegexLexer):
)

operators = (
'!=', '#', '&', '&&', '*', '+', '-', '/', '@', '!', '`',
'!=', '#', '&', '&&', '*', '+', '-', '/', '@', '!',
'-.', '->', '.', '..', '...', '::', ':>', ';', ';;', '<',
'<-', '=', '==', '>', '_', '|', '||', '~', '=>', '<=', '>=',
'/\\', '\\/', '∀', 'Π', 'λ', '↔', '∧', '∨', '≠', '≤', '≥',
Expand All @@ -183,9 +187,8 @@ class Lean4Lexer(RegexLexer):
(words(keywords3, prefix=r'\b', suffix=r'\b'), Keyword.Type),
(words(operators), Name.Builtin.Pseudo),
(words(punctuation), Operator),
("[A-Za-z_\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2100-\u214f]"
"[A-Za-z_'\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2070-\u2079"
"\u207f-\u2089\u2090-\u209c\u2100-\u214f0-9]*", Name),
(_name_segment, Name),
(r'``?' + _name, String.Symbol),
(r'\d+', Number.Integer),
(r'"', String.Double, 'string'),
(r'[~?][a-z][\w\']*:', Name.Variable),
Expand Down
5 changes: 5 additions & 0 deletions tests/examplefiles/lean4/Test.lean
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,8 @@ theorem IsChain.exists_maxChain (hc : IsChain r c) : ∃ M, @IsMaxChain _ r M
-- other bits of tricky syntax
@[to_additive "See note [foo]"]
lemma mul_one : sorry := sorry
variable {ι A B : Type*} (𝒜 : ι → A) (ℬ : ι → B)
#check `𝒜.a
#check ``𝒜
52 changes: 52 additions & 0 deletions tests/examplefiles/lean4/Test.lean.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d0e9946

Please sign in to comment.