lib/rouge/lexers/java.rb in rouge-1.10.1 vs lib/rouge/lexers/java.rb in rouge-1.11.0
- old
+ new
@@ -23,27 +23,30 @@
types = %w(boolean byte char double float int long short void)
id = /[a-zA-Z_][a-zA-Z0-9_]*/
state :root do
- rule %r(^
- (\s*(?:[a-zA-Z_][a-zA-Z0-9_.\[\]]*\s+)+?) # return arguments
+ rule /[^\S\n]+/, Text
+ rule %r(//.*?$), Comment::Single
+ rule %r(/\*.*?\*/)m, Comment::Multiline
+ # keywords: go before method names to avoid lexing "throw new XYZ"
+ # as a method signature
+ rule /(?:#{keywords.join('|')})\b/, Keyword
+
+ rule %r(
+ (\s*(?:[a-zA-Z_][a-zA-Z0-9_.\[\]<>]*\s+)+?) # return arguments
([a-zA-Z_][a-zA-Z0-9_]*) # method name
(\s*)(\() # signature start
)mx do |m|
# TODO: do this better, this shouldn't need a delegation
delegate Java, m[1]
token Name::Function, m[2]
token Text, m[3]
- token Punctuation, m[4]
+ token Operator, m[4]
end
- rule /\s+/, Text
- rule %r(//.*?$), Comment::Single
- rule %r(/\*.*?\*/)m, Comment::Multiline
rule /@#{id}/, Name::Decorator
- rule /(?:#{keywords.join('|')})\b/, Keyword
rule /(?:#{declarations.join('|')})\b/, Keyword::Declaration
rule /(?:#{types.join('|')})\b/, Keyword::Type
rule /package\b/, Keyword::Namespace
rule /(?:true|false|null)\b/, Keyword::Constant
rule /(?:class|interface)\b/, Keyword::Declaration, :class
@@ -57,10 +60,10 @@
rule /\$?#{id}/, Name
rule /[~^*!%&\[\](){}<>\|+=:;,.\/?-]/, Operator
rule /[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, Num::Float
rule /0x[0-9a-f]+/, Num::Hex
rule /[0-9]+L?/, Num::Integer
- # rule /\n/, Text
+ rule /\n/, Text
end
state :class do
rule /\s+/m, Text
rule id, Name::Class, :pop!