Skip to content

Commit

Permalink
Parse method/submethod in RakuAST frontend
Browse files Browse the repository at this point in the history
And wire them up to the existing AST nodes. Still some work to go until
we can actually call a declared method.
  • Loading branch information
jnthn committed Aug 27, 2020
1 parent d62cee4 commit 7a82872
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Raku/Actions.nqp
Expand Up @@ -617,6 +617,12 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
method routine_declarator:sym<sub>($/) {
make $<routine_def>.ast;
}
method routine_declarator:sym<method>($/) {
make $<method_def>.ast;
}
method routine_declarator:sym<submethod>($/) {
make $<method_def>.ast;
}

method routine_def($/) {
my $routine := $*BLOCK;
Expand All @@ -628,6 +634,16 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
make $routine;
}

method method_def($/) {
my $routine := $*BLOCK;
if $<signature> {
$routine.replace-signature($<signature>.ast);
}
$routine.replace-body($<blockoid>.ast);
$routine.calculate-sink();
make $routine;
}

##
## Values
##
Expand Down
16 changes: 16 additions & 0 deletions src/Raku/Grammar.nqp
Expand Up @@ -1204,6 +1204,12 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
token routine_declarator:sym<sub> {
<sym> <.end_keyword> <routine_def('sub')>
}
token routine_declarator:sym<method> {
<sym> <.end_keyword> <method_def('method')>
}
token routine_declarator:sym<submethod> {
<sym> <.end_keyword> <method_def('submethod')>
}

rule routine_def($declarator) {
:my $*IN_DECL := $declarator;
Expand All @@ -1215,6 +1221,16 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
<.leave-block-scope>
}

rule method_def($declarator) {
:my $*IN_DECL := $declarator;
:my $*BLOCK;
<.enter-block-scope(nqp::tclc($declarator))>
<deflongname>?
[ '(' <signature> ')' ]?
<blockoid>
<.leave-block-scope>
}

##
## Values
##
Expand Down

0 comments on commit 7a82872

Please sign in to comment.