Author: particle
Date: Wed Nov 16 14:26:24 2005
New Revision: 10052

Modified:
   trunk/compilers/pge/PGE/Match.pir
   trunk/t/p6rules/context.t
Log:
PGE: implemented '__get_string_keyed_int' for PGE::Match
* allows syntax like ' $S0 = match[0] '
* added test

Modified: trunk/compilers/pge/PGE/Match.pir
==============================================================================
--- trunk/compilers/pge/PGE/Match.pir   (original)
+++ trunk/compilers/pge/PGE/Match.pir   Wed Nov 16 14:26:24 2005
@@ -188,6 +188,25 @@ Returns the portion of the target string
     .return ("")
 .end
 
+=item C<__get_string_keyed_int(int key)>
+
+Returns the portion of the target string matched by C<key>,
+in string context. If the Match object contains an array of
+matches, a space seperated list of matches is returned.
+
+=cut
+
+.sub "__get_string_keyed_int" method
+       .param int key
+    $P0 = getattribute self, "PGE::Match\x0@:capt"
+       $S0 = ''
+    if_null $P0, get_1
+    $P0 = $P0[key]
+       $S0 = $P0
+  get_1:
+    .return ($S0)
+.end
+
 =item C<__get_pmc_keyed_int(int key)>
 
 Returns the subpattern capture associated with C<key>.  This

Modified: trunk/t/p6rules/context.t
==============================================================================
--- trunk/t/p6rules/context.t   (original)
+++ trunk/t/p6rules/context.t   Wed Nov 16 14:26:24 2005
@@ -182,6 +182,20 @@ pir_output_is($PRE.<<'CODE'.$POST,<<OUT,
 CODE

 cba

 OUT

+pir_output_is($PRE.<<'CODE'.$POST,<<OUT,'as array ([2,1,0] => "cba")');

+       rulesub = p6rule('(a)(b)(c)')

+       match = rulesub('abc')

+       .local string res

+       res = match[2]

+       print res

+       res = match[1]

+       print res

+       res = match[0]

+       print res

+       goto END

+CODE

+cba

+OUT

 ## TODO: more 

 

 

@@ -232,4 +246,4 @@ OUT

 

 

 # remember to change the number of tests :-)

-BEGIN { plan tests => 15; }

+BEGIN { plan tests => 16; }

Reply via email to