Skip to content

Commit

Permalink
Factor out repetitive rx literal code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Sep 24, 2015
1 parent 7190914 commit 6b3c7b0
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions src/QRegex/P6Regex/Actions.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,7 @@ class QRegex::P6Regex::Actions is HLL::Actions {
}
else {
my $qast := QAST::Regex.new( ~$/, :rxtype<literal>, :node($/));
if %*RX<i> && %*RX<m> { # >
$qast.subtype('ignorecase+ignoremark')
}
elsif %*RX<i> {
$qast.subtype('ignorecase')
}
elsif %*RX<m> { # >
$qast.subtype('ignoremark')
}
make $qast;
make self.apply_literal_modifiers($qast);
}
}

Expand Down Expand Up @@ -213,32 +204,14 @@ class QRegex::P6Regex::Actions is HLL::Actions {
my $quote := $<quote_EXPR>.ast;
if QAST::SVal.ACCEPTS($quote) { $quote := $quote.value; }
my $qast := QAST::Regex.new( $quote, :rxtype<literal>, :node($/) );
if %*RX<i> && %*RX<m> { # >
$qast.subtype('ignorecase+ignoremark')
}
elsif %*RX<i> {
$qast.subtype('ignorecase')
}
elsif %*RX<m> { # >
$qast.subtype('ignoremark')
}
make $qast;
make self.apply_literal_modifiers($qast);
}

method metachar:sym<">($/) {
my $quote := $<quote_EXPR>.ast;
if QAST::SVal.ACCEPTS($quote) { $quote := $quote.value; }
my $qast := QAST::Regex.new( $quote, :rxtype<literal>, :node($/) );
if %*RX<i> && %*RX<m> { # >
$qast.subtype('ignorecase+ignoremark')
}
elsif %*RX<i> {
$qast.subtype('ignorecase')
}
elsif %*RX<m> { # >
$qast.subtype('ignoremark')
}
make $qast;
make self.apply_literal_modifiers($qast);
}

method metachar:sym<.>($/) {
Expand Down Expand Up @@ -772,6 +745,19 @@ class QRegex::P6Regex::Actions is HLL::Actions {
$ast;
}

method apply_literal_modifiers($qast) {
if %*RX<i> && %*RX<m> { # >
$qast.subtype('ignorecase+ignoremark')
}
elsif %*RX<i> {
$qast.subtype('ignorecase')
}
elsif %*RX<m> { # >
$qast.subtype('ignoremark')
}
return $qast
}

method qbuildsub($qast, $block = QAST::Block.new(), :$anon, :$addself, *%rest) {
my $code_obj := nqp::existskey(%rest, 'code_obj')
?? %rest<code_obj>
Expand Down

0 comments on commit 6b3c7b0

Please sign in to comment.