Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Factor out creation of regex sub for <nibbler> nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 14, 2009
1 parent 8c37aa5 commit b9ea370
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions src/Regex/P6Regex/Actions.pm
Expand Up @@ -8,18 +8,7 @@ our @MODIFIERS := Q:PIR {
};
method TOP($/) {
my $rpast := $<nibbler>.ast;
my %capnames := capnames($rpast, 0);
%capnames{''} := 0;
$rpast := PAST::Regex.new(
PAST::Regex.new( :pasttype('scan') ),
$rpast,
PAST::Regex.new( :pasttype('pass') ),
:pasttype('concat'),
:capnames(%capnames)
);
my $past := PAST::Block.new( $rpast, :blocktype('method') );
make $past;
make buildsub( $<nibbler>.ast );
}
method nibbler($/, $key?) {
Expand Down Expand Up @@ -133,17 +122,7 @@ method metachar:sym<[ ]>($/) {
}

method metachar:sym<( )>($/) {
my $rpast := $<nibbler>.ast;
my %capnames := capnames($rpast, 0);
%capnames{''} := 0;
$rpast := PAST::Regex.new(
PAST::Regex.new( :pasttype('scan') ),
$rpast,
PAST::Regex.new( :pasttype('pass') ),
:pasttype('concat'),
:capnames(%capnames)
);
my $subpast := PAST::Block.new( $rpast, :blocktype('method') );
my $subpast := buildsub($<nibbler>.ast);
my $past := PAST::Regex.new( $subpast, :pasttype('subrule'),
:subtype('capture') );
make $past;
Expand Down Expand Up @@ -380,6 +359,19 @@ method mod_internal($/) {
make 0;
}

sub buildsub($rpast) {
my %capnames := capnames($rpast, 0);
%capnames{''} := 0;
$rpast := PAST::Regex.new(
PAST::Regex.new( :pasttype('scan') ),
$rpast,
PAST::Regex.new( :pasttype('pass') ),
:pasttype('concat'),
:capnames(%capnames)
);
PAST::Block.new( $rpast, :blocktype('method') );
}

sub capnames($ast, $count) {
my %capnames;
my $pasttype := $ast.pasttype;
Expand Down

0 comments on commit b9ea370

Please sign in to comment.