Author: pmichaud
Date: Sun May  8 08:36:49 2005
New Revision: 8010

Modified:
   trunk/compilers/pge/PGE/Exp.pir
   trunk/compilers/pge/PGE/Match.pir
   trunk/compilers/pge/README
   trunk/compilers/pge/demo.pir
Log:
Bugfixes to "isarray" handling for groups
Corrected __get_pmc_keyed in Match
Updated demo.pir to support subrules


Modified: trunk/compilers/pge/PGE/Exp.pir
==============================================================================
--- trunk/compilers/pge/PGE/Exp.pir     (original)
+++ trunk/compilers/pge/PGE/Exp.pir     Sun May  8 08:36:49 2005
@@ -830,7 +830,7 @@
     .param pmc next
     .param pmc pad
     .local pmc exp1
-    .local int isarray
+    .local int isarray, psave
     .local pmc creps
     .local string cname
 
@@ -846,9 +846,9 @@
     unless $I0 goto isarray_0                      # skip if no capture
     $P0 = self["cname"]
     cname = $P0
-    cname = concat "%", cname
     $I0 = isa $P0, "Integer"                       # Integer = subpattern cap
     if $I0 goto creps_2
+    cname = concat "%", cname
   creps_2:
     $I0 = exists creps[cname]                      # have seen capture name?
     unless $I0 goto creps_3                        #
@@ -859,20 +859,23 @@
     creps[cname] = self                            # mark us for future ref
 
   isarray_0:
-    isarray = pad["isarray"]                       # set group's isarray
-    $I0 = self["isarray"]                          # and pass along to
-    isarray |= $I0                                 # nested objects
-    self["isarray"] = isarray
-    $I0 = self["cscope"]
-    unless $I0 goto isarray_1
+    psave = pad["isarray"]                         # get current isarray status
+    isarray = self["isarray"]                      # combine with group's
+    isarray |= psave                               # 
+    self["isarray"] = isarray                      # and pass to nested
+    pad["isarray"] = isarray
+    $I0 = self["cscope"]                           # new scope resets
+    unless $I0 goto isarray_1                      # array status
+    pad["isarray"] = 0
     isarray = 0                                    # each capt obj is single
     delete pad["creps"]                            # new lexical name scope
   isarray_1:
     $I0 = defined self["exp1"]
     unless $I0 goto end
     exp1 = self["exp1"]
-    pad["isarray"] = isarray
     exp1.analyze(next, pad)
+    pad["isarray"] = psave
+
   fc:
     $I0 = self["min"]                              # set up firstchars
     if $I0 > 0 goto fc_2

Modified: trunk/compilers/pge/PGE/Match.pir
==============================================================================
--- trunk/compilers/pge/PGE/Match.pir   (original)
+++ trunk/compilers/pge/PGE/Match.pir   Sun May  8 08:36:49 2005
@@ -160,47 +160,35 @@
     .return ("")
 .end
 
-=item C<__get_pmc_keyed_int(INT key)>
+=item C<__get_pmc_keyed(PMC key)>
 
-Returns the subpattern capture associated with key.  Note that
-this will return either a single Match object or an array of
-match objects depending on the rule.
+Returns the subpattern or subrule capture associated with C<key>.  
+If the first character of C<key> is a digit then return the
+subpattern, otherwise return the subrule.  Note that this will 
+return either a single Match object or an array of match objects 
+depending on the rule.
 
 =cut
 
-.sub "__get_pmc_keyed_int" method
-    .param int key
+.sub "__get_pmc_keyed" method
+    .param pmc key
     .local pmc capt
+    $S0 = key
+    $I0 = is_digit $S0, 0
+    unless $I0 goto keyed_1
     capt = getattribute self, "PGE::Match\x0@:capt"
-    $P0 = capt[key]
-    $P1 = getprop "isarray", $P0
-    unless $P1 goto end
-    $P1 = $P1[-1]
-  end:
-    .return ($P1)
-.end
-
-=item C<__get_pmc_keyed_str(STR key)>
-
-Returns the subrule capture associated with C<key>.  Note that
-this can return either a single Match object or an array of
-Match objects depending on the rule.
-
-=cut
-
-.sub "__get_pmc_keyed_str" method
-    .param int key
-    .local pmc capt
+    goto keyed_2
+  keyed_1:
     capt = getattribute self, "PGE::Match\x0%:capt"
+  keyed_2:
     $P0 = capt[key]
     $P1 = getprop "isarray", $P0
-    unless $P1 goto end
-    $P1 = $P1[-1]
+    if $P1 goto end
+    $P0 = $P0[-1]
   end:
-    .return ($P1)
+    .return ($P0)
 .end
 
-
 =item C<dump()>
 
 Produces a data dump of the match object and all of its subcaptures.

Modified: trunk/compilers/pge/README
==============================================================================
--- trunk/compilers/pge/README  (original)
+++ trunk/compilers/pge/README  Sun May  8 08:36:49 2005
@@ -29,7 +29,8 @@
 example of using PGE.  To run the demo, simply do 
 C<parrot demo.pir>.  The demo understands the following commands:
 
-    rule <pattern>    - a perl 6 rule to be matched
+    rule pattern      - compile a Perl 6 rule from "pattern"
+    save name         - save the current rule as "name"
     text              - a text string to match against previously entered rule
     pir               - display the PIR cod generated for current rule
     exp               - display the expression tree for the current rule
@@ -95,7 +96,7 @@
 patterns in groups -- that's coming next.
 
 This is just the first-cut framework for building the 
-remainder of the engine, so many items (assertions, lookaround, 
+remainder of the engine, so many items (lookaround, 
 conjunctions, closures, character classes, and hypotheticals)
 just aren't implemented yet.  They're on their way!
 

Modified: trunk/compilers/pge/demo.pir
==============================================================================
--- trunk/compilers/pge/demo.pir        (original)
+++ trunk/compilers/pge/demo.pir        Sun May  8 08:36:49 2005
@@ -15,9 +15,12 @@
     find_global p6rule_compile, "PGE", "p6rule"
     istrace = 0
     null rulesub
+
+    (rulesub, pir, exp) = p6rule_compile("\w+")
+    store_global "ident", rulesub
    
   read_loop:
-    print "\ninput \"rule <pattern>\", \"glob <pattern>\", \"pir\",\n"
+    print "\ninput \"rule <pattern>\", \"save <name>\", \"pir\", \"exp\", \n"
     print "target string, \"trace\", or \"next\"\n"
     getstdin stdin
     readline x, stdin
@@ -31,6 +34,7 @@
     chopn x, 1
     if $S0 == "next" goto match_next
     if $S0 == "rule" goto make_p6rule
+    if $S0 == "save" goto save_rule
     if $S0 == "pir" goto print_pir
     if $S0 == "exp" goto print_exp
     if $S0 == "trace" goto toggle_trace
@@ -57,6 +61,16 @@
     pattern = substr x, 5
     (rulesub, pir, exp) = p6rule_compile(pattern)
     goto read_loop
+
+  save_rule:
+    isnull rulesub, match_nopattern
+    x = substr x, 5
+    store_global x, rulesub
+    print "Saved as "
+    print x
+    print "\n"
+    goto read_loop
+    
   
   print_pir:
     isnull rulesub, match_nopattern

Reply via email to