Skip to content

Commit

Permalink
introduce my \term before initializer is parsed
Browse files Browse the repository at this point in the history
(Still doesn't work, since we haven't really closed the definitional loop yet.)
  • Loading branch information
TimToady committed Aug 27, 2015
1 parent f3d060e commit ba5494a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
43 changes: 27 additions & 16 deletions src/Perl6/Actions.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,30 @@ class Perl6::Actions is HLL::Actions does STDActions {
}
}

method deftermnow($/) {
# 'my \foo' style declaration
if $*SCOPE ne 'my' {
$*W.throw($/, 'X::Comp::NYI',
feature => "$*SCOPE scoped term definitions (only 'my' is supported at the moment)");
}
my $name := $<defterm>.ast;
my $cur_lexpad := $*W.cur_lexpad;
if $cur_lexpad.symbol($name) {
$*W.throw($/, ['X', 'Redeclaration'], symbol => $name);
}
if $*OFTYPE {
my $type := $*OFTYPE.ast;
$cur_lexpad[0].push(QAST::Var.new( :$name, :scope('lexical'),
:decl('var'), :returns($type) ));
$cur_lexpad.symbol($name, :$type, :scope<lexical>);
}
else {
$cur_lexpad[0].push(QAST::Var.new(:$name, :scope('lexical'), :decl('var')));
$cur_lexpad.symbol($name, :scope('lexical'));
}
make $<defterm>.ast;
}

method defterm($/) {
my $name := ~$<identifier>;
if $<colonpair> {
Expand Down Expand Up @@ -2432,22 +2456,11 @@ Compilation unit '$file' contained the following violations:

make $list;
}
elsif $<defterm> {
elsif $<deftermnow> {
# 'my \foo' style declaration
if $*SCOPE ne 'my' {
$*W.throw($/, 'X::Comp::NYI',
feature => "$*SCOPE scoped term definitions (only 'my' is supported at the moment)");
}
my $name := $<defterm>.ast;
my $cur_lexpad := $*W.cur_lexpad;
if $cur_lexpad.symbol($name) {
$*W.throw($/, ['X', 'Redeclaration'], symbol => $name);
}
my $name := $<deftermnow>.ast;
if $*OFTYPE {
my $type := $*OFTYPE.ast;
$cur_lexpad[0].push(QAST::Var.new( :$name, :scope('lexical'),
:decl('var'), :returns($type) ));
$cur_lexpad.symbol($name, :$type, :scope<lexical>);
make QAST::Op.new(
:op<bind>,
QAST::Var.new(:$name, :scope<lexical>),
Expand All @@ -2461,14 +2474,12 @@ Compilation unit '$file' contained the following violations:
);
}
else {
$cur_lexpad[0].push(QAST::Var.new(:$name, :scope('lexical'), :decl('var')));
$cur_lexpad.symbol($name, :scope('lexical'));
make QAST::Op.new(
:op<bind>,
QAST::Var.new(:$name, :scope<lexical>),
$<term_init>.ast
);
}
}
}
else {
$/.CURSOR.panic('Unknown declarator type');
Expand Down
4 changes: 3 additions & 1 deletion src/Perl6/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
<subshortname> <sigterm>?
}

token deftermnow { <defterm> }

token defterm { # XXX this is probably too general
:dba('new term to be defined')
<identifier>
Expand Down Expand Up @@ -2286,7 +2288,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
[
# STD.pm6 uses <defterm> here, but we need different
# action methods
| '\\' <defterm>
| '\\' <deftermnow>
[ <.ws> <term_init=initializer> || <.typed_panic: "X::Syntax::Term::MissingInitializer"> ]
| <variable_declarator>
[
Expand Down

0 comments on commit ba5494a

Please sign in to comment.