Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement backreferences.
  • Loading branch information
jnthn committed Sep 29, 2012
1 parent 9a42dc5 commit 5c4d6b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/QRegex/P5Regex/Actions.nqp
Expand Up @@ -164,8 +164,15 @@ class QRegex::P5Regex::Actions is HLL::Actions {
}

method p5backslash:sym<misc>($/) {
my $qast := QAST::Regex.new( ~$/ , :rxtype('literal'), :node($/) );
make $qast;
if $<litchar> {
make QAST::Regex.new( ~$<litchar> , :rxtype('literal'), :node($/) );
}
else {
make QAST::Regex.new( :rxtype<subrule>, :subtype<method>, :node($/),
QAST::Node.new(
QAST::SVal.new( :value('!BACKREF') ),
QAST::SVal.new( :value(~$<number> - 1) ) ) );
}
}

method p5quantifier:sym<*>($/) {
Expand Down
2 changes: 1 addition & 1 deletion src/QRegex/P5Regex/Grammar.nqp
Expand Up @@ -83,7 +83,7 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {

token p5backslash:sym<b> { $<sym>=[<[bB]>] }
token p5backslash:sym<s> { $<sym>=[<[dDnNsSwW]>] }
token p5backslash:sym<misc> { \W }
token p5backslash:sym<misc> { $<litchar>=(\W) | $<number>=(\d+) }
token p5backslash:sym<oops> { <.panic: "Unrecognized Perl 5 regex backslash sequence"> }

proto token p5assertion { <...> }
Expand Down
2 changes: 2 additions & 0 deletions t/p5regex/rx_captures
Expand Up @@ -14,3 +14,5 @@ d()ef zzzabcdefzzz y empty capture
(a)b(c) abc y multiple matches
(a)b(c) abc <mob[0]: a @ 0> basic $0
(a)b(c) abc <mob[1]: c @ 2> basic $1
b(.)\1 bookkeeper y backreference
b(.)\1(.)\2 bookkeeper y backreference

0 comments on commit 5c4d6b2

Please sign in to comment.