Skip to content

Commit

Permalink
Allow $/ in subrule arg lists
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Oct 23, 2010
1 parent e7c2875 commit 5f8e944
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
33 changes: 19 additions & 14 deletions src/Niecza/Actions.pm
Expand Up @@ -762,22 +762,27 @@ sub assertion__S_name { my ($cl, $M) = @_;
"Qualified method calls NYI");
if ($M->{assertion}[0]) {
$M->{_ast} = $M->{assertion}[0]{_ast};
} elsif ($name eq 'sym') {
$M->{_ast} = RxOp::Sym->new;
return;
} elsif ($name eq 'before') {
$M->{_ast} = RxOp::Before->new(zyg => [$M->{nibbler}[0]{_ast}]);
return;
} elsif (!$M->{nibbler}[0] && !$M->{arglist}[0]) {
$M->{_ast} = RxOp::Subrule->new(method => $name);
} else {
if ($name eq 'sym') {
$M->{_ast} = RxOp::Sym->new;
return;
} elsif ($name eq 'before') {
$M->{_ast} = RxOp::Before->new(zyg => [$M->{nibbler}[0]{_ast}]);
return;
}
my $args = $M->{nibbler}[0] ?
[ $cl->op_for_regex($M, $M->{nibbler}[0]{_ast}) ] :
$M->{arglist}[0]{_ast};

if ($M->{nibbler}[0]) {
$M->{_ast} = RxOp::Subrule->new(method => $name,
arglist => [ $cl->op_for_regex($M, $M->{nibbler}[0]{_ast}) ]);
} else {
my $args = ($M->{arglist}[0] ? $M->{arglist}[0]{_ast} : []);
$M->{_ast} = RxOp::Subrule->new(arglist => $args, method => $name);
}
my $callop = Op::CallMethod->new(
receiver => Op::Lexical->new(name => ''),
name => $name,
args => $args);

my $regex = $cl->transparent($M, $callop, sig => Sig->simple(''));

$M->{_ast} = RxOp::Subrule->new(regex => $regex);
}
$M->{_ast} = $cl->rxcapturize($M, $name, $M->{_ast});
}
Expand Down
10 changes: 10 additions & 0 deletions test2.pl
Expand Up @@ -58,6 +58,16 @@

ok "abcabc" ~~ /^ (\w+) $0 $/, '$/ in variable refs functional';
ok "abcabc" ~~ /^ (\w+) "$0" $/, '$/ in substrings functional';

(grammar {
method moo($cap) { is $cap<cap>, "hi", '$/ from subrule args works'; @( self, ) }
token TOP { $<cap>={"hi"} <moo($/)> }
}).parse("");

#ok (grammar {
# method moo() { self }
# regex TOP { <.moo> }
#}).parse(""), "simply returning self from a regex works";
}

# {
Expand Down
5 changes: 3 additions & 2 deletions v6/TODO
Expand Up @@ -4,10 +4,10 @@ Cursor.mixin
Parcel.LISTSTORE
Highwater stuff
Audit nibble
self in regexes
$/ and $¢ in subrule argument lists
<after>
token { $param-role-var }
Fix simply returning self from a method

NOT NEEDED FOR #phasers:
Cursor.canonicalize_name
Expand All @@ -20,7 +20,6 @@ Cursor.gettrait
Cursor.load_lex
Cursor.add_categorical
Action methods
Make sure / (\w+) $0 / works
Non-string parameterized role arguments

DONE:
Expand All @@ -41,9 +40,11 @@ defined($thing)
:delete
:exists
$*FOO as a parameter
self in regexes
func(|($key => $value))
gt, lt, leg, etc
$*GOAL handling
Make sure / (\w+) $0 / works
Hash.keys &keys
Hash.LISTSTORE
infix:<x>
Expand Down

0 comments on commit 5f8e944

Please sign in to comment.