Skip to content

Commit

Permalink
- Better dumping of regular expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
trizen committed Dec 16, 2015
1 parent 932cebb commit 32262a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/Sidef/Deparse/Perl.pm
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,8 @@ HEADER
elsif ($ref eq 'Sidef::Types::Regex::Regex') {
$code =
$self->make_constant($ref, 'new', "Regex$refaddr",
$self->_dump_string("$obj->{regex}"),
$obj->{global} ? '"g"' : ());
$self->_dump_string("$obj->{raw}"),
$self->_dump_string($obj->{flags} . ($obj->{global} ? 'g' : '')));
}
elsif ($ref eq 'Sidef::Types::Block::If' or $ref eq 'Sidef::Types::Block::While') {
## ok
Expand Down
17 changes: 7 additions & 10 deletions lib/Sidef/Types/Regex/Regex.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ package Sidef::Types::Regex::Regex {
sub new {
my (undef, $regex, $mode) = @_;

$mode = defined($mode) ? ref($mode) ? $mode->get_value : $mode : '';
$regex = defined($regex) ? ref($regex) ? $regex->get_value : $regex : '';
$mode = defined($mode) ? ref($mode) ? $mode->get_value : $mode : '';

my $global_mode = $mode =~ tr/g//d;
my $compiled_re = $mode eq '' ? qr{$regex} : qr{(?$mode:$regex)};
my $compiled_re = qr{(?$mode:$regex)};

bless {
regex => $compiled_re,
raw => $regex,
flags => $mode,
global => $global_mode,
pos => 0,
},
Expand Down Expand Up @@ -64,14 +67,8 @@ package Sidef::Types::Regex::Regex {
sub dump {
my ($self) = @_;

my $str = "$self->{regex}";

my $flags = '';
if ($str =~ s/\(\?\^u:\(\?(?:\^|(.*?))://) {
$flags = $1 // '';
chop $str;
chop $str;
}
my $str = $self->{raw};
my $flags = $self->{flags};

Sidef::Types::String::String->new('/' . $str =~ s{/}{\\/}gr . '/' . $flags . ($self->{global} ? 'g' : ''));
}
Expand Down

0 comments on commit 32262a1

Please sign in to comment.