summaryrefslogtreecommitdiff
path: root/pygments/lexers/ruby.py
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2014-10-06 20:12:55 -0700
committerTim Hatch <tim@timhatch.com>2014-10-06 20:12:55 -0700
commit335ae1e0f099b523ed362734300a8bed1cc54a7e (patch)
treee330ddfba95d366064307810c993ecd4457ee3eb /pygments/lexers/ruby.py
parentad76a6679d2092f197e4503e5ededffafb87983b (diff)
downloadpygments-335ae1e0f099b523ed362734300a8bed1cc54a7e.tar.gz
RubyLexer: Highlight operator methods better.
Fixes #1033
Diffstat (limited to 'pygments/lexers/ruby.py')
-rw-r--r--pygments/lexers/ruby.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/pygments/lexers/ruby.py b/pygments/lexers/ruby.py
index 52ba23ad..88cbafec 100644
--- a/pygments/lexers/ruby.py
+++ b/pygments/lexers/ruby.py
@@ -22,6 +22,11 @@ __all__ = ['RubyLexer', 'RubyConsoleLexer', 'FancyLexer']
line_re = re.compile('.*?\n')
+RUBY_OPERATORS = (
+ '*', '**', '-', '+', '-@', '+@', '/', '%', '&', '|', '^', '`', '~',
+ '[]', '[]=', '<<', '>>', '<', '<>', '<=>', '>', '>=', '==', '==='
+)
+
class RubyLexer(ExtendedRegexLexer):
"""
For `Ruby <http://www.ruby-lang.org>`_ source code.
@@ -100,8 +105,8 @@ class RubyLexer(ExtendedRegexLexer):
states = {}
states['strings'] = [
# easy ones
- (r'\:@{0,2}([a-zA-Z_]\w*[\!\?]?|\*\*?|[-+]@?|'
- r'[/%&|^`~]|\[\]=?|<<|>>|<=?>|>=?|===?)', String.Symbol),
+ (r'\:@{0,2}[a-zA-Z_]\w*[\!\?]?', String.Symbol),
+ (words(RUBY_OPERATORS, prefix=r'\:@{0,2}'), String.Symbol),
(r":'(\\\\|\\'|[^'])*'", String.Symbol),
(r"'(\\\\|\\'|[^'])*'", String.Single),
(r':"', String.Symbol, 'simple-sym'),
@@ -306,6 +311,8 @@ class RubyLexer(ExtendedRegexLexer):
(r'[A-Z]\w+', Name.Constant),
# this is needed because ruby attributes can look
# like keywords (class) or like this: ` ?!?
+ (words(RUBY_OPERATORS, prefix=r'(\.|::)'),
+ bygroups(Operator, Name.Operator)),
(r'(\.|::)([a-zA-Z_]\w*[\!\?]?|[*%&^`~+\-/\[<>=])',
bygroups(Operator, Name)),
(r'[a-zA-Z_]\w*[\!\?]?', Name),