Skip to content

Commit

Permalink
Merge pull request #974 from jneen/dblessing-patch-3
Browse files Browse the repository at this point in the history
Perl - Allow any non-whitespace character to delimit regexes
  • Loading branch information
dblessing committed Aug 16, 2018
2 parents 7f027b1 + 3ba03cc commit 27a4bfb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,16 @@ This log summarizes the changes in each released version of rouge. The versionin
we use is semver, although we will often release new lexers in minor versions, as a
practical matter.

## version 3.2.1: (2018/08/16)

https://github.com/jneen/rouge/compare/v3.2.0...v3.2.1

* Perl Lexer
* Allow any non-whitespace character to delimit regexes ([#974](https://github.com/jneen/rouge/pull/974) by dblessing)
* Details: In specific cases where a previously unsupported regex delimiter was
used, a later rule could cause a backtrack in the regex system.
This resulted in Rouge hanging for an unspecified amount of time.

## version 3.2.0: (2018/08/02)

https://github.com/jneen/rouge/compare/v3.1.1...v3.2.0
Expand Down
18 changes: 11 additions & 7 deletions lib/rouge/lexers/perl.rb
Expand Up @@ -77,21 +77,25 @@ def self.detect?(text)
rule /(?:eq|lt|gt|le|ge|ne|not|and|or|cmp)\b/, Operator::Word

# common delimiters
rule %r(s/(\\\\|\\/|[^/])*/(\\\\|\\/|[^/])*/[egimosx]*), re_tok
rule %r(s!(\\\\|\\!|[^!])*!(\\\\|\\!|[^!])*![egimosx]*), re_tok
rule %r(s\\(\\\\|[^\\])*\\(\\\\|[^\\])*\\[egimosx]*), re_tok
rule %r(s@(\\\\|\\@|[^@])*@(\\\\|\\@|[^@])*@[egimosx]*), re_tok
rule %r(s%(\\\\|\\%|[^%])*%(\\\\|\\%|[^%])*%[egimosx]*), re_tok
rule %r(s/(\\\\|\\/|[^/])*/(\\\\|\\/|[^/])*/[msixpodualngc]*), re_tok
rule %r(s!(\\\\|\\!|[^!])*!(\\\\|\\!|[^!])*![msixpodualngc]*), re_tok
rule %r(s\\(\\\\|[^\\])*\\(\\\\|[^\\])*\\[msixpodualngc]*), re_tok
rule %r(s@(\\\\|\\@|[^@])*@(\\\\|\\@|[^@])*@[msixpodualngc]*), re_tok
rule %r(s%(\\\\|\\%|[^%])*%(\\\\|\\%|[^%])*%[msixpodualngc]*), re_tok

# balanced delimiters
rule %r(s{(\\\\|\\}|[^}])*}\s*), re_tok, :balanced_regex
rule %r(s<(\\\\|\\>|[^>])*>\s*), re_tok, :balanced_regex
rule %r(s\[(\\\\|\\\]|[^\]])*\]\s*), re_tok, :balanced_regex
rule %r[s\((\\\\|\\\)|[^\)])*\)\s*], re_tok, :balanced_regex

rule %r(m?/(\\\\|\\/|[^/\n])*/[gcimosx]*), re_tok
rule %r(m?/(\\\\|\\/|[^/\n])*/[msixpodualngc]*), re_tok
rule %r(m(?=[/!\\{<\[\(@%\$])), re_tok, :balanced_regex
rule %r(((?<==~)|(?<=\())\s*/(\\\\|\\/|[^/])*/[gcimosx]*),

# Perl allows any non-whitespace character to delimit
# a regex when `m` is used.
rule %r(m(\S).*\1[msixpodualngc]*), re_tok
rule %r(((?<==~)|(?<=\())\s*/(\\\\|\\/|[^/])*/[msixpodualngc]*),
re_tok, :balanced_regex

rule /\s+/, Text
Expand Down
2 changes: 1 addition & 1 deletion lib/rouge/version.rb
Expand Up @@ -2,6 +2,6 @@

module Rouge
def self.version
"3.2.0"
"3.2.1"
end
end
4 changes: 4 additions & 0 deletions spec/visual/samples/perl
Expand Up @@ -225,4 +225,8 @@ sub foo {

# operators
my $moduloOperation = $totalNumber % $columns ? 1 : 0;
$moduloOperation = 2;
my $addOperation = $totalNumber + $myOtherVar;

# regexes delimited by non-standard (non-whitespace) character
if $filename and $filename =~ m,usr/share/doc/[^/]+/examples/,;

0 comments on commit 27a4bfb

Please sign in to comment.