Skip to content

Commit

Permalink
Fix custom delimiter rule in sed lexer (#893)
Browse files Browse the repository at this point in the history
Groups are not correctly being used in the custom delimiter rule. This
commit fixes that.
  • Loading branch information
axiac authored and pyrmont committed Aug 2, 2019
1 parent a0a0823 commit 72988bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/sed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def replacement
end

# alternate regex rage delimiters
rule %r((\\)(.)(\\.|.)*?(\2)) do |m|
rule %r((\\)(.)((?:\\.|.)*?)(\2)) do |m|
token addr_tok, m[1] + m[2]
delegate regex, m[3]
token addr_tok, m[4]
Expand Down
12 changes: 12 additions & 0 deletions spec/lexers/sed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,16 @@
assert_guess :source => '#!/usr/bin/sed'
end
end

describe 'lexing' do
include Support::Lexing

it 'parses regex addresses with custom delimiter' do
assert_tokens_equal '\#foobar#n',
['Keyword.Namespace', '\#'],
['Literal.String.Regex', 'foobar'],
['Keyword.Namespace', '#'],
['Keyword', 'n']
end
end
end

0 comments on commit 72988bf

Please sign in to comment.