diff --git a/lib/rouge/lexers/perl.rb b/lib/rouge/lexers/perl.rb index 2b404273bf..78aa05ce12 100644 --- a/lib/rouge/lexers/perl.rb +++ b/lib/rouge/lexers/perl.rb @@ -178,16 +178,24 @@ def self.detect?(text) end state :sq do - rule %r/\\[']/, Str::Escape + rule %r/\\[\\']/, Str::Escape rule %r/[^\\']+/, Str::Single rule %r/'/, Punctuation, :pop! + rule %r/\\/, Str::Single end state :dq do mixin :string_intp - rule %r/\\[\\tnr"]/, Str::Escape + rule %r/\\[\\tnrabefluLUE"$@]/, Str::Escape + rule %r/\\0\d{2}/, Str::Escape + rule %r/\\o\{\d+\}/, Str::Escape + rule %r/\\x\h{2}/, Str::Escape + rule %r/\\x\{\h+\}/, Str::Escape + rule %r/\\c./, Str::Escape + rule %r/\\N\{[^\}]+\}/, Str::Escape rule %r/[^\\"]+?/, Str::Double rule %r/"/, Punctuation, :pop! + rule %r/\\/, Str::Escape end state :bq do diff --git a/spec/visual/samples/perl b/spec/visual/samples/perl index e6c9e3ceab..5bf890854e 100644 --- a/spec/visual/samples/perl +++ b/spec/visual/samples/perl @@ -60,7 +60,15 @@ $s =~ y/[]|/()&/; # "backward" compatible # quoted strings +my $a = 'foo'; +my $a = 'foo\'s bar'; +my $a = 'foo\bar'; +my $a = 'foo\\bar'; my $a = "foo"; +my $a = "foo \" bar"; +my $a = "foo\bar"; +my $a = "foo \057 \x7f \x{263a} \cC \N{GREEK SMALL LETTER SIGMA} bar"; +my $a = "invalid escape \w"; print "a: "; print $a, " - ";