From 0139dac152d0abd5ed556f23d6865aacb96db649 Mon Sep 17 00:00:00 2001 From: Jonathan Worthington Date: Wed, 10 Jun 2020 13:45:54 +0200 Subject: [PATCH] Add RakuAST for [...] and {...} postcircumfixes --- src/Raku/Actions.nqp | 16 ++++++++++++---- src/Raku/Grammar.nqp | 20 +++++++++++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Raku/Actions.nqp b/src/Raku/Actions.nqp index 7ba0c741cc1..f5ccc85afd2 100644 --- a/src/Raku/Actions.nqp +++ b/src/Raku/Actions.nqp @@ -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 => $.ast // self.r('Infix').new($), + infix => $.ast // self.r('Infix').new($), left => $/[0].ast, right => $/[1].ast; } @@ -201,17 +201,17 @@ class Raku::Actions is HLL::Actions { @operands.push($_.ast); } make self.r('ApplyListInfix').new: - infix => $.ast // self.r('Infix').new($), + infix => $.ast // self.r('Infix').new($), operands => @operands; } elsif $KEY eq 'PREFIX' { make self.r('ApplyPrefix').new: - prefix => $.ast // self.r('Prefix').new($), + prefix => $.ast // self.r('Prefix').new($), operand => $/[0].ast; } elsif $KEY eq 'POSTFIX' { make self.r('ApplyPostfix').new: - postfix => $.ast // self.r('Postfix').new($), + postfix => $.ast // self.r('Postfix').new($), operand => $/[0].ast; } else { @@ -224,6 +224,14 @@ class Raku::Actions is HLL::Actions { } } + method postcircumfix:sym<[ ]>($/) { + make self.r('Postcircumfix', 'ArrayIndex').new($.ast); + } + + method postcircumfix:sym<{ }>($/) { + make self.r('Postcircumfix', 'HashIndex').new($.ast); + } + method infixish($/) { my $ast; if $ { diff --git a/src/Raku/Grammar.nqp b/src/Raku/Grammar.nqp index c4af18abcb1..9cedff073a1 100644 --- a/src/Raku/Grammar.nqp +++ b/src/Raku/Grammar.nqp @@ -453,8 +453,8 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { [ | | '.' ## dotted form of postfix operator (non-wordy only) -# | -# | '.' + | + | '.' # | # | # | && !$*QSIGIL }> @@ -469,13 +469,27 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { token postop { | $ = {$} $ = {$} -# | $ = {$} $ = {$} + | $ = {$} $ = {$} } method AS_MATCH($v) { self.'!clone_match_at'($v,self.pos()); } + token postcircumfix:sym<[ ]> { + :my $*QSIGIL := ''; + :dba('subscript') + '[' ~ ']' [ <.ws> ] + + } + + token postcircumfix:sym<{ }> { + :my $*QSIGIL := ''; + :dba('subscript') + '{' ~ '}' [ <.ws> ] + + } + token prefix:sym<++> { } token prefix:sym<--> { } token prefix:sym<++⚛> { }