Author: pmichaud
Date: Mon Nov  7 17:37:51 2005
New Revision: 9833

Modified:
   trunk/compilers/pge/PGE/Exp.pir
   trunk/compilers/pge/PGE/Rule.pir
Log:
* Changed C<null> to C<"null">, C<fail> to C<"fail">
* Added "nextchars" capability to subrules.
* Added "nextchars" capability to <ws> subrule.


Modified: trunk/compilers/pge/PGE/Exp.pir
==============================================================================
--- trunk/compilers/pge/PGE/Exp.pir     (original)
+++ trunk/compilers/pge/PGE/Exp.pir     Mon Nov  7 17:37:51 2005
@@ -1023,8 +1023,11 @@ register.
 .namespace [ "PGE::Exp::Subrule" ]
 
 .sub "reduce" :method
+    .param pmc next
     self["isquant"] = 1
     self["firstchars"] = ""
+    $S0 = next["firstchars"]
+    self["nextchars"] = $S0
     .return (self)
 .end
 
@@ -1033,7 +1036,7 @@ register.
     .param string label
     .param string next
     .local pmc emit
-    .local string subname, subargs
+    .local string subname, subargs, nextchars
     .local string cname, captsave, captback
     .local int iscapture, iscut, isnegated
     emit = find_global "PGE::Exp", "emit"
@@ -1042,6 +1045,7 @@ register.
     iscut = self["iscut"]
     isnegated = self["isnegated"]
     cname = self["cname"]
+    nextchars = self["nextchars"]
     emit(code, "\n  %s:  # subrule %s    ##", label, subname)
     subargs = ""
     $I0 = exists self["arg"]
@@ -1069,7 +1073,6 @@ register.
     emit(code, "    ($P1,$P9,$P9,$P0) = newfrom(captscope, pos, \"%s\")", $S0)
     emit(code, "    $P0 = pos")
     emit(code, "    $P0 = find_global \"%s\", \"%s\"", $S0, $S1)
-    emit(code, "    $P0 = $P0($P1%s)", subargs)
     goto subrule_3
   subrule_simple_name:
     emit(code, "    $P0 = getattribute captscope, \"PGE::Match\\x0$:pos\"")
@@ -1081,8 +1084,15 @@ register.
     emit(code, "  %s_s1:", label)
     emit(code, "    $P0 = find_global \"%s\"", subname)
     emit(code, "  %s_s2:", label)
-    emit(code, "    $P0 = $P0(captscope%s)", subargs)
+    emit(code, "    $P1 = captscope", subargs)
   subrule_3:
+    if nextchars == "" goto subrule_3a
+    nextchars = self.escape(nextchars)
+    emit(code, "    $P2 = new String")
+    emit(code, "    $P2 = %s", nextchars)
+    emit(code, "    setprop $P0, \"nextchars\", $P2")
+  subrule_3a:
+    emit(code, "    $P0 = $P0($P1%s)", subargs)
     emit(code, "    $P1 = getattribute $P0, \"PGE::Match\\x0$:pos\"")
     emit(code, "    if $P1 <= %s goto %s_commit", PGE_CUT_MATCH, label)
     if isnegated == 0 goto subrule_4

Modified: trunk/compilers/pge/PGE/Rule.pir
==============================================================================
--- trunk/compilers/pge/PGE/Rule.pir    (original)
+++ trunk/compilers/pge/PGE/Rule.pir    Mon Nov  7 17:37:51 2005
@@ -32,7 +32,7 @@ Match a null string (always returns true
 
 =cut
 
-.sub null
+.sub "null"
     .param pmc mob
     .local pmc target, mfrom, mpos
     $P0 = find_global "PGE::Match", "newfrom"
@@ -47,7 +47,7 @@ Force a backtrack.  (Taken from A05.)
 
 =cut
 
-.sub fail
+.sub "fail"
     .param pmc mob
     $P0 = find_global "PGE::Match", "newfrom"
     .return $P0(mob)
@@ -384,21 +384,39 @@ Match whitespace between tokens.
     .local string target
     .local pmc mfrom, mpos
     .local int rep, pos, lastpos
+    .local string nextchars
     .const .Sub corou = "ws_corou"
+    nextchars = ""
+    $P0 = interpinfo .INTERPINFO_CURRENT_SUB
+    $P1 = getprop "nextchars", $P0
+    if_null $P1, ws_1
+    delprop $P0, "nextchars"
+    nextchars = $P1
+  ws_1:
     $P0 = find_global "PGE::Match", "newfrom"
     (mob, target, mfrom, mpos) = $P0(mob)
     lastpos = length target
     pos = mfrom
     if pos >= lastpos goto end
-    if pos < 1 goto ws_succ
+    if pos < 1 goto ws_scan
     $I0 = is_cclass .CCLASS_WORD, target, pos
-    if $I0 == 0 goto ws_succ
+    if $I0 == 0 goto ws_scan
     $I1 = pos - 1
     $I0 = is_cclass .CCLASS_WORD, target, $I1
-    if $I0 == 0 goto ws_succ
-    .return (mob)
-  ws_succ:
+    if $I0 == 0 goto ws_scan
+    goto end
+  ws_scan:
     $I0 = find_not_cclass .CCLASS_WHITESPACE, target, pos, lastpos
+    if nextchars == "" goto found
+  ws_scan2:
+    if $I0 < pos goto end
+    $S0 = substr target, $I0, 1
+    $I1 = index nextchars, $S0
+    if $I1 >= 0 goto found
+    $I1 = length nextchars
+    $I2 = find_cclass .CCLASS_WHITESPACE, nextchars, 0, $I1
+    if $I2 == $I1 goto end
+  found:
     mpos = $I0
     if $I0 == pos goto end
     $P0 = corou
@@ -425,7 +443,8 @@ Match whitespace between tokens.
 =item C<before(PMC mob, STR pattern)>
 
 Perform lookahead -- i.e., check if we're at a position where
-C<pattern> matches.  Always returns a zero-width Match object.
+C<pattern> matches.  Returns a zero-width Match object on
+success.
 
 =cut
 

Reply via email to