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

Commit

Permalink
Handle simple binding aliases.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 13, 2009
1 parent 76c694d commit 4481429
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Regex/P6Regex/Actions.pm
Expand Up @@ -168,6 +168,19 @@ method metachar:sym<assert>($/) {
make $<assertion>.ast;
}

method metachar:sym<var>($/) {
my $past;
my $name := $<pos> ?? +$<pos> !! ~$<name>;
if $<quantified_atom> {
$past := $<quantified_atom>[0].ast;
if $past.pasttype eq 'subrule' {
$past.subtype('capture');
$past.name($name);
}
}
make $past;
}

method backslash:sym<w>($/) {
my $subtype := ~$<sym> eq 'n' ?? 'nl' !! ~$<sym>;
my $past := PAST::Regex.new( :pasttype('charclass'), :subtype($subtype) );
Expand Down Expand Up @@ -329,6 +342,7 @@ sub capnames($ast, $count) {
$ast.name($count);
$count := $count + 1;
}
elsif $ast.name eq '0' || $ast.name > 0 { $count := $ast.name + 1; }
%capnames{$ast.name} := 1;
}
elsif $pasttype eq 'quant' {
Expand Down
10 changes: 10 additions & 0 deletions src/Regex/P6Regex/Grammar.pm
Expand Up @@ -71,6 +71,16 @@ grammar Regex::P6Regex::Grammar is PCT::Grammar;
{*}
}

token metachar:sym<var> {
[
| '$<' $<name>=[<-[>]>+] '>'
| '$' $<pos>=[\d+]
]

[ <.ws> '=' <.ws> <quantified_atom> ]?
{*}
}

# proto token backslash { <...> }
token backslash:sym<w> { $<sym>=[<[dswnDSWN]>] {*} }
token backslash:sym<b> { $<sym>=[<[bB]>] {*} }
Expand Down

0 comments on commit 4481429

Please sign in to comment.