Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add named and numbered aliases to subrules.
  • Loading branch information
pmichaud committed Jul 12, 2011
1 parent ea8cab2 commit b5a80bf
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/QRegex/P6Regex/Actions.nqp
Expand Up @@ -155,6 +155,25 @@ class QRegex::P6Regex::Actions is HLL::Actions {
make $<assertion>.ast;
}

method metachar:sym<var>($/) {
my $qast;
my $name := $<pos> ?? +$<pos> !! ~$<name>;
if $<quantified_atom> {
$qast := $<quantified_atom>[0].ast;
if $qast.rxtype eq 'quant' && $qast[0].rxtype eq 'subrule' {
self.subrule_alias($qast[0], $name);
}
elsif $qast.rxtype eq 'subrule' {
self.subrule_alias($qast, $name);
}
else {
$qast := QAST::Regex.new( $qast, :name($name),
:rxtype<subcapture>, :node($/) );
}
}
make $qast;
}

method backslash:sym<s>($/) {
make QAST::Regex.new(:rxtype<cclass>, '.CCLASS_WHITESPACE',
:subtype($<sym> eq 'n' ?? 'nl' !! ~$<sym>),
Expand Down Expand Up @@ -262,8 +281,17 @@ class QRegex::P6Regex::Actions is HLL::Actions {

method assertion:sym<name>($/) {
my $name := ~$<longname>;
my $qast := QAST::Regex.new( :rxtype<subrule>, :subtype<capture>, :node($/),
PAST::Node.new($name), :name($name) );
my $qast;
if $<assertion> {
say("aliasing to $name");
$qast := $<assertion>[0].ast;
self.subrule_alias($qast, $name);
}
else {
$qast := QAST::Regex.new(:rxtype<subrule>, :subtype<capture>,
:node($/), PAST::Node.new($name),
:name($name) );
}
make $qast;
}

Expand Down

0 comments on commit b5a80bf

Please sign in to comment.