Permalink
Browse files

Support <::($bar)>, <Foo::($bar)> regex syntax (possibly this should …

…not capture?)
  • Loading branch information...
1 parent 59f5ccb commit 797fd448539b5c37cdf84116ac45ced1835f17df @sorear committed Jan 29, 2012
Showing with 58 additions and 2 deletions.
  1. +0 −2 docs/TODO.S05
  2. +58 −0 src/niecza
View
@@ -33,8 +33,6 @@ LOL: feature requires slice context mappings.
(1253) No handling of formal parameters in LTM
(1276) Declarativeness of constants is insufficiently general
(1461) DISCUSS: STD parses EXPR in assertion:variable, why?
-(1507) No support for indirect <::($name)> calls
- Also, nice fossil.
(1585) <[ z..a ]> not treated as compile error DISCUSS
(1679) No <.>
(1718) No <?same>, <?at($pos)>
View
@@ -49,6 +49,64 @@ our ($RxOp, $RxOpAlt, $RxOpAny, $RxOpBefore, $RxOpCut, $RxOpConj, $RxOpCutLTM,
our ($Sig, $SigParameter, $PassSimplifier, $CClass); #OK
our $Actions; $Actions = $Actions but role {
+method assertion:name ($/) {
+ my ($pname) = self.process_name($<longname>, :defer);
+ my $name = ~$<longname>;
+
+ if !$pname {
+ $pname = { name => 'alpha' };
+ $/.CURSOR.sorry('Method call requires a method name');
+ }
+
+ my @lex = $*CURLEX<!sub>.lookup_lex("&$name");
+ my $is_lexical = substr($/.orig, $/.from-1, 1) ne '.' &&
+ @lex && @lex[0] eq 'sub' && @lex[4].is_regex;
+
+ if $<assertion> {
+ make $<assertion>.ast;
+ } elsif $name eq 'sym' {
+ $/.CURSOR.sorry("<sym> is only valid in multiregexes")
+ unless defined %*RX<sym>;
+ make $RxOpSym.new(igcase => %*RX<i>, igmark => %*RX<a>,
+ text => %*RX<sym> // '', endsym => %*RX<endsym>);
+ } elsif $name eq 'before' {
+ make $RxOpBefore.new(zyg => [$<nibbler>.ast]);
+ return Nil;
+ } elsif $name eq 'after' {
+ my @l = $<nibbler>.ast.tocclist;
+ if grep { !defined $_ }, @l {
+ $/.CURSOR.sorry("Unsuppored elements in after list");
+ make $RxOpSequence.new;
+ return Nil;
+ }
+ make $RxOpZeroWidthCCs.new(neg => False, after => True, ccs => @l);
+ return;
+ } elsif !$<nibbler> && !$<arglist> && !$pname<pkg> && !$pname<iname> &&
+ !$is_lexical {
+ make $RxOpSubrule.new(method => $pname<name>);
+ } else {
+ my $args = $<nibbler> ??
+ [ self.op_for_regex($/, $<nibbler>.ast) ] !!
+ $<arglist> ?? $<arglist>.ast !! [];
+
+ my $callop;
+ if $is_lexical {
+ $callop = $OpCallSub.new(invocant => mklex($/, "&$name"),
+ positionals => [ mklex($/, '$¢'), @$args ]);
+ } elsif $pname<iname> {
+ $callop = $Operator_Method.new(name => $pname<iname>, :$args,
+ meta => '::(').with_args($/, mklex($/, '$¢'));
+ } else {
+ $callop = $Operator_Method.new(name => $pname<name>, :$args,
+ package => $pname<pkg>).with_args($/, mklex($/, '$¢'));
+ }
+
+ my $regex = self.rxembed($/, $callop, True);
+
+ make $RxOpSubrule.new(regex => $regex);
+ }
+ make self.rxcapturize($/, ~$<longname>, $/.ast);
+}
method methodop($/) {
if $<longname> {
my ($c) = self.process_name($<longname>, :defer);

0 comments on commit 797fd44

Please sign in to comment.