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

Commit

Permalink
[nqp]: Add simple parameters to signatures.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 26, 2009
1 parent 4c4a0e2 commit 4c594ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/NQP/Actions.pm
Expand Up @@ -145,6 +145,21 @@ method routine_def($/) {
make $past;
}

method signature($/) {
my $BLOCKINIT := @BLOCK[0][0];
for $<parameter> { $BLOCKINIT.push($_.ast); }
}

method parameter($/) { make $<param_var>.ast; }

method param_var($/) {
my $past := $<variable>.ast;
$past.isdecl(1);
$past.scope('parameter');
@BLOCK[0].symbol($past.name, :scope('lexical') );
make $past;
}

method term:sym<identifier>($/) {
my $past := $<args>.ast;
$past.name(~$<identifier>);
Expand Down
8 changes: 8 additions & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -100,9 +100,17 @@ token routine_declarator:sym<sub> { <sym> <routine_def> }
rule routine_def {
<deflongname=ident>?
<.newpad>
[ '(' <signature> ')'
|| <.panic: 'Routine declaration requires a signature'> ]
<blockoid>
}

token signature { [ [<.ws><parameter><.ws>] ** ',' ]? }

token parameter { <param_var> }

token param_var { <variable> }

proto token term { <...> }

token term:sym<identifier> {
Expand Down

0 comments on commit 4c594ad

Please sign in to comment.