summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pygments/lexers/agile.py40
-rw-r--r--pygments/lexers/web.py1
-rw-r--r--tests/examplefiles/test.rb18
3 files changed, 43 insertions, 16 deletions
diff --git a/pygments/lexers/agile.py b/pygments/lexers/agile.py
index 7275ea28..5c91ebf9 100644
--- a/pygments/lexers/agile.py
+++ b/pygments/lexers/agile.py
@@ -402,10 +402,18 @@ class RubyLexer(ExtendedRegexLexer):
'root': [
(r'#.*?$', Comment.Single),
(r'=begin\n.*?\n=end', Comment.Multiline),
+ # keywords
(r'(BEGIN|END|alias|begin|break|case|defined\?|'
r'do|else|elsif|end|ensure|for|if|in|next|redo|'
r'rescue|raise|retry|return|super|then|undef|unless|until|when|'
r'while|yield)\b', Keyword),
+ # start of function, class and module names
+ (r'(module)(\s+)([a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*)',
+ bygroups(Keyword, Text, Name.Namespace)),
+ (r'(def)(\s+)', bygroups(Keyword, Text), 'funcname'),
+ (r'def(?=[*%&^`~+-/\[<>=])', Keyword, 'funcname'),
+ (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
+ # special methods
(r'(initialize|new|loop|include|extend|raise|attr_reader|'
r'attr_writer|attr_accessor|attr|catch|throw|private|'
r'module_function|public|protected|true|false|nil)\b', Keyword.Pseudo),
@@ -474,13 +482,18 @@ class RubyLexer(ExtendedRegexLexer):
# lex numbers and ignore following regular expressions which
# are division operators in fact (grrrr. i hate that. any
# better ideas?)
- (r'(0_?[0-7]+(?:_[0-7]+)*)(\s*)(/)?',
+ # since pygments 0.7 we also eat a "?" operator after numbers
+ # so that the char operator does not work. Chars are not allowed
+ # there so that you can use the terner operator.
+ # stupid example:
+ # x>=0?n[x]:""
+ (r'(0_?[0-7]+(?:_[0-7]+)*)(\s*)([/?])?',
bygroups(Number.Oct, Text, Operator)),
- (r'(0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*)(\s*)(/)?',
+ (r'(0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*)(\s*)([/?])?',
bygroups(Number.Hex, Text, Operator)),
- (r'(0b[01]+(?:_[01]+)*)(\s*)(/)?',
+ (r'(0b[01]+(?:_[01]+)*)(\s*)([/?])?',
bygroups(Number.Bin, Text, Operator)),
- (r'([\d]+(?:_\d+)*)(\s*)(/)?',
+ (r'([\d]+(?:_\d+)*)(\s*)([/?])?',
bygroups(Number.Integer, Text, Operator)),
# Names
(r'@@[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable.Class),
@@ -498,23 +511,20 @@ class RubyLexer(ExtendedRegexLexer):
(r'[A-Z][a-zA-Z0-9_]+', Name.Constant),
# this is needed because ruby attributes can look
# like keywords (class) or like this: ` ?!?
- (r'(?<=\.)([a-zA-Z_]\w*[\!\?]?|[*%&^`~+-/\[<>=])', Name),
- # module name
- (r'(module)(\s+)([a-zA-Z_]\w*)', bygroups(Keyword, Text, Name.Namespace)),
- # start of function name, a bit tricky
- (r'(def)(\s+)', bygroups(Keyword, Text), 'funcname'),
- (r'def(?=[*%&^`~+-/\[<>=])', Keyword, 'funcname'),
- (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
+ (r'(\.|::)([a-zA-Z_]\w*[\!\?]?|[*%&^`~+-/\[<>=])',
+ bygroups(Operator, Name)),
(r'[a-zA-Z_][\w_]*[\!\?]?', Name),
- (r'(\[\]|\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|'
+ (r'(\[|\]|\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|'
r'!~|&&?|\|\||\.{1,3})', Operator),
(r'[-+/*%=<>&!^|~]=?', Operator),
- (r'[\[\](){};,/?:\\]', Punctuation),
+ (r'[(){};,/?:\\]', Punctuation),
(r'\s+', Text)
],
'funcname': [
- (r'([a-zA-Z_][\w_]*[\!\?]?|\*\*?|[-+]@?|'
- r'[/%&|^`~]|\[\]=?|<<|>>|<=?>|>=?|===?)', Name.Function, '#pop')
+ (r'(?:([a-zA-Z_][a-zA-Z0-9_]*)(\.))?'
+ r'([a-zA-Z_][\w_]*[\!\?]?|\*\*?|[-+]@?|'
+ r'[/%&|^`~]|\[\]=?|<<|>>|<=?>|>=?|===?)',
+ bygroups(Name.Class, Operator, Name.Function), '#pop')
],
'classname': [
(r'<<', Operator, '#pop'),
diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py
index 09374209..bbd6d76e 100644
--- a/pygments/lexers/web.py
+++ b/pygments/lexers/web.py
@@ -230,6 +230,7 @@ class HtmlLexer(RegexLexer):
'tag': [
(r'\s+', Text),
(r'[a-zA-Z0-9_:-]+\s*=', Name.Attribute, 'attr'),
+ (r'[a-zA-Z0-9_:-]+', Name.Attribute),
(r'/?\s*>', Name.Tag, '#pop'),
],
'script-content': [
diff --git a/tests/examplefiles/test.rb b/tests/examplefiles/test.rb
index cf365af7..1f609e32 100644
--- a/tests/examplefiles/test.rb
+++ b/tests/examplefiles/test.rb
@@ -1,6 +1,6 @@
a.each{|el|anz[el]=anz[el]?anz[el]+1:1}
while x<10000
-#a bis f dienen dazu die Nachbarschaft festzulegen. Man stelle sich die #Zahl von 1 bis 64 im Binärcode vor 1 bedeutet an 0 aus
+#a bis f dienen dazu die Nachbarschaft festzulegen. Man stelle sich die #Zahl von 1 bis 64 im Binärcode vor 1 bedeutet an 0 aus
b=(p[x]%32)/16<1 ? 0 : 1
(x-102>=0? n[x-102].to_i : 0)*a+(x-101>=0?n[x-101].to_i : 0)*e+n[x-100].to_i+(x-99>=0? n[x-99].to_i : 0)*f+(x-98>=0? n[x-98].to_i : 0)*a+
@@ -21,6 +21,22 @@ sleep(10)
1E1E1
puts 30.send(:/, 5) # prints 6
+# fun with class attributes
+class Foo
+ def self.blub x
+ if not x.nil?
+ self.new
+ end
+ end
+ def another_way_to_get_class
+ self.class
+ end
+end
+
+# ruby 1.9 "call operator"
+a = Proc.new { 42 }
+a.()
+
"instance variables can be #@included, #@@class_variables\n and #$globals as well."
`instance variables can be #@included, #@@class_variables\n and #$globals as well.`
'instance variables can be #@included, #@@class_variables\n and #$globals as well.'