Skip to content

Commit

Permalink
Add RakuAST for [...] and {...} postcircumfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jun 10, 2020
1 parent 825bac4 commit 0139dac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
16 changes: 12 additions & 4 deletions src/Raku/Actions.nqp
Expand Up @@ -191,7 +191,7 @@ class Raku::Actions is HLL::Actions {
my $key := nqp::lc($KEY);
if $KEY eq 'INFIX' {
make self.r('ApplyInfix').new:
infix => $<infix>.ast // self.r('Infix').new($<infix><sym>),
infix => $<OPER>.ast // self.r('Infix').new($<infix><sym>),
left => $/[0].ast,
right => $/[1].ast;
}
Expand All @@ -201,17 +201,17 @@ class Raku::Actions is HLL::Actions {
@operands.push($_.ast);
}
make self.r('ApplyListInfix').new:
infix => $<infix>.ast // self.r('Infix').new($<infix><sym>),
infix => $<OPER>.ast // self.r('Infix').new($<infix><sym>),
operands => @operands;
}
elsif $KEY eq 'PREFIX' {
make self.r('ApplyPrefix').new:
prefix => $<prefix>.ast // self.r('Prefix').new($<prefix><sym>),
prefix => $<OPER>.ast // self.r('Prefix').new($<prefix><sym>),
operand => $/[0].ast;
}
elsif $KEY eq 'POSTFIX' {
make self.r('ApplyPostfix').new:
postfix => $<postfix>.ast // self.r('Postfix').new($<postfix><sym>),
postfix => $<OPER>.ast // self.r('Postfix').new($<postfix><sym>),
operand => $/[0].ast;
}
else {
Expand All @@ -224,6 +224,14 @@ class Raku::Actions is HLL::Actions {
}
}

method postcircumfix:sym<[ ]>($/) {
make self.r('Postcircumfix', 'ArrayIndex').new($<semilist>.ast);
}

method postcircumfix:sym<{ }>($/) {
make self.r('Postcircumfix', 'HashIndex').new($<semilist>.ast);
}

method infixish($/) {
my $ast;
if $<infix> {
Expand Down
20 changes: 17 additions & 3 deletions src/Raku/Grammar.nqp
Expand Up @@ -453,8 +453,8 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
[
| <OPER=postfix>
| '.' <?before \W> <OPER=postfix> ## dotted form of postfix operator (non-wordy only)
# | <OPER=postcircumfix>
# | '.' <?[ [ { < ]> <OPER=postcircumfix>
| <OPER=postcircumfix>
| '.' <?[ [ { < ]> <OPER=postcircumfix>
# | <OPER=dotty>
# | <OPER=privop>
# | <?{ $<postfix_prefix_meta_operator> && !$*QSIGIL }>
Expand All @@ -469,13 +469,27 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {

token postop {
| <postfix> $<O> = {$<postfix><O>} $<sym> = {$<postfix><sym>}
# | <postcircumfix> $<O> = {$<postcircumfix><O>} $<sym> = {$<postcircumfix><sym>}
| <postcircumfix> $<O> = {$<postcircumfix><O>} $<sym> = {$<postcircumfix><sym>}
}

method AS_MATCH($v) {
self.'!clone_match_at'($v,self.pos());
}

token postcircumfix:sym<[ ]> {
:my $*QSIGIL := '';
:dba('subscript')
'[' ~ ']' [ <.ws> <semilist> ]
<O(|%methodcall)>
}

token postcircumfix:sym<{ }> {
:my $*QSIGIL := '';
:dba('subscript')
'{' ~ '}' [ <.ws> <semilist> ]
<O(|%methodcall)>
}

token prefix:sym<++> { <sym> <O(|%autoincrement)> }
token prefix:sym<--> { <sym> <O(|%autoincrement)> }
token prefix:sym<++⚛> { <sym> <O(|%autoincrement)> }
Expand Down

0 comments on commit 0139dac

Please sign in to comment.