Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix parsing of ::<$a>, implement Foo:: = Foo.WHO syntax
  • Loading branch information
sorear committed Aug 2, 2011
1 parent f2fccf7 commit c1c841b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/Kernel.cs
Expand Up @@ -2761,7 +2761,7 @@ public struct StashCursor {
if (bind_to != null)
throw new NieczaException("cannot bind a psuedo package");
{
P6any who = Kernel.BoxRaw(sc, Kernel.PseudoStashMO);
P6any who = Kernel.BoxRaw(this, Kernel.PseudoStashMO);
who.SetSlot("name", Kernel.BoxAnyMO(key, Kernel.StrMO));
v = MakePackage(key, who);
}
Expand Down Expand Up @@ -2789,6 +2789,7 @@ public struct StashCursor {
Variable v;
int ix1 = 0;
string sigil = "";
string last = "ROOT";
while (true) {
int ix2 = key.IndexOf("::", ix1);
if (ix2 < 0) {
Expand All @@ -2804,10 +2805,20 @@ public struct StashCursor {

if (elt != "") {
sc.Core(elt, false, out r, out v, null);
last = elt;
sc = r;
}
}
key = sigil + key;
if (key == "") {
if (bind_to != null)
throw new NieczaException("Cannot bind to a stash");
if (sc.type == WHO)
return Kernel.NewROScalar((P6any) sc.p1);
P6any who = Kernel.BoxRaw(sc, Kernel.PseudoStashMO);
who.SetSlot("name", Kernel.BoxAnyMO(last, Kernel.StrMO));
return Kernel.NewROScalar(who);
}
if (bind_to != null) {
bool list = key != "" && (key[0] == '@' || key[0] == '%');
bind_to = Kernel.NewBoundVar(list ? Kernel.NBV_LIST :
Expand Down
40 changes: 40 additions & 0 deletions src/niecza
Expand Up @@ -42,6 +42,46 @@ class Op::IndirectVar is Op {


augment class NieczaActions {
method term:name ($/) {
my ($name) = self.process_name($<longname>, :defer);

if $<args> {
$name<name> = '&' ~ $name<name> if $name<name>;
$name<iname> = mkstringycat($/, '&', $name<iname>) if $name<iname>;
}

if $name<iname> {
make ::Op::IndirectVar.new(|node($/), name => $name<iname>);
}
elsif $name<pkg> {
make self.package_var($/, self.gensym, $name<name>, $name<pkg>);
} else {
make mklex($/, $name<name>);
}

my @pc = @( $<postcircumfix> );
if @pc && @pc[0].substr(0,1) eq '[' {
make mkcall($/, '&_param_role_inst', $/.ast, @( @pc[0].ast.args ));
shift @pc;
} elsif $<args> {
my $sal = $<args>.ast // [];
# TODO: support zero-D slicels

if $sal > 1 {
$/.CURSOR.sorry("Slicel lists are NYI");
return;
}

make ::Op::CallSub.new(|node($/), invocant => $/.ast,
args => $sal[0] // []);
}

if @pc {
make @pc[0].ast.with_args($/, $/.ast);
}
}


method variable_declarator($/) {
if $*MULTINESS {
$/.CURSOR.sorry("Multi variables NYI");
Expand Down

0 comments on commit c1c841b

Please sign in to comment.