Author: fperrad
Date: Wed Mar 14 00:14:36 2007
New Revision: 17477
Modified:
trunk/languages/lua/doc/status.pod
trunk/languages/lua/lib/luaregex.pir
trunk/languages/lua/t/regex.t
trunk/languages/lua/t/rx_metachars
trunk/languages/lua/t/string.t
Log:
[Lua]
- regex balanced
Modified: trunk/languages/lua/doc/status.pod
==============================================================================
--- trunk/languages/lua/doc/status.pod (original)
+++ trunk/languages/lua/doc/status.pod Wed Mar 14 00:14:36 2007
@@ -177,6 +177,9 @@
Except math & table libraries, all of these libraries are incomplete.
+As compiled regex are not stored in Lua variable, the Regex compiler needs a
+Memoization mecanism (well-known optimization).
+
=head1 Extension Libraries
These libraries are loaded dynamically with the Lua function C<require>.
Modified: trunk/languages/lua/lib/luaregex.pir
==============================================================================
--- trunk/languages/lua/lib/luaregex.pir (original)
+++ trunk/languages/lua/lib/luaregex.pir Wed Mar 14 00:14:36 2007
@@ -688,15 +688,32 @@
.param string label
.param string next
- .local string x, y
+ .local string begin, end
$S0 = self
- x = substr $S0, 0, 1
- y = substr $S0, 1, 1
+ begin = substr $S0, 0, 1
+ begin = code.escape(begin)
+ end = substr $S0, 1, 1
+ end = code.escape(end)
- # TODO
- code.emit(<<" CODE", label, $S0, next)
- %0: # balanced %1
- goto %2
+ code.emit(<<" CODE", label, begin, end, next)
+ %0: # balanced
+ if pos >= lastpos goto fail
+ $S0 = substr target, pos, 1
+ if $S0 != %1 goto fail
+ $I1 = 1
+ %0_1:
+ inc pos
+ if pos >= lastpos goto fail
+ $S0 = substr target, pos, 1
+ if $S0 != %2 goto %0_2
+ dec $I1
+ if $I1 != 0 goto %0_1
+ inc pos
+ goto %3
+ %0_2:
+ if $S0 != %1 goto %0_1
+ inc $I1
+ goto %0_1
CODE
.return ()
.end
Modified: trunk/languages/lua/t/regex.t
==============================================================================
--- trunk/languages/lua/t/regex.t (original)
+++ trunk/languages/lua/t/regex.t Wed Mar 14 00:14:36 2007
@@ -47,7 +47,7 @@
use FindBin;
use lib "$FindBin::Bin";
-use Parrot::Test tests => 148;
+use Parrot::Test tests => 149;
use Test::More;
use File::Spec;
@@ -59,9 +59,6 @@
my %todo_info = (
7 => 'empty capture',
- 145 => 'balanced',
- 147 => 'balanced',
- 148 => 'balanced',
);
my $test_number = 0;
Modified: trunk/languages/lua/t/rx_metachars
==============================================================================
--- trunk/languages/lua/t/rx_metachars (original)
+++ trunk/languages/lua/t/rx_metachars Wed Mar 14 00:14:36 2007
@@ -100,5 +100,6 @@
a%b()f a(b(de)f nil balanced
a%b()f a(b(d)e)f a(b(d)e)f balanced
a%b''f a'bcde'f a'bcde'f balanced
+a%b""f a"bcde"f a"bcde"f balanced
## vim: noexpandtab tabstop=4 shiftwidth=4
Modified: trunk/languages/lua/t/string.t
==============================================================================
--- trunk/languages/lua/t/string.t (original)
+++ trunk/languages/lua/t/string.t Wed Mar 14 00:14:36 2007
@@ -266,8 +266,7 @@
print(string.gsub(test, "/%*.*%*/", "<COMMENT>"))
print(string.gsub(test, "/%*.-%*/", "<COMMENT>"))
s = "a (enclosed (in) parentheses) line"
--- print(string.gsub(s, "%b()", ""))
-print("a line", 1)
+print(string.gsub(s, "%b()", ""))
print(string.gsub("hello Lua!", "%a", "%0-%0"))
print(string.gsub("hello Lua", "(.)(.)", "%2%1"))
CODE