summaryrefslogtreecommitdiff
path: root/pygments/lexers/theorem.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2023-04-20 14:10:50 +0100
committerGitHub <noreply@github.com>2023-04-20 15:10:50 +0200
commitd5bfdd4cca547fa3e14dea6e89a29be8019efdf5 (patch)
tree7b4365a2af82e605ddd7d0229171a747bf5eb5b5 /pygments/lexers/theorem.py
parent50207e008d92f7a8750a8d080863e5cada0b0fca (diff)
downloadpygments-git-d5bfdd4cca547fa3e14dea6e89a29be8019efdf5.tar.gz
lean: correctly parse expressions nested within attributes (#1817)
Diffstat (limited to 'pygments/lexers/theorem.py')
-rw-r--r--pygments/lexers/theorem.py55
1 files changed, 32 insertions, 23 deletions
diff --git a/pygments/lexers/theorem.py b/pygments/lexers/theorem.py
index beed2e94..529451ad 100644
--- a/pygments/lexers/theorem.py
+++ b/pygments/lexers/theorem.py
@@ -8,7 +8,9 @@
:license: BSD, see LICENSE for details.
"""
-from pygments.lexer import RegexLexer, default, words
+import re
+
+from pygments.lexer import RegexLexer, default, words, include
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
Number, Punctuation, Generic, Whitespace
@@ -399,12 +401,34 @@ class LeanLexer(RegexLexer):
mimetypes = ['text/x-lean']
tokens = {
- 'root': [
+ 'expression': [
(r'\s+', Text),
(r'/--', String.Doc, 'docstring'),
(r'/-', Comment, 'comment'),
(r'--.*?$', Comment.Single),
(words((
+ 'forall', 'fun', 'Pi', 'from', 'have', 'show', 'assume', 'suffices',
+ 'let', 'if', 'else', 'then', 'in', 'with', 'calc', 'match',
+ 'do'
+ ), prefix=r'\b', suffix=r'\b'), Keyword),
+ (words(('sorry', 'admit'), prefix=r'\b', suffix=r'\b'), Generic.Error),
+ (words(('Sort', 'Prop', 'Type'), prefix=r'\b', suffix=r'\b'), Keyword.Type),
+ (words((
+ '(', ')', ':', '{', '}', '[', ']', '⟨', '⟩', '‹', '›', '⦃', '⦄', ':=', ',',
+ )), Operator),
+ (r'[A-Za-z_\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2100-\u214f]'
+ r'[.A-Za-z_\'\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2070-\u2079'
+ r'\u207f-\u2089\u2090-\u209c\u2100-\u214f0-9]*', Name),
+ (r'0x[A-Za-z0-9]+', Number.Integer),
+ (r'0b[01]+', Number.Integer),
+ (r'\d+', Number.Integer),
+ (r'"', String.Double, 'string'),
+ (r"'(?:(\\[\\\"'nt])|(\\x[0-9a-fA-F]{2})|(\\u[0-9a-fA-F]{4})|.)'", String.Char),
+ (r'[~?][a-z][\w\']*:', Name.Variable),
+ (r'\S', Name.Builtin.Pseudo),
+ ],
+ 'root': [
+ (words((
'import', 'renaming', 'hiding',
'namespace',
'local',
@@ -439,31 +463,16 @@ class LeanLexer(RegexLexer):
'set_option',
'run_cmd',
), prefix=r'\b', suffix=r'\b'), Keyword.Declaration),
- (r'@\[[^\]]*\]', Keyword.Declaration),
- (words((
- 'forall', 'fun', 'Pi', 'from', 'have', 'show', 'assume', 'suffices',
- 'let', 'if', 'else', 'then', 'in', 'with', 'calc', 'match',
- 'do'
- ), prefix=r'\b', suffix=r'\b'), Keyword),
- (words(('sorry', 'admit'), prefix=r'\b', suffix=r'\b'), Generic.Error),
- (words(('Sort', 'Prop', 'Type'), prefix=r'\b', suffix=r'\b'), Keyword.Type),
+ (r'@\[', Keyword.Declaration, 'attribute'),
(words((
'#eval', '#check', '#reduce', '#exit',
'#print', '#help',
), suffix=r'\b'), Keyword),
- (words((
- '(', ')', ':', '{', '}', '[', ']', '⟨', '⟩', '‹', '›', '⦃', '⦄', ':=', ',',
- )), Operator),
- (r'[A-Za-z_\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2100-\u214f]'
- r'[.A-Za-z_\'\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2070-\u2079'
- r'\u207f-\u2089\u2090-\u209c\u2100-\u214f0-9]*', Name),
- (r'0x[A-Za-z0-9]+', Number.Integer),
- (r'0b[01]+', Number.Integer),
- (r'\d+', Number.Integer),
- (r'"', String.Double, 'string'),
- (r"'(?:(\\[\\\"'nt])|(\\x[0-9a-fA-F]{2})|(\\u[0-9a-fA-F]{4})|.)'", String.Char),
- (r'[~?][a-z][\w\']*:', Name.Variable),
- (r'\S', Name.Builtin.Pseudo),
+ include('expression')
+ ],
+ 'attribute': [
+ (r'\]', Keyword.Declaration, '#pop'),
+ include('expression'),
],
'comment': [
(r'[^/-]', Comment.Multiline),