Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Refactor scope and variable declarators.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 26, 2009
1 parent 4039648 commit 09880e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
19 changes: 15 additions & 4 deletions src/NQP/Actions.pm
Expand Up @@ -86,23 +86,34 @@ method statement_control:sym<unless>($/) {
## Terms

method noun:sym<variable>($/) { make $<variable>.ast; }
method noun:sym<scoped>($/) { make $<scoped>.ast; }
method noun:sym<scope_declarator>($/) { make $<scope_declarator>.ast; }

method variable($/) {
make PAST::Var.new( :name(~$/) );
}

method scope_declarator:sym<my>($/) { make $<scoped>.ast; }
method scope_declarator:sym<our>($/) {
my $past := $<scoped>.ast;
$past.scope('package');
@BLOCK[0].symbol( $past.name, :scope('package') );
make $past;
}

method scoped($/) {
make $<variable_declarator>.ast;
}

method variable_declarator($/) {
my $past := $<variable>.ast;
my $name := $past.name;
if @BLOCK[0].symbol($name) {
$/.CURSOR.panic("Redeclaration of symbol ", $name);
}
my $scope := $<scope_declarator> eq 'our' ?? 'package' !! 'lexical';
$past.scope($scope);
$past.scope('lexical');
$past.isdecl(1);
$past.viviself('Undef');
@BLOCK[0].symbol( $name, :scope($scope) );
@BLOCK[0].symbol( $name, :scope('lexical') );
make $past;
}

Expand Down
11 changes: 8 additions & 3 deletions src/NQP/Grammar.pm
Expand Up @@ -72,7 +72,7 @@ token statement_control:sym<unless> {
## Terms

token noun:sym<variable> { <variable> }
token noun:sym<scoped> { <scoped> }
token noun:sym<scope_declarator> { <scope_declarator> }

token variable {
<sigil> <twigil>? <desigilname=ident>
Expand All @@ -82,11 +82,16 @@ token sigil { <[$@%&]> }

token twigil { <[*]> }

proto token scope_declarator { <...> }
token scope_declarator:sym<my> { <sym> <scoped> }
token scope_declarator:sym<our> { <sym> <scoped> }

rule scoped {
$<scope_declarator>=[my|our]
<variable>
| <variable_declarator>
}

token variable_declarator { <variable> }

proto token term { <...> }

token term:sym<identifier> {
Expand Down

0 comments on commit 09880e0

Please sign in to comment.