Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid allocating block parameters unnecessarily #1246

Merged
merged 1 commit into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rouge/lexers/apache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def name_for_token(token, kwtype, tktype)

state :section do
# Match section arguments
rule %r/([^>]+)?(>(?:\r\n?|\n)?)/ do |m|
rule %r/([^>]+)?(>(?:\r\n?|\n)?)/ do
groups Literal::String::Regex, Punctuation
pop!
end
Expand Down
24 changes: 12 additions & 12 deletions lib/rouge/lexers/bpf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ class BPF < RegexLexer

state :root do
# Calls to helpers
rule %r/(call)(\s+)(\d+)/i do |m|
rule %r/(call)(\s+)(\d+)/i do
groups Keyword, Text::Whitespace, Literal::Number::Integer
end

# Unconditional jumps
rule %r/(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do |m|
rule %r/(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do
groups Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
end

# Conditional jumps
rule %r/(if)(\s+)(r\d+)(\s*)([s!=<>]+)(\s*)(0x\h+|[-]?\d+)(\s*)(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do |m|
rule %r/(if)(\s+)(r\d+)(\s*)([s!=<>]+)(\s*)(0x\h+|[-]?\d+)(\s*)(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do
groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Literal::Number, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
end
rule %r/(if)(\s+)(r\d+)(\s*)([s!=<>]+)(\s*)(r\d+)(\s*)(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do |m|
rule %r/(if)(\s+)(r\d+)(\s*)([s!=<>]+)(\s*)(r\d+)(\s*)(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do
groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Name, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
end

# Dereferences
rule %r/(\*)(\s*)(\()(#{TYPE_KEYWORDS})(\s*)(\*)(\))/i do |m|
rule %r/(\*)(\s*)(\()(#{TYPE_KEYWORDS})(\s*)(\*)(\))/i do
groups Operator, Text::Whitespace, Punctuation, Keyword::Type, Text::Whitespace, Operator, Punctuation
push :address
end
Expand All @@ -45,7 +45,7 @@ class BPF < RegexLexer
rule %r/[+-\/\*&|><^s]{0,3}=/i, Operator

# Registers
rule %r/([+-]?)(r\d+)/i do |m|
rule %r/([+-]?)(r\d+)/i do
groups Punctuation, Name
end

Expand All @@ -56,15 +56,15 @@ class BPF < RegexLexer
rule %r/#{MISC_KEYWORDS}/i, Keyword

# Literals and global objects (maps) refered by name
rule %r/(0x\h+|[-]?\d+)(\s*)(ll)?/i do |m|
rule %r/(0x\h+|[-]?\d+)(\s*)(ll)?/i do
groups Literal::Number, Text::Whitespace, Keyword::Type
end
rule %r/(\w+)(\s*)(ll)/i do |m|
rule %r/(\w+)(\s*)(ll)/i do
groups Name, Text::Whitespace, Keyword::Type
end

# Labels
rule %r/(\w+)(\s*)(:)/i do |m|
rule %r/(\w+)(\s*)(:)/i do
groups Name::Label, Text::Whitespace, Punctuation
end

Expand All @@ -73,17 +73,17 @@ class BPF < RegexLexer

state :address do
# Address is offset from register
rule %r/(\()(r\d+)(\s*)([+-])(\s*)(\d+)(\))/i do |m|
rule %r/(\()(r\d+)(\s*)([+-])(\s*)(\d+)(\))/i do
groups Punctuation, Name, Text::Whitespace, Operator, Text::Whitespace, Literal::Number::Integer, Punctuation
pop!
end

# Address is array subscript
rule %r/(\w+)(\[)(\d+)(\])/i do |m|
rule %r/(\w+)(\[)(\d+)(\])/i do
groups Name, Punctuation, Literal::Number::Integer, Punctuation
pop!
end
rule %r/(\w+)(\[)(r\d+)(\])/i do |m|
rule %r/(\w+)(\[)(r\d+)(\])/i do
groups Name, Punctuation, Name, Punctuation
pop!
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rouge/lexers/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class Docker < RegexLexer
state :root do
rule %r/\s+/, Text

rule %r/^(ONBUILD)(\s+)(#{KEYWORDS})(.*)/io do |m|
rule %r/^(ONBUILD)(\s+)(#{KEYWORDS})(.*)/io do
groups Keyword, Text::Whitespace, Keyword, Str
end

rule %r/^(#{KEYWORDS})\b(.*)/io do |m|
rule %r/^(#{KEYWORDS})\b(.*)/io do
groups Keyword, Str
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def content_lexer
end

state :content do
rule %r/.+/m do |m|
rule %r/.+/m do
delegate(content_lexer)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/idlang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def self.routines

rule %r{\#\#|\#|\&\&|\|\||/=|<=|>=|->|\@|\?|[-+*/<=~^{}]}, Operator
# Structures and the like
rule %r/(#{name})(\.)([^\s,]*)/i do |m|
rule %r/(#{name})(\.)([^\s,]*)/i do
groups Name, Operator, Name
#delegate IDLang, m[3]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/make.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def initialize(opts={})
end

state :block_body do
rule %r/(\t[\t ]*)([@-]?)/ do |m|
rule %r/(\t[\t ]*)([@-]?)/ do
groups Text, Punctuation
push :shell_line
end
Expand Down
3 changes: 2 additions & 1 deletion lib/rouge/lexers/nim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ def self.underscorize(words)
# Numbers
# Note: Have to do this with a block to push multiple states first,
# since we can't pass array of states like w/ Pygments.
rule(/[0-9][0-9_]*(?=([eE.]|'?[fF](32|64)))/) do |number|
rule(/[0-9][0-9_]*(?=([eE.]|'?[fF](32|64)))/) do
push :floatsuffix
push :floatnumber
token Num::Float
end

rule(/0[xX][a-fA-F0-9][a-fA-F0-9_]*/, Num::Hex, :intsuffix)
rule(/0[bB][01][01_]*/, Num, :intsuffix)
rule(/0o[0-7][0-7_]*/, Num::Oct, :intsuffix)
Expand Down
6 changes: 3 additions & 3 deletions lib/rouge/lexers/openedge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,14 @@ def self.keywords_type
state :root do
rule %r(\s+), Text

rule %r((\.)(\s+)) do |m|
rule %r((\.)(\s+)) do
groups Operator, Text
end

rule %r(//[^\n]*), Comment::Single
rule %r(/[*].*?[*]/)m, Comment::Multiline

rule %r/(\{?&)(\S+)/ do |m|
rule %r/(\{?&)(\S+)/ do
groups Comment::Preproc, Name::Other
push :preproc
end
Expand Down Expand Up @@ -415,7 +415,7 @@ def self.keywords_type
rule %r/\n/, Text, :pop!
rule %r/\s+/, Text

rule %r/({?&)(\S+)/ do |m|
rule %r/({?&)(\S+)/ do
groups Comment::Preproc, Name::Other
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/powershell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class Powershell < RegexLexer
end
rule %r/(?:#{KEYWORDS})\b(?!-)/i, Keyword::Reserved

rule %r/(\w+)(\.)/ do |m|
rule %r/(\w+)(\.)/ do
groups Name::Constant, Operator
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def self.detect?(text)
rule %r/\b(#{BUILTINS})\s*\b(?!(\.|-))/, Name::Builtin
rule %r/[.](?=\s)/, Name::Builtin

rule %r/(\b\w+)(=)/ do |m|
rule %r/(\b\w+)(=)/ do
groups Name::Variable, Operator
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/lexers/tex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def self.detect?(text)
rule %r/\$/, Punctuation, :inlinemath
rule %r/\\(begin|end)\{.*?\}/, Name::Tag

rule %r/(\\verb)\b(\S)(.*?)(\2)/ do |m|
rule %r/(\\verb)\b(\S)(.*?)(\2)/ do
groups Name::Builtin, Keyword::Pseudo, Str::Other, Keyword::Pseudo
end

Expand Down