Author: pmichaud
Date: Thu Nov 3 19:22:37 2005
New Revision: 9768
Modified:
trunk/compilers/pge/PGE/Exp.pir
trunk/compilers/pge/PGE/P6Rule.pir
trunk/lib/Parrot/Test/PGE.pm
trunk/t/p6rules/builtins.t
trunk/t/p6rules/metachars.t
Log:
* Fixed test harness to selectively mark targets as unicode.
* Added conjunctions (&) to expressions.
* Updated tests in metachars.t and builtins.t.
Modified: trunk/compilers/pge/PGE/Exp.pir
==============================================================================
--- trunk/compilers/pge/PGE/Exp.pir (original)
+++ trunk/compilers/pge/PGE/Exp.pir Thu Nov 3 19:22:37 2005
@@ -20,8 +20,8 @@
$P1 = subclass $P0, "PGE::Exp::EnumCharList"
$P1 = subclass $P0, "PGE::Exp::Anchor"
$P1 = subclass $P0, "PGE::Exp::Concat"
- $P1 = subclass $P0, "PGE::Exp::Conj"
$P1 = subclass $P0, "PGE::Exp::Alt"
+ $P1 = subclass $P0, "PGE::Exp::Conj"
$P1 = subclass $P0, "PGE::Exp::Group"
$P1 = subclass $P0, "PGE::Exp::Subrule"
$P1 = subclass $P0, "PGE::Exp::Cut"
@@ -680,6 +680,48 @@ register.
.return ()
.end
+
+.namespace [ "PGE::Exp::Conj" ]
+
+.sub "gen" :method
+ .param pmc code
+ .param string label
+ .param string next
+ .local pmc emit
+ .local pmc exp0, exp1
+ .local string exp0label, exp1label, chk0label, chk1label
+ emit = find_global "PGE::Exp", "emit"
+ (exp0label, $I0) = self.serno()
+ (exp1label, $I1) = self.serno()
+ chk0label = concat label, "_0"
+ chk1label = concat label, "_1"
+ emit(code, "\n %s: # conj %s, %s ##", label, exp0label, exp1label)
+ emit(code, " push gpad, pos")
+ emit(code, " push gpad, pos")
+ self.emitsub(code, exp0label, "NOCUT")
+ emit(code, " $I0 = pop gpad")
+ emit(code, " $I0 = pop gpad")
+ emit(code, " goto fail")
+ emit(code, " %s:", chk0label)
+ emit(code, " gpad[-1] = pos")
+ emit(code, " pos = gpad[-2]")
+ emit(code, " goto %s", exp1label)
+ emit(code, " %s:", chk1label)
+ emit(code, " $I0 = gpad[-1]")
+ emit(code, " if $I0 != pos goto fail")
+ emit(code, " $I0 = pop gpad")
+ emit(code, " $I1 = pop gpad")
+ self.emitsub(code, next, "$I0", "$I1", "NOCUT")
+ emit(code, " push gpad, $I1")
+ emit(code, " push gpad, $I0")
+ emit(code, " goto fail")
+ exp0 = self[0]
+ exp0.gen(code, exp0label, chk0label)
+ exp1 = self[1]
+ exp1.gen(code, exp1label, chk1label)
+ .return ()
+.end
+
.namespace [ "PGE::Exp::Quant" ]
Modified: trunk/compilers/pge/PGE/P6Rule.pir
==============================================================================
--- trunk/compilers/pge/PGE/P6Rule.pir (original)
+++ trunk/compilers/pge/PGE/P6Rule.pir Thu Nov 3 19:22:37 2005
@@ -60,7 +60,8 @@
optable.addtok("postfix:::", "postfix:*", "left", $P0)
optable.addtok("infix:", "<postfix:*", "right,nows", "PGE::Exp::Concat")
- optable.addtok("infix:|", "<infix:", "left,nows", "PGE::Exp::Alt")
+ optable.addtok("infix:&", "<infix:", "left,nows", "PGE::Exp::Conj")
+ optable.addtok("infix:|", "<infix:&", "left,nows", "PGE::Exp::Alt")
optable.addtok("infix::=", ">postfix:*", "right", "PGE::Exp::Alias")
@@ -678,6 +679,20 @@
end:
.return (self)
.end
+
+.namespace [ "PGE::Exp::Conj" ]
+
+.sub "p6analyze" :method
+ .param pmc pad
+ $P0 = self[0]
+ $P0 = $P0.p6analyze(pad)
+ self[0] = $P0
+ $P1 = self[1]
+ $P1 = $P1.p6analyze(pad)
+ self[1] = $P1
+ .return (self)
+.end
+
.namespace [ "PGE::Exp::Quant" ]
Modified: trunk/lib/Parrot/Test/PGE.pm
==============================================================================
--- trunk/lib/Parrot/Test/PGE.pm (original)
+++ trunk/lib/Parrot/Test/PGE.pm Thu Nov 3 19:22:37 2005
@@ -191,6 +191,7 @@ sub _generate_pir_for {
my($target, $pattern, $captures) = @_;
$target = _parrot_stringify($target);
$pattern = _parrot_stringify($pattern);
+ my $unicode = ($target =~ /\\u/) ? "unicode:" : "";
if ($captures) {
$captures = qq(
print "\\n"
@@ -213,7 +214,7 @@ sub _generate_pir_for {
.local pmc match
.local pmc code
.local pmc exp
- target = unicode:"$target"
+ target = $unicode"$target"
pattern = "$pattern"
(rulesub, code, exp) = p6rule_compile(pattern)
match = rulesub(target)
Modified: trunk/t/p6rules/builtins.t
==============================================================================
--- trunk/t/p6rules/builtins.t (original)
+++ trunk/t/p6rules/builtins.t Thu Nov 3 19:22:37 2005
@@ -124,7 +124,7 @@ p6rule_like ("aabaaa", '<!before ..b> a
## leading + -- enumerated char class
p6rule_is ('az', '<[a..z]>+', 'metasyntax with leading + (<+...>)');
p6rule_is ('az', '<+[a..z]>+', 'metasyntax with leading + (<+...>)');
-p6rule_is ('az', '<+<alpha>>+', 'metasyntax with leading + (<+...>)',
+p6rule_is ('az', '<+alpha>+', 'metasyntax with leading + (<+...>)',
todo => 'not yet implemented');
Modified: trunk/t/p6rules/metachars.t
==============================================================================
--- trunk/t/p6rules/metachars.t (original)
+++ trunk/t/p6rules/metachars.t Thu Nov 3 19:22:37 2005
@@ -96,13 +96,13 @@ p6rule_isnt("\n", '\n $$', 'line beginni
## &
-p6rule_is ("c", '[a..d] & [b..e]', 'conjunction (&)', todo => 'not yet
implemented');
-p6rule_isnt("c", '[a..d] & [d..e]', 'conjunction (&)');
-p6rule_isnt("c", '[a..b] & [b..e]', 'conjunction (&)');
-p6rule_is ("bcd", '[a..d]+ & [b..e]+', 'conjunction (&)', todo => 'not yet
implemented');
-p6rule_is ("bcd", '^ [a..d]+ & [b..e]+ $', 'conjunction (&)', todo => 'not
yet implemented');
-p6rule_isnt("bcd", '[a..c]+ & [b..e]+', 'conjunction (&)');
-p6rule_isnt("bcd", '[a..d]+ & [c..e]+', 'conjunction (&)');
+p6rule_is ("c", '<[a..d]> & <[b..e]>', 'conjunction (&)');
+p6rule_isnt("c", '<[a..d]> & <[d..e]>', 'conjunction (&)');
+p6rule_isnt("c", '<[a..b]> & <[b..e]>', 'conjunction (&)');
+p6rule_is ("bcd", '<[a..d]>+ & <[b..e]>+', 'conjunction (&)');
+p6rule_is ("bcd", '^ <[a..d]>+ & <[b..e]>+ $', 'conjunction (&)');
+p6rule_is ("bcd", '<[a..c]>+ & <[b..e]>+', 'conjunction (&)');
+p6rule_is ("bcd", '<[a..d]>+ & <[c..e]>+', 'conjunction (&)');
## \p and \P -- deprecated