Permalink
Browse files

Ensure that interpretation of variables always precedes validation

  • Loading branch information...
1 parent 8609d73 commit 58f8f28436646e4c7b443b02fdcda72fe339b25b @sorear committed Mar 31, 2012
Showing with 11 additions and 9 deletions.
  1. +7 −0 src/NieczaActions.pm6
  2. +4 −9 src/STD.pm6
@@ -428,6 +428,7 @@ method sublongname($/) {
method desigilname($/) {
if $<variable> {
make { ind => self.do_variable_reference($/, $<variable>.ast) };
+ self.check_variable($<variable>);
} else {
make self.process_name($<longname>, :defer);
}
@@ -786,6 +787,7 @@ method metachar:var ($/) {
if !defined $cid {
$/.CURSOR.sorry("Non-Match bindings NYI");
+ # self.check_variable($<variable>);
make $RxOpSequence.new;
return Nil;
}
@@ -814,6 +816,7 @@ method metachar:var ($/) {
make $RxOpListPrim.new(name => ~$<variable>, type => $kind,
ops => self.rxembed($/,
self.do_variable_reference($/, $<variable>.ast), True));
+ self.check_variable($<variable>);
}
method rxcapturize($M, $name, $rxop is copy) { #OK not used
@@ -1682,6 +1685,7 @@ method methodop($/) {
} elsif $<variable> {
make $Operator_Function.new(function =>
self.do_variable_reference($/, $<variable>.ast));
+ self.check_variable($<variable>);
}
$/.ast.args = $<args>.ast[0] // [] if $<args>;
@@ -1773,6 +1777,7 @@ method colonpair($/) {
if $tv ~~ Hash {
$tv = self.do_variable_reference($/, $tv);
+ self.check_variable($<v>);
}
make { term => $OpSimplePair.new(key => $<k>, value => $tv) };
@@ -1986,6 +1991,7 @@ method check_variable ($variable) {
my $here = $variable.CURSOR.cursor($variable.from);
$here.deb("check_variable $name") if $*DEBUG +& DEBUG::symtab;
my ($sigil, $twigil, $first) = $name ~~ /(\$|\@|\%|\&)(\W*)(.?)/;
+ $variable.ast<checked> || $here.sorry("do_variable_reference must always precede check_variable");
($first,$twigil) = ($twigil, '') if $first eq '';
given $twigil {
when '' {
@@ -2060,6 +2066,7 @@ method check_variable ($variable) {
}
method do_variable_reference($M, $v) {
+ $v<checked> = True;
if $v<term> {
return $v<term>;
}
View
@@ -2050,7 +2050,7 @@ grammar P6 is STD {
| <coloncircumfix('')>
{ $key = ""; $value = $<coloncircumfix>; }
| $<var> = <.colonpair_var>
- { $key = $<var><desigilname>.Str; $value = $<var>; $Actions.check_variable($value); }
+ { $key = $<var><desigilname>.Str; $value = $<var>; }
]
$<k> = {$key} $<v> = {$value}
}
@@ -2354,10 +2354,7 @@ grammar P6 is STD {
[
| <?before '$' >
[ <?{ $*IN_DECL }> <.panic: "Cannot declare an indirect variable name"> ]?
- <variable> {
- $*VAR = $<variable>;
- $Actions.check_variable($*VAR) if substr($*VAR,1,1) ne '$';
- }
+ <variable>
| <?before <[\@\%\&]> <sigil>* \w > <.panic: "Invalid hard reference syntax">
| <longname>
]
@@ -3371,7 +3368,7 @@ grammar P6 is STD {
token methodop {
[
| <longname>
- | <?before '$' | '@' | '&' > <variable> { $Actions.check_variable($<variable>) }
+ | <?before '$' | '@' | '&' > <variable>
| <?before <[ ' " ]> >
[ <!{$*QSIGIL}> || <!before '"' <-["]>*? \s > ] # dwim on "$foo."
<quote>
@@ -4935,9 +4932,7 @@ grammar Regex is STD {
$<sym> = {$<variable>.Str}
[
|| $<binding> = ( \s* '=' \s* <quantified_atom> )
- { $Actions.check_variable($<variable>) unless substr($<sym>,1,1) eq '<' }
- || { $Actions.check_variable($<variable>) }
- [ <?before '.'? <[ \[ \{ \< ]>> <.worry: "Apparent subscript will be treated as regex"> ]?
+ || [ <?before '.'? <[ \[ \{ \< ]>> <.worry: "Apparent subscript will be treated as regex"> ]?
]
}

0 comments on commit 58f8f28

Please sign in to comment.