From c18359996be8bce595871b90575f2854c83b69ed Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Fri, 15 Jan 2010 23:39:56 +0100 Subject: [PATCH] [GGE::TreeSpider] backreferences --- lib/GGE/TreeSpider.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/GGE/TreeSpider.pm b/lib/GGE/TreeSpider.pm index b802e40..f9ab306 100644 --- a/lib/GGE/TreeSpider.pm +++ b/lib/GGE/TreeSpider.pm @@ -83,6 +83,29 @@ class GGE::TreeSpider { when FAIL_RULE { $!current.failed-rule($!pos, %pad) } when * { die 'Unknown action ', $!last.name } }; + if $!current ~~ GGE::Exp::Scalar { + # Find a capture that is a scope. + my $ix = @!capstack.end; + --$ix + while $ix > 0 + && @!capstack[$ix] !~~ Array + && ! @!capstack[$ix].hash-access('isscope'); + my $topcap = @!capstack[$ix]; + my $cname = $!current.hash-access('cname'); + my $subrule = $cname.substr(0, 1) eq "'" + ?? $topcap.hash-access($cname.substr(1, -1)) + !! $topcap[$cname]; + my $backref = $subrule ~~ Array + ?? ~$subrule[*-1] + !! ~$subrule; + if $!pos <= $!target.chars - $backref.chars + && $!target.substr($!pos, $backref.chars) eq $backref { + $!pos += $backref.chars; + } + else { + $action = FAIL; + } + } if $action != DESCEND && ($!last == BACKTRACK || !($!current ~~ GGE::Container)) { my $participle