Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement correct-style <{ }> assertion

  • Loading branch information...
commit 40118edf04fec0df0f2179432d7e2b7858009501 1 parent c2f6274
@sorear authored
View
1  docs/TODO.S05
@@ -29,7 +29,6 @@ All line numbers are relative to c4882a67. Also, deliberate discrepencies.)
(1461) Arguments in <&foo(2)> not handled; STD parses EXPR but only this legal
(1507) No support for indirect <::($name)> calls
Also, nice fossil.
-(1533) <{ }> has wrong semantics
(1565) Code assertions not always considered declarative
(1585) <[ z..a ]> not treated as compile error DISCUSS
(1634) No Unicode properties
View
6 src/RxOp.pm6
@@ -519,14 +519,16 @@ class Alt is AltBase {
class CheckBlock is RxOp {
has $.block = die "CheckBlock.block required"; # Op
+ has Bool $.negate;
method ctxopzyg() { $!block, 1 }
method opzyg() { $!block }
method code($body) {
- CgOp.ncgoto('backtrack', CgOp.obj_getbool($!block.cgop($body)));
+ my $m = $!negate ?? "cgoto" !! "ncgoto";
+ CgOp."$m"('backtrack', CgOp.obj_getbool($!block.cgop($body)));
}
- method lad() { ['Imp'] }
+ method lad() { ['Null'] }
}
class SaveValue is RxOp {
View
30 src/niecza
@@ -123,6 +123,36 @@ class RxOp::ListPrim is RxOp {
}
augment class NieczaActions {
+method assertion:sym<{ }> ($/) {
+ $/.CURSOR.trymop({
+ $<embeddedblock>.ast.add_my_name('$¢', :noinit, |mnode($/));
+ $<embeddedblock>.ast.set_signature(Sig.simple('$¢'));
+ });
+
+ make ::RxOp::ListPrim.new(type => 'scalar_asn', ops => self.inliney_call($/,
+ $<embeddedblock>.ast, ::Op::MakeCursor.new(|node($/))));
+}
+
+method assertion:sym<?> ($/) {
+ if $<assertion> {
+ make $<assertion>.reduced eq 'assertion:sym<{ }>' ??
+ ::RxOp::CheckBlock.new(block => $<assertion>.ast.ops, :!negate) !!
+ ::RxOp::Before.new(zyg => [self.decapturize($/)]);
+ } else {
+ make ::RxOp::Sequence.new;
+ }
+}
+
+method assertion:sym<!> ($/) {
+ if $<assertion> {
+ make $<assertion>.reduced eq 'assertion:sym<{ }>' ??
+ ::RxOp::CheckBlock.new(block => $<assertion>.ast.ops, :negate) !!
+ ::RxOp::NotBefore.new(zyg => [self.decapturize($/)]);
+ } else {
+ make ::RxOp::None.new;
+ }
+}
+
method assertion:variable ($/) {
given substr($/,0,1) {
when '&' {
View
4 test.pl
@@ -1186,8 +1186,8 @@
is { a => 1, b => 2 }.<b>, 2, "hash constructors work w/ lists";
ok { } ~~ Hash, "hash constructors work w/ nothing";
-ok !('xy' ~~ /x <{ False }> y/), '<{False}> blocks a match';
-ok 'xy' ~~ /x <{ True }> y/, '<{True}> does not affect it';
+ok !('xy' ~~ /x <?{ False }> y/), '<{False}> blocks a match';
+ok 'xy' ~~ /x <?{ True }> y/, '<{True}> does not affect it';
ok (1 < 3 > 2), "CHAIN works with dissimilar ops";
{
View
5 test2.pl
@@ -62,6 +62,11 @@
is +[@l], 3, 'binding to existing list vars works';
}
+{
+ my $rxd = / (\d+) <{ "a ** $0" }> /;
+ is ("3aaa" ~~ $rxd), "3aaa", '<{}> works';
+}
+
is [ 1,2,3 ... 10 ], [1..10];
is [ 1,2,4 ... 256 ], [map 2 ** *, 0..8];
is [ 1,1,*+* ...^ *>100 ], [1,1,2,3,5,8,13,21,34,55,89];
Please sign in to comment.
Something went wrong with that request. Please try again.