Skip to content

Commit

Permalink
Reduce duplicated range warnings (#1189)
Browse files Browse the repository at this point in the history
This updates a large number of the lexers to reduce the number of
"character class has duplicated range" warnings.
  • Loading branch information
ashmaroli authored and pyrmont committed Jun 19, 2019
1 parent c7c8ec3 commit 056070e
Show file tree
Hide file tree
Showing 26 changed files with 45 additions and 42 deletions.
4 changes: 2 additions & 2 deletions lib/rouge/lexers/abap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def self.new_keywords
rule %r(^\*.*), Comment::Multiline
rule %r/\d+/, Num::Integer
rule %r/('|`)/, Str::Single, :single_string
rule %r/[\[\]\(\)\{\}\[\]\.,:\|]/, Punctuation
rule %r/[\[\]\(\)\{\}\.,:\|]/, Punctuation

# builtins / new ABAP 7.40 keywords (@DATA(), ...)
rule %r/(->|=>)?([A-Za-z][A-Za-z0-9_\-]*)(\()/ do |m|
Expand All @@ -207,7 +207,7 @@ def self.new_keywords
end

# keywords, types and normal text
rule %r/\w[\w\d]*/ do |m|
rule %r/\w\w*/ do |m|
if self.class.keywords.include? m[0].upcase
token Keyword
elsif self.class.types.include? m[0].downcase
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/biml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def self.detect?(text)
state :directive_tag do
rule %r/\s+/m, Text
rule %r/[\w.:-]+\s*=/m, Name::Attribute, :attr
rule %r/[\w]+\s*/m, Name::Attribute
rule %r/\w+\s*/m, Name::Attribute
rule %r(/?\s*#>), Name::Tag, :pop!
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/bsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Bsl < RegexLexer
rule %r(//.*$), Comment::Single
rule %r/[\[\]:(),;]/, Punctuation
rule %r/(?<=[^\wа-яё]|^)\&.*$/, Keyword::Declaration
rule %r/[-+\/=<>*%=<>.?&]/, Operator
rule %r/[-+\/*%=<>.?&]/, Operator
rule %r/(?<=[^\wа-яё]|^)\#.*$/, Keyword::Declaration
rule KEYWORDS, Keyword
rule BUILTINS, Name::Builtin
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/ceylon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Ceylon < RegexLexer
rule %r([a-zA-Z_]\w*:), Name::Label
rule %r((\\I[a-z]|[A-Z])\w*), Name::Decorator
rule %r([a-zA-Z_]\w*), Name
rule %r([~^*!%&\[\](){}<>|+=:;,./?-`]), Operator
rule %r([~^*!%&\[\](){}<>|+=:;,./?`-]), Operator
rule %r(\d{1,3}(_\d{3})+\.\d{1,3}(_\d{3})+[kMGTPmunpf]?), Literal::Number::Float
rule %r(\d{1,3}(_\d{3})+\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?),
Literal::Number::Float
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/conf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Conf < RegexLexer
rule %r/'.*?'/, Str::Single
rule %r/[a-z]\w*/i, Name
rule %r/\d+/, Num
rule %r/[^\d\w#"']+/, Text
rule %r/[^\w#"']+/, Text
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rouge/lexers/crystal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ def self.detect?(text)
rule %r/\s+/, Text
rule %r/\(/, Punctuation, :defexpr
rule %r(
(?:([a-zA-Z_][\w_]*)(\.))?
(?:([a-zA-Z_]\w*)(\.))?
(
[a-zA-Z_][\w_]*[!?]? |
[a-zA-Z_]\w*[!?]? |
\*\*? | [-+]@? | [/%&\|^`~] | \[\]=? |
<<? | >>? | <=>? | >= | ===?
)
Expand Down
4 changes: 2 additions & 2 deletions lib/rouge/lexers/dart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Dart < RegexLexer
state :root do
rule %r(^
(\s*(?:[a-zA-Z_][a-zA-Z\d_.\[\]]*\s+)+?) # return arguments
([a-zA-Z_][\w]*) # method name
(\s*)(\() # signature start
([a-zA-Z_]\w*) # method name
(\s*)(\() # signature start
)mx do |m|
# TODO: do this better, this shouldn't need a delegation
delegate Dart, m[1]
Expand Down
5 changes: 3 additions & 2 deletions lib/rouge/lexers/elixir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Elixir < RegexLexer
rule %r/:"/, Str::Symbol, :interpoling_symbol
rule %r/\b(nil|true|false)\b(?![?!])|\b[A-Z]\w*\b/, Name::Constant
rule %r/\b(__(FILE|LINE|MODULE|MAIN|FUNCTION)__)\b(?![?!])/, Name::Builtin::Pseudo
rule %r/[a-zA-Z_!][\w_]*[!\?]?/, Name
rule %r/[a-zA-Z_!]\w*[!\?]?/, Name
rule %r{::|[%(){};,/\|:\\\[\]]}, Punctuation
rule %r/@[a-zA-Z_]\w*|&\d/, Name::Variable
rule %r{\b(0[xX][0-9A-Fa-f]+|\d(_?\d)*(\.(?![^\d\s])
Expand Down Expand Up @@ -117,7 +117,8 @@ class Elixir < RegexLexer
rule %r/[\\#]/, toktype
end

rule %r/[^##{open}#{close}\\]+/m, toktype
uniq_chars = "#{open}#{close}".squeeze
rule %r/[^##{uniq_chars}\\]+/m, toktype
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rouge/lexers/elm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ module exposing port
rule %r/\b(#{keywords.join('|')})\b/, Keyword

# Variable or a function
rule %r/[a-z][\w]*/, Name
rule %r/[a-z]\w*/, Name
# Underscore is a name for a variable, when it won't be used later
rule %r/_/, Name
# Type
rule %r/[A-Z][\w]*/, Keyword::Type
rule %r/[A-Z]\w*/, Keyword::Type

# Two symbol operators: -> :: // .. && || ++ |> <| << >> == /= <= >=
rule %r/(->|::|\/\/|\.\.|&&|\|\||\+\+|\|>|<\||>>|<<|==|\/=|<=|>=)/, Operator
Expand Down
4 changes: 2 additions & 2 deletions lib/rouge/lexers/fortran.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def self.intrinsics
end

state :root do
rule %r/[\s\n]+/, Text::Whitespace
rule %r/[\s]+/, Text::Whitespace
rule %r/!.*$/, Comment::Single
rule %r/^#.*$/, Comment::Preproc

Expand Down Expand Up @@ -169,7 +169,7 @@ def self.intrinsics
rule %r/\(/, Punctuation, :format_spec
rule %r/\)/, Punctuation, :pop!
rule %r/,/, Punctuation
rule %r/[\s\n]+/, Text::Whitespace
rule %r/[\s]+/, Text::Whitespace
# Edit descriptors could be seen as a kind of "format literal".
rule %r/[^\s'"(),]+/, Literal
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Go < RegexLexer

# Characters

WHITE_SPACE = /[\s\t\r\n]+/
WHITE_SPACE = /\s+/

NEWLINE = /\n/
UNICODE_CHAR = /[^\n]/
Expand Down
10 changes: 5 additions & 5 deletions lib/rouge/lexers/groovy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def self.constants

state :root do
rule %r(^
(\s*(?:\w[\w\d.\[\]]*\s+)+?) # return arguments
(\w[\w\d]*) # method name
(\s*(?:\w[\w.\[\]]*\s+)+?) # return arguments
(\w\w*) # method name
(\s*) (\() # signature start
)x do |m|
delegate self.clone, m[1]
Expand All @@ -57,7 +57,7 @@ def self.constants
rule %r/[^\S\n]+/, Text
rule %r(//.*?$), Comment::Single
rule %r(/[*].*?[*]/)m, Comment::Multiline
rule %r/@\w[\w\d.]*/, Name::Decorator
rule %r/@\w[\w.]*/, Name::Decorator
rule %r/(class|interface|trait)\b/, Keyword::Declaration, :class
rule %r/package\b/, Keyword::Namespace, :import
rule %r/import\b/, Keyword::Namespace, :import
Expand Down Expand Up @@ -101,12 +101,12 @@ def self.constants

state :class do
rule %r/\s+/, Text
rule %r/\w[\w\d]*/, Name::Class, :pop!
rule %r/\w\w*/, Name::Class, :pop!
end

state :import do
rule %r/\s+/, Text
rule %r/[\w\d.]+[*]?/, Name::Namespace, :pop!
rule %r/[\w.]+[*]?/, Name::Namespace, :pop!
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rouge/lexers/idlang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def self.routines
end

state :root do
rule %r/[\s\n]+/, Text::Whitespace
rule %r/\s+/, Text::Whitespace
# Normal comments
rule %r/;.*$/, Comment::Single
rule %r/\,\s*\,/, Error
Expand Down Expand Up @@ -303,7 +303,7 @@ def self.routines
rule %r/\(/, Punctuation, :format_spec
rule %r/\)/, Punctuation, :pop!
rule %r/,/, Punctuation
rule %r/[\s\n]+/, Text::Whitespace
rule %r/\s+/, Text::Whitespace
# Edit descriptors could be seen as a kind of "format literal".
rule %r/[^\s'"(),]+/, Literal
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/julia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def self.detect?(text)
| !== | =>
/x

PUNCTUATION = / [ \[ \] { } \( \) , ; ] /x
PUNCTUATION = /[\[\]{}\(\),;]/


state :root do
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/m68k.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def self.builtins
end

state :inline_whitespace do
rule %r/[\s\t\r]+/, Text
rule %r/\s+/, Text
end

state :whitespace do
Expand Down
4 changes: 2 additions & 2 deletions lib/rouge/lexers/moonscript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def builtins
end

state :base do
ident = '(?:[\w_][\w\d_]*)'
ident = '(?:\w\w*)'

rule %r((?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?'), Num::Float
rule %r((?i)\d+e[+-]?\d+), Num::Float
rule %r((?i)0x[0-9a-f]*), Num::Hex
rule %r(\d+), Num::Integer
rule %r(@#{ident}*), Name::Variable::Instance
rule %r([A-Z][\w\d_]*), Name::Class
rule %r([A-Z]\w*), Name::Class
rule %r("?[^"]+":), Literal::String::Symbol
rule %r(#{ident}:), Literal::String::Symbol
rule %r(:#{ident}), Literal::String::Symbol
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/nim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def self.underscorize(words)
Punctuation)

# Strings
rule(/(?:[\w]+)"/,Str, :rdqs)
rule(/(?:\w+)"/,Str, :rdqs)
rule(/"""/, Str, :tdqs)
rule(/"/, Str, :dqs)

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/plist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Plist < RegexLexer
rule %r/"([^"\\]|\\.)*"/, Literal::String::Double
rule %r/'([^'\\]|\\.)*'/, Literal::String::Single
rule %r/</, Punctuation, :data
rule %r{[\w_$/:.-]+}, Literal
rule %r{[\w$/:.-]+}, Literal
end

state :dictionary do
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/pony.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class compiler_intrinsic consume continue
)

state :whitespace do
rule %r/[\s\t\r\n]+/m, Text
rule %r/\s+/m, Text
end

state :root do
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/praat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def self.detect?(text)
end

state :string_interpolated do
rule %r/'[\._a-z][^\[\]'":]*(\[([\d,]+|"[\w\d,]+")\])?(:[0-9]+)?'/, Literal::String::Interpol
rule %r/'[\._a-z][^\[\]'":]*(\[([\d,]+|"[\w,]+")\])?(:[0-9]+)?'/, Literal::String::Interpol
end

state :string_unquoted do
Expand Down
6 changes: 4 additions & 2 deletions lib/rouge/lexers/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def self.detect?(text)
token toktype

push do
rule %r/\\[##{open}#{close}\\]/, Str::Escape
uniq_chars = "#{open}#{close}".squeeze
uniq_chars = '' if open == close && open == "\\#"
rule %r/\\[##{uniq_chars}\\]/, Str::Escape
# nesting rules only with asymmetric delimiters
if open != close
rule %r/#{open}/ do
Expand All @@ -74,7 +76,7 @@ def self.detect?(text)
rule %r/[\\#]/, toktype
end

rule %r/[^##{open}#{close}\\]+/m, toktype
rule %r/[^##{uniq_chars}\\]+/m, toktype
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/rust.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def macro_closed?
rule %r([=-]>), Keyword
rule %r(<->), Keyword
rule %r/[()\[\]{}|,:;]/, Punctuation
rule %r/[*!@~&+%^<>=-\?]|\.{2,3}/, Operator
rule %r/[*!@~&+%^<>=\?-]|\.{2,3}/, Operator

rule %r/([.]\s*)?#{id}(?=\s*[(])/m, Name::Function
rule %r/[.]\s*#{id}/, Name::Property
Expand Down
4 changes: 2 additions & 2 deletions lib/rouge/lexers/sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ def self.keywords
rule %r/"/, Name::Variable, :double_string
rule %r/`/, Name::Variable, :backtick

rule %r/\w[\w\d]*/ do |m|
rule %r/\w\w*/ do |m|
if self.class.keywords.include? m[0].upcase
token Keyword
else
token Name
end
end

rule %r([+*/<>=~!@#%^&|?^-]), Operator
rule %r([+*/<>=~!@#%&|?^-]), Operator
rule %r/[;:()\[\],.]/, Punctuation
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/tcl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.detect?(text)
CLOSE = %w| \) \] \} |
ALL = OPEN + CLOSE
END_LINE = CLOSE + %w(; \n)
END_WORD = END_LINE + %w(\s)
END_WORD = END_LINE + %w(\r \t \v)

CHARS = lambda { |list| Regexp.new %/[#{list.join}]/ }
NOT_CHARS = lambda { |list| Regexp.new %/[^#{list.join}]/ }
Expand Down
6 changes: 3 additions & 3 deletions lib/rouge/lexers/toml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class TOML < RegexLexer
filenames '*.toml'
mimetypes 'text/x-toml'

identifier = /[\w.\S]+/
identifier = /\S+/

state :basic do
rule %r/\s+/, Text
rule %r/#.*?$/, Comment
rule %r/(true|false)/, Keyword::Constant
rule %r/(?<!=)\s*\[[\w\d\S]+\]/, Name::Namespace
rule %r/(?<!=)\s*\[[\S]+\]/, Name::Namespace

rule %r/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/, Literal::Date

Expand Down Expand Up @@ -56,7 +56,7 @@ class TOML < RegexLexer
end

state :esc_str do
rule %r/\\[0t\tn\n "\\ r]/, Str::Escape
rule %r/\\[0t\tn\n "\\r]/, Str::Escape
end

state :array do
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/turtle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Turtle < RegexLexer

rule %r/#.*$/, Comment::Single

rule %r/@[^\s,.; ]+/, Name::Attribute
rule %r/@[^\s,.;]+/, Name::Attribute

rule %r/[+-]?[0-9]+\.[0-9]*E[+-]?[0-9]+/, Literal::Number::Float
rule %r/[+-]?\.[0-9]+E[+-]?[0-9]+/, Literal::Number::Float
Expand Down

0 comments on commit 056070e

Please sign in to comment.