Author: fperrad
Date: Wed Mar 7 00:15:09 2007
New Revision: 17375
Modified:
trunk/languages/lua/lib/luaregex.pir
trunk/languages/lua/t/regex.t
trunk/languages/lua/t/string.t
Log:
[Lua]
- regex: handle back reference
Modified: trunk/languages/lua/lib/luaregex.pir
==============================================================================
--- trunk/languages/lua/lib/luaregex.pir (original)
+++ trunk/languages/lua/lib/luaregex.pir Wed Mar 7 00:15:09 2007
@@ -282,6 +282,17 @@
optable.newtok('term:%x', 'equiv'=>'term:', 'nows'=>1,
'match'=>'PGE::Exp::LuaCCShortcut')
optable.newtok('term:%X', 'equiv'=>'term:', 'nows'=>1,
'match'=>'PGE::Exp::LuaCCShortcut')
+ $P0 = get_hll_global ['PGE::LuaRegex'], 'parse_backref'
+ optable.newtok('term:%1', 'equiv'=>'term:', 'nows'=>1, 'parsed'=>$P0)
+ optable.newtok('term:%2', 'equiv'=>'term:', 'nows'=>1, 'parsed'=>$P0)
+ optable.newtok('term:%3', 'equiv'=>'term:', 'nows'=>1, 'parsed'=>$P0)
+ optable.newtok('term:%4', 'equiv'=>'term:', 'nows'=>1, 'parsed'=>$P0)
+ optable.newtok('term:%5', 'equiv'=>'term:', 'nows'=>1, 'parsed'=>$P0)
+ optable.newtok('term:%6', 'equiv'=>'term:', 'nows'=>1, 'parsed'=>$P0)
+ optable.newtok('term:%7', 'equiv'=>'term:', 'nows'=>1, 'parsed'=>$P0)
+ 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')
$P0 = get_hll_global ['PGE::LuaRegex'], 'parse_enumclass'
@@ -541,6 +552,28 @@
.end
+.sub 'parse_backref'
+ .param pmc mob
+ .local string target
+ .local int pos
+ .local pmc newfrom, mfrom, mpos
+ .local string cname
+ newfrom = get_hll_global ['PGE::Match'], 'newfrom'
+ $P0 = getattribute mob, '$.target'
+ target = $P0
+ $P0 = getattribute mob, '$.pos'
+ pos = $P0
+ $I0 = pos - 1
+ $S0 = substr target, $I0, 1
+ (mob, $P0, mfrom, mpos) = newfrom(mob, 0, 'PGE::Exp::Scalar')
+ $I0 = $S0
+ dec $I0
+ mob["cname"] = $I0
+ mpos = pos
+ .return (mob)
+.end
+
+
.namespace [ 'PGE::Exp' ]
.sub 'luaanalyze' :method
Modified: trunk/languages/lua/t/regex.t
==============================================================================
--- trunk/languages/lua/t/regex.t (original)
+++ trunk/languages/lua/t/regex.t Wed Mar 7 00:15:09 2007
@@ -47,7 +47,7 @@
use FindBin;
use lib "$FindBin::Bin";
-use Parrot::Test 'no_plan';
+use Parrot::Test tests => 148;
use Test::More;
use File::Spec;
@@ -59,8 +59,6 @@
my %todo_info = (
7 => 'empty capture',
- 8 => 'back reference',
- 9 => 'back reference',
145 => 'balanced',
147 => 'balanced',
148 => 'balanced',
@@ -90,13 +88,14 @@
$output =~ s/\\03/\03/g;
$output =~ s/\\04/\04/g;
$output =~ s/\\0/\0/g;
+ chomp $desc;
$test_number ++;
my $code = "print(string.match(\"$target\", \"$pattern\"))";
local $TODO = $todo_info{$test_number} if (exists
$todo_info{$test_number});
if ($output =~ /^\//) {
- language_output_like( 'lua', $code, $output . "\n", $desc );
+ language_output_like( 'lua', $code, $output, $desc );
}
else {
language_output_is( 'lua', $code, $output . "\n", $desc );
Modified: trunk/languages/lua/t/string.t
==============================================================================
--- trunk/languages/lua/t/string.t (original)
+++ trunk/languages/lua/t/string.t Wed Mar 7 00:15:09 2007
@@ -377,9 +377,6 @@
name Anna
OUTPUT
-TODO: {
- local $TODO = 'back reference';
-
language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function string.match
(back ref)' );
s = [[then he said: "it's all right"!]]
q, quotedPart = string.match(s, "([\"'])(.-)%1")
@@ -393,7 +390,6 @@
"
= [[ something ]] ]==]x
OUTPUT
-}
language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function string.rep' );
print(string.rep("ab", 3))