Author: pmichaud
Date: Wed May  7 14:55:54 2008
New Revision: 27383

Modified:
   trunk/compilers/pge/PGE/Perl6Regex.pir
   trunk/t/compilers/pge/perl6regex/rx_captures

Log:
[pge]:
* Add <alias=foo> syntax for capturing subrules.


Modified: trunk/compilers/pge/PGE/Perl6Regex.pir
==============================================================================
--- trunk/compilers/pge/PGE/Perl6Regex.pir      (original)
+++ trunk/compilers/pge/PGE/Perl6Regex.pir      Wed May  7 14:55:54 2008
@@ -737,8 +737,15 @@
     if key == '<?' goto scan_subname             ## FIXME: RT#53834
     if key == '<!' goto negated
 
-    ##  it's a capturing subrule
+    ##  capturing subrule, get its name/alias
     iscapture = 1
+    .local string subname, cname
+    (subname, pos) = 'parse_subname'(target, pos)
+    cname = subname
+    $S0 = substr target, pos, 1
+    unless $S0 == '=' goto subrule_arg
+    ##  aliased subrule, skip the '=' and get the real name
+    inc pos
     goto scan_subname
 
   negated:
@@ -747,12 +754,11 @@
     mob['iszerowidth'] = 1
 
   scan_subname:
-    .local string subname
     (subname, pos) = 'parse_subname'(target, pos)
-    mob['subname'] = subname
-    $S0 = substr target, pos, 1
 
   subrule_arg:
+    mob['subname'] = subname
+    $S0 = substr target, pos, 1
     if $S0 == ':' goto subrule_text_arg
     if $S0 != ' ' goto subrule_end
   subrule_pattern_arg:
@@ -793,7 +799,7 @@
     mob.'to'(pos)
     mob['iscapture'] = iscapture
     unless iscapture goto end
-    $S0 = escape subname
+    $S0 = escape cname
     $S0 = concat '"', $S0
     $S0 = concat $S0, '"'
     mob['cname'] = $S0

Modified: trunk/t/compilers/pge/perl6regex/rx_captures
==============================================================================
--- trunk/t/compilers/pge/perl6regex/rx_captures        (original)
+++ trunk/t/compilers/pge/perl6regex/rx_captures        Wed May  7 14:55:54 2008
@@ -57,4 +57,7 @@
 # todo :pugs<feature>
 (.)*x                                  123x            /mob: <123x @ 0>/       
repeated dot capture
 
+$<key>=<alpha>                         12ab34          /mob<key>: <a @ 2>/     
alias capture
+<key=alpha>                            12ab34          /mob<key>: <a @ 2>/     
alias capture
+
 ## vim: noexpandtab tabstop=4 shiftwidth=4

Reply via email to