Skip to content

Commit

Permalink
Java: make it less operator-heavy
Browse files Browse the repository at this point in the history
Fixes #987
  • Loading branch information
birkenfeld committed Nov 24, 2019
1 parent 35c3833 commit ec982e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Version 2.5.0
- Add LICENSE file to wheel builds
- Emacs Lisp: add more string functions
- Java: support ``var`` contextual keyword
- Java: make structural punctuation (braces, parens, colon, comma)
``Punctuation``, not ``Operator`` (#987)
- Ruby: support squiggly heredocs
- Dart: support ``@`` annotations
- GAS: accept registers in directive arguments
Expand Down
8 changes: 5 additions & 3 deletions pygments/lexers/jvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class JavaLexer(RegexLexer):
(r'((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)' # return arguments
r'((?:[^\W\d]|\$)[\w$]*)' # method name
r'(\s*)(\()', # signature start
bygroups(using(this), Name.Function, Text, Operator)),
bygroups(using(this), Name.Function, Text, Punctuation)),
(r'@[^\W\d][\w.]*', Name.Decorator),
(r'(abstract|const|enum|extends|final|implements|native|private|'
r'protected|public|static|strictfp|super|synchronized|throws|'
Expand All @@ -67,7 +67,8 @@ class JavaLexer(RegexLexer):
'import'),
(r'"(\\\\|\\"|[^"])*"', String),
(r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char),
(r'(\.)((?:[^\W\d]|\$)[\w$]*)', bygroups(Operator, Name.Attribute)),
(r'(\.)((?:[^\W\d]|\$)[\w$]*)', bygroups(Punctuation,
Name.Attribute)),
(r'^\s*([^\W\d]|\$)[\w$]*:', Name.Label),
(r'([^\W\d]|\$)[\w$]*', Name),
(r'([0-9][0-9_]*\.([0-9][0-9_]*)?|'
Expand All @@ -82,7 +83,8 @@ class JavaLexer(RegexLexer):
(r'0[bB][01][01_]*[lL]?', Number.Bin),
(r'0[0-7_]+[lL]?', Number.Oct),
(r'0|[1-9][0-9_]*[lL]?', Number.Integer),
(r'[~^*!%&\[\](){}<>|+=:;,./?-]', Operator),
(r'[~^*!%&\[\]<>|+=/?-]', Operator),
(r'[{}();:.,]', Punctuation),
(r'\n', Text)
],
'class': [
Expand Down
14 changes: 7 additions & 7 deletions tests/test_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import pytest

from pygments.token import Text, Name, Operator, Keyword, Number
from pygments.token import Text, Name, Punctuation, Keyword, Number
from pygments.lexers import JavaLexer


Expand All @@ -18,23 +18,23 @@ def lexer():
yield JavaLexer()


def testEnhancedFor(lexer):
def test_enhanced_for(lexer):
fragment = u'label:\nfor(String var2: var1) {}\n'
tokens = [
(Name.Label, u'label:'),
(Text, u'\n'),
(Keyword, u'for'),
(Operator, u'('),
(Punctuation, u'('),
(Name, u'String'),
(Text, u' '),
(Name, u'var2'),
(Operator, u':'),
(Punctuation, u':'),
(Text, u' '),
(Name, u'var1'),
(Operator, u')'),
(Punctuation, u')'),
(Text, u' '),
(Operator, u'{'),
(Operator, u'}'),
(Punctuation, u'{'),
(Punctuation, u'}'),
(Text, u'\n'),
]
assert list(lexer.get_tokens(fragment)) == tokens
Expand Down

0 comments on commit ec982e5

Please sign in to comment.