Skip to content

Commit

Permalink
First round of changes to parse variable initializers as part of vari…
Browse files Browse the repository at this point in the history
…able_declarator. Basically works, though doesn't yet handle the attribute initializer case yet.
  • Loading branch information
jnthn committed Feb 8, 2012
1 parent f3058c8 commit 95a255a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
35 changes: 33 additions & 2 deletions src/Perl6/Actions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1295,10 +1295,26 @@ class Perl6::Actions is HLL::Actions {
method scope_declarator:sym<state>($/) { make $<scoped>.ast; }

method declarator($/) {
if $<variable_declarator> { make $<variable_declarator>.ast }
elsif $<routine_declarator> { make $<routine_declarator>.ast }
if $<routine_declarator> { make $<routine_declarator>.ast }
elsif $<regex_declarator> { make $<regex_declarator>.ast }
elsif $<type_declarator> { make $<type_declarator>.ast }
elsif $<variable_declarator> {
my $past := $<variable_declarator>.ast;
if $<initializer> {
say("in new init code");
if $<initializer>[0]<sym> eq '=' {
$past := assign_op($/, $past, $<initializer>[0].ast);
}
elsif $<initializer>[0]<sym> eq '.=' {
$past := make_dot_equals($past, $<initializer>[0].ast);
}
else {
$past := bind_op($/, $past, $<initializer>[0].ast,
$<initializer>[0]<sym> eq '::=');
}
}
make $past;
}
elsif $<signature> {
# Go over the params and declare the variable defined
# in them.
Expand All @@ -1320,6 +1336,21 @@ class Perl6::Actions is HLL::Actions {
$*W.create_container_descriptor(%cont_info<value_type>, 1, 'anon')));
}
}

if $<initializer> {
if $<initializer>[0]<sym> eq '=' {
$/.CURSOR.panic("Cannot assign to a list of 'has' scoped declarations")
if $*SCOPE eq 'has';
$list := assign_op($list, $<initializer>[0].ast);
}
elsif $<initializer>[0]<sym> eq '.=' {
$/.CURSOR.panic("Cannot use .= initializer with a list of declarations");
}
else {
$/.CURSOR.panic("Binding to signatures in $*SCOPE declarations not yet implemented");
}
}

make $list;
}
else {
Expand Down
21 changes: 12 additions & 9 deletions src/Perl6/Grammar.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,8 @@ grammar Perl6::Grammar is HLL::Grammar {

token declarator {
[
| <variable_declarator>
| '(' ~ ')' <signature> <trait>*
| <variable_declarator> <initializer>?
| '(' ~ ')' <signature> <trait>* <initializer>?
| <routine_declarator>
| <regex_declarator>
| <type_declarator>
Expand Down Expand Up @@ -1784,21 +1784,24 @@ grammar Perl6::Grammar is HLL::Grammar {

proto token initializer { <...> }
token initializer:sym<=> {
<sym> <.ws>
<sym>
[
|| <?{ $*LEFTSIGIL eq '$' }> <EXPR('i=')>
|| <EXPR('e=')>
<.ws>
[
|| <?{ $*LEFTSIGIL eq '$' }> <EXPR('i=')>
|| <EXPR('e=')>
]
|| <.panic: "Malformed initializer">
]
|| <.panic: "Malformed initializer">
}
token initializer:sym<:=> {
<sym> <.ws> <EXPR('e=')> || <.panic: "Malformed binding">
<sym> [ <.ws> <EXPR('e=')> || <.panic: "Malformed binding"> ]
}
token initializer:sym<::=> {
<sym> <.ws> <EXPR('e=')> || <.panic: "Malformed binding">
<sym> [ <.ws> <EXPR('e=')> || <.panic: "Malformed binding"> ]
}
token initializer:sym<.=> {
<sym> <.ws> <dottyopish> || <.panic: "Malformed mutator method call">
<sym> [ <.ws> <dottyopish> || <.panic: "Malformed mutator method call"> ]
}

rule trait {
Expand Down

0 comments on commit 95a255a

Please sign in to comment.