Author: fperrad
Date: Thu Mar 15 01:45:52 2007
New Revision: 17488

Modified:
   trunk/languages/lua/lib/luaregex.pir
   trunk/languages/lua/lib/luastring.pir
   trunk/languages/lua/t/regex.t

Log:
[Lua]
- regex: empty capture

Modified: trunk/languages/lua/lib/luaregex.pir
==============================================================================
--- trunk/languages/lua/lib/luaregex.pir        (original)
+++ trunk/languages/lua/lib/luaregex.pir        Thu Mar 15 01:45:52 2007
@@ -190,6 +190,9 @@
     $P0 = getclass 'PGE::Exp::CCShortcut'
     $P1 = subclass $P0, 'PGE::Exp::LuaCCShortcut'
 
+    $P0 = getclass 'PGE::Exp::CGroup'
+    $P1 = subclass $P0, 'PGE::Exp::LuaCGroup'
+
     $P0 = getclass 'PGE::Exp'
     $P1 = subclass $P0, 'PGE::Exp::LuaBalanced'
 .end
@@ -293,7 +296,7 @@
     optable.newtok('term:%8', 'equiv'=>'term:', 'nows'=>1, 'parsed'=>$P0)
     optable.newtok('term:%9', 'equiv'=>'term:', 'nows'=>1, 'parsed'=>$P0)
 
-    optable.newtok('circumfix:( )',   'equiv'=>'term:', 'nows'=>1, 
'nullterm'=>1, 'match'=>'PGE::Exp::CGroup')
+    optable.newtok('circumfix:( )',   'equiv'=>'term:', 'nows'=>1, 
'nullterm'=>1, 'match'=>'PGE::Exp::LuaCGroup')
 
     $P0 = get_hll_global ['PGE::LuaRegex'], 'parse_enumclass'
     optable.newtok('term:[', 'precedence'=>'=', 'nows'=>1, 'parsed'=>$P0)
@@ -593,7 +596,7 @@
 .end
 
 
-.namespace [ 'PGE::Exp::CGroup' ]
+.namespace [ 'PGE::Exp::LuaCGroup' ]
 
 .sub 'luaanalyze' :method
     .param pmc pad
@@ -615,6 +618,43 @@
     .return (self)
 .end
 
+.sub 'pir' :method
+    .param pmc code
+    .param string label
+    .param string next
+
+    $P0 = self[0]
+    $I0 = isa $P0, 'PGE::Exp::Literal'
+    unless $I0 goto super
+    $S0 = $P0
+    unless $S0 == '' goto super
+
+    .local pmc args
+    args = self.getargs(label, next)
+
+    .local string captgen, captsave, captback
+    (captgen, captsave, captback) = self.'gencapture'(label)
+
+    code.emit(<<"        CODE", captgen, captsave, captback, args :flat :named)
+        %L: # empty capture
+          %0
+          push ustack, captscope
+          new captob, .Integer
+          set captob, pos
+          inc captob
+          %1
+          bsr %S
+          %2
+          captscope = pop ustack
+          goto fail\n
+        CODE
+    .return ()
+
+  super:
+    $P0 = get_hll_global ['PGE::Exp::CGroup'], 'pir'
+    .return $P0(self, code, label, next)
+.end
+
 
 .namespace [ 'PGE::Exp::LuaCCShortcut' ]
 

Modified: trunk/languages/lua/lib/luastring.pir
==============================================================================
--- trunk/languages/lua/lib/luastring.pir       (original)
+++ trunk/languages/lua/lib/luastring.pir       Thu Mar 15 01:45:52 2007
@@ -253,8 +253,6 @@
 If the pattern has captures, then in a successful match the captured values
 are also returned, after the two indices.
 
-STILL INCOMPLETE (see F<languages/lua/lib/luaregex.pir>).
-
 =cut
 
 .sub '_string_find' :anon
@@ -359,32 +357,40 @@
 L2:
     unless $I0 < $I1 goto L3
     $P0 = capts[$I0]
+    $I10 = can $P0, 'text'
+    if $I10 goto L4
+    $I10 = $P0
+    new $P1, .LuaNumber
+    set $P1, $I10
+    goto L5
+L4:
     $S0 = $P0.'text'()
     $I2 = index $S0, "\0"
-    if $I2 < 0 goto L4
+    if $I2 < 0 goto L6
     # sorry, strictly compatible
     $S0 = substr $S0, 0, $I2
-L4:
+L6:
     new $P1, .LuaString
     set $P1, $S0
+L5:
     ret[$I0] = $P1
     inc $I0
     goto L2
 L3:
     .return (ret)
 L1:
-    unless whole == 1 goto L5
+    unless whole == 1 goto L7
     set ret, 1
     $S0 = match.'text'()
     $I2 = index $S0, "\0"
-    if $I2 < 0 goto L6
+    if $I2 < 0 goto L8
     # sorry, strictly compatible
     $S0 = substr $S0, 0, $I2
-L6:
+L8:
     new $P1, .LuaString
     set $P1, $S0
     ret[0] = $P1
-L5:
+L7:
     .return (ret)
 .end
 
@@ -612,8 +618,6 @@
         t[k] = v
     end
 
-STILL INCOMPLETE (see F<languages/lua/lib/luaregex.pir>).
-
 =cut
 
 .sub '_string_gmatch' :anon :lex
@@ -675,8 +679,6 @@
 to occur. For instance, when C<n> is 1 only the first occurrence of C<pat>
 is replaced.
 
-STILL INCOMPLETE (see F<languages/lua/lib/luaregex.pir>).
-
 =cut
 
 .sub '_string_gsub' :anon
@@ -750,9 +752,7 @@
 L4:
     $I0 = isa repl, 'LuaTable'
     unless $I0 goto L6
-    $S0 = onecapture(match, 0)
-    new $P0, .LuaString
-    set $P0, $S0
+    $P0 = onecapture(match, 0)
     $P1 = repl[$P0]
     goto L5
 L6:
@@ -825,17 +825,26 @@
 .sub 'onecapture' :anon
     .param pmc match
     .param int i
-    push_eh _handler
     $P0 = match.'get_array'()
     $P1 = $P0[i]
+    unless $P1 goto L1
+    $I0 = can $P1, 'text'
+    if $I0 goto L2
+    $I0 = $P1
+    new $P0, .LuaNumber
+    set $P0, $I0
+    .return ($P0)
+L2:
     $S0 = $P1.'text'()
     $I0 = index $S0, "\0"
-    if $I0 < 0 goto L1
+    if $I0 < 0 goto L3
     # sorry, strictly compatible
     $S0 = substr $S0, 0, $I0
+L3:
+    new $P0, .LuaString
+    set $P0, $S0
+    .return ($P0)
 L1:
-    .return ($S0)
-_handler:
     error("invalid capture index")
 .end
 
@@ -884,8 +893,6 @@
 returned. A third, optional numerical argument C<init> specifies where to
 start the search; its default value is 1 and may be negative.
 
-STILL INCOMPLETE (see F<languages/lua/lib/luaregex.pir>).
-
 =cut
 
 .sub '_string_match' :anon

Modified: trunk/languages/lua/t/regex.t
==============================================================================
--- trunk/languages/lua/t/regex.t       (original)
+++ trunk/languages/lua/t/regex.t       Thu Mar 15 01:45:52 2007
@@ -58,7 +58,6 @@
 );
 
 my %todo_info = (
-    7   => 'empty capture',
 );
 
 my $test_number = 0;

Reply via email to