1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/*
* SPL - The SPL Programming Language
* Copyright (C) 2004, 2005 Clifford Wolf <clifford@clifford.at>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* example39.spl: Some more advanced regex tests
*/
// SKIP_IF_NO_REGEX
function test1()
{
var x = "foolish bigfoot";
var r = x =~ /(?P<word>(?P<firstchar>\S)\S*)\s*/APLg;
foreach i (r) {
var $$;
r[i].word =~ s/foo(.*)/bar$1/;
debug "Match #$i: [${r[i].firstchar}] ${r[i].word} ($0)";
}
var text1 = "Ever seen a ${r[0].word} $1?";
var text2 = text1 =~ s/seen/beeing eaten by/R;
debug text1;
debug text2;
}
function test2()
{
var x ="foobar";
x =~ /(?P<foo>f.+)/;
debug "$1 == $<1> == $<foo>";
var a = $1;
var b = $<1>;
var c = $<foo>;
debug "$a == $b == $c";
}
function test3()
{
var x = "axbxxax";
x =~ s/(?<!x)(?P<foobar>x)/y/g;
debug x;
}
function test4()
{
var text = "Hello World";
if (text =~ /(?P<foo>\S+)\s+(?P<bar>\S+)/) {
import $$;
debug "$foo $bar";
}
if (declared foo)
panic "This is never reached";
if (text =~ /(?P<foo>\S+)\s+(?P<bar>\S+)/I) {
debug "$foo $bar";
}
if (declared foo)
debug "Foo is now defined here too.";
}
function test5()
{
function x() {
"faxbar" =~ /f../;
debug $0;
}
"foobar" =~ /f../;
x();
debug $0;
}
test1();
test2();
test3();
test4();
test5();
|