Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix scoping of $*GOAL with ~
  • Loading branch information
sorear committed Nov 17, 2010
1 parent dfc2971 commit e302aa3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Niecza/Actions.pm
Expand Up @@ -341,14 +341,17 @@ sub encapsulate_regex { my ($cl, $M, $rxop, %args) = @_;
my @lift = $rxop->oplift;
my ($nrxop, $mb) = Optimizer::RxSimple::run($rxop);
my $lad = $rxop->lad;
unshift @lift, Op::Bind->new(readonly => 1,
lhs => Op::Lexical->new(name => '$*GOAL', declaring => 1),
rhs => Op::StringLiteral->new(text => $args{goal}))
if exists $args{goal};
# XXX do this in the signature so it won't be affected by transparent
my @parm = Sig::Parameter->new(slot => 'self', name => 'self', readonly => 1);
if (exists $args{goal}) {
push @parm, Sig::Parameter->new(slot => '$*GOAL', name => '$*GOAL',
readonly => 1, positional => 0, default =>
Op::StringLiteral->new(text => $args{goal}));
}
my $subop = $cl->transparent($M, Op::RegexBody->new(canback => $mb,
pre => \@lift, passcut => $args{passcut}, passcap => $args{passcap},
rxop => $nrxop), ltm => $lad, class => 'Regex', type => 'regex',
sig => Sig->simple->for_method);
sig => Sig->new(params => \@parm));
$subop = Op::CallSub->new(node($M), invocant => $subop, positionals => [ Op::MakeCursor->new(node($M)) ]);
return RxOp::Subrule->new(regex => $subop, passcap => $args{passcap},
_passcapzyg => $nrxop, _passcapltm => $lad);
Expand Down
51 changes: 51 additions & 0 deletions v6/tryfile
Expand Up @@ -56,6 +56,29 @@ augment class Hash {

augment class STD {
our $ALL;
method do_use($module,$args) {
self.do_need($module);
self.do_import($module,$args);
self;
}

method do_need($mo) {
my $module = $mo.Str;
my $topsym;
try { $topsym = self.sys_load_modinfo($module); }
if !$topsym {
self.panic("Could not load $module");
}
self.add_my_name($module);
$*DECLARAND<really> = $topsym;
self;
}

method sys_load_modinfo($module) {
# TODO: Implement compile-on-demand. Requires some kind of modtime API.
from-jsync(slurp($module ~ ".syml"));
}

my %term = (:dba('term') , :prec<z=>);
my %methodcall = (:dba('methodcall') , :prec<y=>, :assoc<unary>, :uassoc<left>, :fiddly, :!pure);
my %autoincrement = (:dba('autoincrement') , :prec<x=>, :assoc<unary>, :uassoc<non>, :!pure);
Expand Down Expand Up @@ -282,8 +305,36 @@ method do_import_aliases($pkg, *@names) {
}

augment class STD::P6 {
my %item_assignment = (:dba('item assignment') , :prec<i=>, :assoc<right>, :!pure);
my %term = (:dba('term') , :prec<z=>);
my %methodcall = (:dba('methodcall') , :prec<y=>, :assoc<unary>, :uassoc<left>, :fiddly, :!pure);
token infixish ($in_meta = $*IN_META) {
:my ($infix, $O, $sym);
:my $*IN_META = $in_meta;
<!stdstopper>
<!infixstopper>
:dba('infix or meta-infix')
[
| <colonpair> $<fake> = {1} { $sym = ':' }
{ $O = {:prec(%item_assignment<prec>), :assoc<unary>,
:dba<adverb> } }
# actual test is non-inclusive!
| [
| :dba('bracketed infix') '[' ~ ']' <infix=.infixish('[]')> { $O = $<infix><O>; $sym = $<infix><sym> }
| <infix=infix_circumfix_meta_operator> { $O = $<infix><O>; $sym = $<infix><sym>; }
| <infix=infix_prefix_meta_operator> { $O = $<infix><O>; $sym = $<infix><sym>; }
| <infix> { $O = $<infix><O>; $sym = $<infix><sym>; }
| {} <?dotty> <.panic: "Method call found where infix expected (omit whitespace?)">
| {} <?postfix> <.panic: "Postfix found where infix expected (omit whitespace?)">
]
[ <?before '='> <assign_meta_operator($<infix>)>
{$O = $<assign_meta_operator>[0]<O>}
{$sym = $<assign_meta_operator>[0]<sym>}
]?

]
$<O> = { $O } $<sym> = { $sym }
}
token trait_mod:of {
['of'|'returns']:s <typename>
[ <?{ $*DECLARAND<of> }> <.sorry("Extra 'of' type; already declared as type " ~ $*DECLARAND<of>.Str)> ]?
Expand Down

0 comments on commit e302aa3

Please sign in to comment.