Author: pmichaud
Date: Tue Nov 1 12:45:17 2005
New Revision: 9695
Modified:
trunk/compilers/pge/PGE/Rule.pir
trunk/t/p6rules/builtins.t
Log:
* Fixed <before> to fail if no subrule given
* Added cut to <before> rule to avoid useless backtracking
* Added <before> tests to t/p6rules/builtins.t
Modified: trunk/compilers/pge/PGE/Rule.pir
==============================================================================
--- trunk/compilers/pge/PGE/Rule.pir (original)
+++ trunk/compilers/pge/PGE/Rule.pir Tue Nov 1 12:45:17 2005
@@ -436,6 +436,10 @@ C<pattern> matches. Always returns a ze
.param int has_pattern :opt_flag
.local pmc cache, rule
+ if has_pattern goto lookahead
+ mob = fail(mob)
+ .return (mob)
+ lookahead:
cache = find_global "PGE::Rule", "%:cache"
$I0 = exists cache[pattern]
if $I0 == 0 goto new_pattern
@@ -451,6 +455,8 @@ C<pattern> matches. Always returns a ze
$P0 = getattribute mob, "PGE::Match\x0$:from"
$P1 = getattribute mob, "PGE::Match\x0$:pos"
assign $P1, $P0
+ null $P0
+ setattribute mob, "PGE::Match\\x0&:corou", $P0
end:
.return (mob)
.end
Modified: trunk/t/p6rules/builtins.t
==============================================================================
--- trunk/t/p6rules/builtins.t (original)
+++ trunk/t/p6rules/builtins.t Tue Nov 1 12:45:17 2005
@@ -1,4 +1,4 @@
-use Parrot::Test tests => 41;
+use Parrot::Test tests => 44;
use Parrot::Test::PGE;
$str =
@@ -99,3 +99,12 @@ p6rule_like($str, '<?dot>+',
p6rule_like("2+3 ab2", '<ident>',
qr/mob<ident>: <ab2 @ 4>/, 'capturing builtin');
+
+p6rule_like("abacad", '<before .d> a.',
+ qr/mob: <ad @ 4>/,
+ 'lookahead <before>');
+
+p6rule_isnt("abacad", '<before c> ....', 'lookahead <before>');
+
+p6rule_isnt("abcd", '<before> .', 'null <before>');
+