Author: pmichaud
Date: Tue Nov  1 13:39:21 2005
New Revision: 9696

Modified:
   trunk/compilers/pge/PGE/Exp.pir
   trunk/compilers/pge/PGE/P6Rule.pir
   trunk/compilers/pge/PGE/Rule.pir
   trunk/t/p6rules/builtins.t
Log:
* Added negated subrules (<!before ...>, <!ident>)
* Fixed attribute bug in <before> rule
* Changed some .returns to use PIR tailcalls (suggested by Will Coleda)


Modified: trunk/compilers/pge/PGE/Exp.pir
==============================================================================
--- trunk/compilers/pge/PGE/Exp.pir     (original)
+++ trunk/compilers/pge/PGE/Exp.pir     Tue Nov  1 13:39:21 2005
@@ -875,11 +875,12 @@ register.
     .local pmc emit
     .local string subname, subargs
     .local string cname, captsave, captback
-    .local int iscapture, iscut
+    .local int iscapture, iscut, isnegated
     emit = find_global "PGE::Exp", "emit"
     subname = self["subname"]
     iscapture = self["iscapture"]
     iscut = self["iscut"]
+    isnegated = self["isnegated"]
     cname = self["cname"]
     emit(code, "\n  %s:  # subrule %s    ##", label, subname)
     subargs = ""
@@ -925,12 +926,21 @@ register.
     emit(code, "  %s_s2:", label)
     emit(code, "    $P0 = $P0(captscope%s)", subargs)
   subrule_3:
+    if isnegated == 0 goto subrule_4
+    emit(code, "    if $P0 goto fail")
+    emit(code, "    $P1 = getattribute $P0, \"PGE::Match\\x0$:from\"")
+    emit(code, "    $P1 = pos")
+    emit(code, "    $P1 = getattribute $P0, \"PGE::Match\\x0$:pos\"")
+    emit(code, "    $P1 = pos")
+    emit(code, "    goto %s", next)
+    goto end
+  subrule_4:
     emit(code, "    unless $P0 goto fail")
     emit(code, captsave, cname)
-    if iscut == 0 goto subrule_4
+    if iscut == 0 goto subrule_5
     emit(code, "    goto %s", next)
     goto end
-  subrule_4:
+  subrule_5:
     emit(code, "  %s_sr3:", label)
     emit(code, "    pos = $P0.to()")
     emit(code, "    $P1 = getattribute $P0, \"PGE::Match\\x0&:corou\"")

Modified: trunk/compilers/pge/PGE/P6Rule.pir
==============================================================================
--- trunk/compilers/pge/PGE/P6Rule.pir  (original)
+++ trunk/compilers/pge/PGE/P6Rule.pir  Tue Nov  1 13:39:21 2005
@@ -240,9 +240,12 @@
     lastpos = length target
     $S0 = substr target, pos, 2
     if $S0 == "<?" goto nocapture
+    if $S0 == "<!" goto negated
     iscapture = 1
     inc pos
     goto subrule_name
+  negated:
+    mob["isnegated"] = 1
   nocapture:
     iscapture = 0
     pos += 2

Modified: trunk/compilers/pge/PGE/Rule.pir
==============================================================================
--- trunk/compilers/pge/PGE/Rule.pir    (original)
+++ trunk/compilers/pge/PGE/Rule.pir    Tue Nov  1 13:39:21 2005
@@ -50,8 +50,7 @@ Force a backtrack.  (Taken from A05.)
 .sub fail
     .param pmc mob
     $P0 = find_global "PGE::Match", "newfrom"
-    mob = $P0(mob)
-    .return (mob)
+    .return $P0(mob)
 .end
 
 =item C<upper()>
@@ -456,7 +455,7 @@ C<pattern> matches.  Always returns a ze
     $P1 = getattribute mob, "PGE::Match\x0$:pos"
     assign $P1, $P0
     null $P0
-    setattribute mob, "PGE::Match\\x0&:corou", $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 13:39:21 2005
@@ -1,4 +1,4 @@
-use Parrot::Test tests => 44;
+use Parrot::Test tests => 45;
 use Parrot::Test::PGE;
 
 $str = 
@@ -108,3 +108,8 @@ p6rule_isnt("abacad", '<before c> ....',
 
 p6rule_isnt("abcd", '<before> .', 'null <before>');
 
+p6rule_like  ("aabaaa", '<!before ..b> aa', 
+    qr/mob: <aa @ 3>/,
+    'negated lookahead');
+
+

Reply via email to