summaryrefslogtreecommitdiff
path: root/pygments
diff options
context:
space:
mode:
authoramitkummer <49096391+amitkummer@users.noreply.github.com>2022-01-03 20:40:34 +0200
committerGitHub <noreply@github.com>2022-01-03 19:40:34 +0100
commite0f4e77e9ce4957385a9ea0f6910f04062fe40f0 (patch)
treecce92b8936266712a5216abd45c275fb82c242ce /pygments
parenta2ff2f095ac522bde768b290a3b6d0de4d828ef7 (diff)
downloadpygments-git-e0f4e77e9ce4957385a9ea0f6910f04062fe40f0.tar.gz
Java: fix lexing of 'record' soft keyword (#2018)
* Java: fix lexing of 'record' soft keyword Refactor the Java lexer to treat `record` as a soft keyword. Previously, the lexer assumed record is a reserved word, even though it is a soft keyword which can be used as a variable name. This refactor lexes record as a keyword only if it appears at the beggining of the line, with some potential other keywords like public and private preceding it. * Remove repetition in capture group * Update test output
Diffstat (limited to 'pygments')
-rw-r--r--pygments/lexers/jvm.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/pygments/lexers/jvm.py b/pygments/lexers/jvm.py
index 74bf00c6..4ffc5c7f 100644
--- a/pygments/lexers/jvm.py
+++ b/pygments/lexers/jvm.py
@@ -37,6 +37,8 @@ class JavaLexer(RegexLexer):
tokens = {
'root': [
+ (r'(^\s*)((?:(?:public|private|protected|static|strictfp)(?:\s+))*)(record)\b',
+ bygroups(Text, using(this), Keyword.Declaration), 'class'),
(r'[^\S\n]+', Text),
(r'//.*?\n', Comment.Single),
(r'/\*.*?\*/', Comment.Multiline),
@@ -58,8 +60,7 @@ class JavaLexer(RegexLexer):
Keyword.Type),
(r'(package)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
(r'(true|false|null)\b', Keyword.Constant),
- (r'(class|interface|record)(\s+)', bygroups(Keyword.Declaration, Text),
- 'class'),
+ (r'(class|interface)\b', Keyword.Declaration, 'class'),
(r'(var)(\s+)', bygroups(Keyword.Declaration, Text),
'var'),
(r'(import(?:\s+static)?)(\s+)', bygroups(Keyword.Namespace, Text),
@@ -89,6 +90,7 @@ class JavaLexer(RegexLexer):
(r'\n', Text)
],
'class': [
+ (r'\s+', Text),
(r'([^\W\d]|\$)[\w$]*', Name.Class, '#pop')
],
'var': [