Author: pmichaud
Date: Wed May  7 12:16:29 2008
New Revision: 27378

Modified:
   trunk/compilers/pge/PGE/Exp.pir
   trunk/compilers/pge/PGE/Perl6Regex.pir

Log:
[pge]:
* Initial code refactor to handle zero-width matches.


Modified: trunk/compilers/pge/PGE/Exp.pir
==============================================================================
--- trunk/compilers/pge/PGE/Exp.pir     (original)
+++ trunk/compilers/pge/PGE/Exp.pir     Wed May  7 12:16:29 2008
@@ -817,8 +817,8 @@
         CODE
 
   subrule_match:
-    $I0 = self['isnegated']
-    if $I0 goto subrule_negated
+    $I0 = self['iszerowidth']
+    if $I0 goto subrule_zerowidth
     $S0 = concat label, '_3'
     $I0 = self['backtrack']
     if $I0 != PGE_BACKTRACK_NONE goto subrule_match_1
@@ -861,18 +861,24 @@
     goto end
     .return()
 
-  subrule_negated:
-    ##   This handles negative subrule matches; if a subrule fails, then
-    ##   record a zero-width match and continue to the next node.
-    code.emit(<<"        CODE", PGE_CUT_MATCH, next, subarg)
-          captob = $P0(captob%2)
+  subrule_zerowidth:
+    ##  this handles zero-width subrule matches, either positive
+    ##  or negative.
+    .local string test
+    test = 'if'
+    $I0 = self['isnegated']
+    unless $I0 goto have_test
+    test = 'unless'
+  have_test:
+    code.emit(<<"        CODE", PGE_CUT_MATCH, test, next, subarg)
+          captob = $P0(captob%3)
           $P1 = getattribute captob, '$.pos'
           if $P1 <= %0 goto fail_match
-          if $P1 >= 0 goto fail
+          %1 $P1 < 0 goto fail
           $P1 = pos
           $P1 = getattribute captob, '$.from'
           $P1 = pos
-          goto %1
+          goto %2
         CODE
   end:
     .return()

Modified: trunk/compilers/pge/PGE/Perl6Regex.pir
==============================================================================
--- trunk/compilers/pge/PGE/Perl6Regex.pir      (original)
+++ trunk/compilers/pge/PGE/Perl6Regex.pir      Wed May  7 12:16:29 2008
@@ -747,6 +747,7 @@
 
   negated:
     mob['isnegated'] = 1
+    mob['iszerowidth'] = 1
   nocapture:
     mob['iscapture'] = 0
   subrule_arg:

Reply via email to