Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Detect undeclared stuff appearing in a BEGIN.
Previously we missed catching cases like BEGIN { unknown-thing() }
before going ahead and compiling the BEGIN block, leading to unhelpful
error messages at the BEGIN block's runtime.
  • Loading branch information
jnthn committed Apr 8, 2015
1 parent ee0086b commit 16ca41b
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/Perl6/Grammar.nqp
Expand Up @@ -1163,18 +1163,12 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
<.install_doc_phaser>

[ $ || <.typed_panic: 'X::Syntax::Confused'> ]


<.explain_mystery>
<.cry_sorrows>

{
# Emit any errors/worries.
self.explain_mystery();
if @*SORROWS {
if +@*SORROWS == 1 && !@*WORRIES {
@*SORROWS[0].throw()
}
else {
$*W.group_exception(@*SORROWS.pop).throw();
}
}
# Emit any worries.
if @*WORRIES {
nqp::printfh(nqp::getstderr(), $*W.group_exception().gist());
}
Expand Down Expand Up @@ -1814,7 +1808,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
rule statement_control:sym<CONTROL> {<sym> <block(1)> }

proto token statement_prefix { <...> }
token statement_prefix:sym<BEGIN> { <sym><.kok> <blorst> }
token statement_prefix:sym<BEGIN> { :my %*MYSTERY; <sym><.kok> <blorst> <.explain_mystery> <.cry_sorrows> }
token statement_prefix:sym<COMPOSE> { <sym><.kok> <blorst> }
token statement_prefix:sym<TEMP> { <sym><.kok> <blorst> }
token statement_prefix:sym<CHECK> { <sym><.kok> <blorst> }
Expand Down Expand Up @@ -4473,6 +4467,18 @@ grammar Perl6::Grammar is HLL::Grammar does STD {

self;
}

method cry_sorrows() {
if @*SORROWS {
if +@*SORROWS == 1 && !@*WORRIES {
@*SORROWS[0].throw()
}
else {
$*W.group_exception(@*SORROWS.pop).throw();
}
}
self
}

method add_variable($name) {
my $categorical := $name ~~ /^'&'((\w+)':<'\s*(\S+?)\s*'>')$/;
Expand Down

0 comments on commit 16ca41b

Please sign in to comment.