diff --git a/src/Raku/Actions.nqp b/src/Raku/Actions.nqp index e5d6665afd4..99f49410e31 100644 --- a/src/Raku/Actions.nqp +++ b/src/Raku/Actions.nqp @@ -1053,7 +1053,7 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { if ($/.pragma("STOPPER") // '') eq $sym { $/.worry: "Ambiguous use of $sym; use " - ~ ($ eq '>>' ?? '»' !! '>>') + ~ ($sym eq '>>' ?? '»' !! '>>') ~ " instead to mean hyper, or insert whitespace before" ~ " $sym to mean a quote terminator (or use different delimiters?)"; } @@ -1146,30 +1146,32 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { method methodop($/) { my $args := $ ?? $.ast !! Nodify('ArgList').new(); if $ { - if $*special { - my $longname := $.ast; + my $longname := $.ast; + my $name := $longname.canonicalize; + + if $*DOTTY { + my $DOTTY := $*DOTTY; unless $longname.is-identifier { - $/.dotty-non-ident($*special); + $/.dotty-non-ident($DOTTY); } - my $name := $longname.canonicalize; - if $*special eq '!' { - self.attach: $/, Nodify('Call', 'PrivateMethod').new(:name($.ast), :$args); + if $DOTTY eq '!' { + self.attach: $/,Nodify('Call','PrivateMethod').new(:name($longname),:$args); } - elsif $*special eq '.^' { + elsif $DOTTY eq '.^' { self.attach: $/, Nodify('Call', 'MetaMethod').new(:$name, :$args); } - elsif $*special eq '.?' { + elsif $DOTTY eq '.?' { self.attach: $/, Nodify('Call', 'MaybeMethod').new(:$name, :$args); } - elsif $*special eq '.&' { - self.attach: $/, Nodify('Call', 'VarMethod').new(:name($.ast), :$args); + elsif $DOTTY eq '.&' { + self.attach: $/, Nodify('Call', 'VarMethod').new(:name($longname), :$args); } else { - nqp::die("Missing compilation of $*special"); + nqp::die("Missing compilation of $DOTTY"); } } else { - self.attach: $/, Nodify('Call', 'Method').new(:name($.ast), :$args); + self.attach: $/, Nodify('Call', 'Method').new(:name($longname), :$args); } } elsif $ { diff --git a/src/Raku/Grammar.nqp b/src/Raku/Grammar.nqp index 3b578f090d0..6aca3655ba7 100644 --- a/src/Raku/Grammar.nqp +++ b/src/Raku/Grammar.nqp @@ -1626,7 +1626,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { my $OPER := $op; if $OPER { self.typed-panic("X::Syntax::CannotMeta", - meta => meta, + meta => $meta, operator => ~$OPER, dba => ~$OPER.made, reason => "too $reason" @@ -1695,77 +1695,113 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { regex infixstopper { :dba('infix stopper') [ - | - | > + | + + | > + + ] } +#------------------------------------------------------------------------------- proto token infix-prefix-meta-operator {*} + # !foo token infix-prefix-meta-operator:sym { - {} [ || <.panic: "Negation metaoperator not followed by valid infix"> ] + + + {} + [ + || <.panic: "Negation metaoperator not followed by valid infix"> + ] .Str eq '=' }> [ - || <.can-meta($, "negate")> .made }> - )> - || { self.typed-panic: "X::Syntax::CannotMeta", meta => "negate", operator => ~$, dba => ~$.made, reason => "not iffy enough" } + || <.can-meta: $, "negate"> + .made }> + )> + + || { self.typed-panic: "X::Syntax::CannotMeta", + meta => "negate", + operator => ~$, + dba => ~$.made, + reason => "not iffy enough" + } ] } + # Rfoo token infix-prefix-meta-operator:sym { - {} - <.can-meta($, "reverse the args of")> - )> + + + {} + <.can-meta: $, "reverse the args of"> + )> } + # Helper token / method to reverse left/right associativity token revO($from) { - :my $*FROM := $from.made; + :my $*FROM := $from.made; } + # Xfoo token infix-prefix-meta-operator:sym { - {} - <.can-meta($, "cross with")> + + + {} + <.can-meta: $, "cross with"> } + # Zfoo token infix-prefix-meta-operator:sym { - {} - <.can-meta($, "zip with")> + + + {} + <.can-meta: $, "zip with"> } +#------------------------------------------------------------------------------- + proto token infix-postfix-meta-operator {*} + # foo= token infix-postfix-meta-operator:sym<=> { + :my $OPER := $*OPER; :my %prec; :my %fudge_oper; '=' - { %fudge_oper := $*OPER } - <.can-meta(%fudge_oper, "make assignment out of")> - [ .made }> || <.can-meta(%fudge_oper, "make assignment out of", "diffy")> ] + { %fudge_oper := $OPER } + <.can-meta: %fudge_oper, "make assignment out of"> + [ .made }> + || <.can-meta: %fudge_oper, "make assignment out of", "diffy"> + ] { - $ := $*OPER ~ '='; - if $*OPER.made gt 'g=' { - %prec := %item_assignment; - } - else { - %prec := %list_assignment; - } + $ := $OPER ~ '='; + %prec := $OPER.made gt 'g=' + ?? %item_assignment + !! %list_assignment; } - {} + } +#------------------------------------------------------------------------------- + proto token infix-circumfix-meta-operator {*} + # «foo» token infix-circumfix-meta-operator:sym<« »> { $=[ '«' | '»' ] - {} + {} + $=[ '«' | '»' || <.missing: "« or »"> ] <.can-meta($, "hyper with")> - {} )> + {} + )> } + # <> token infix-circumfix-meta-operator:sym«<< >>» { $=[ '<<' | '>>' ] {} @@ -1773,6 +1809,8 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { {} )> } +#------------------------------------------------------------------------------- + token prefixish { :dba('prefix') @@ -1786,32 +1824,44 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { | '<<' } +#------------------------------------------------------------------------------- + token postfixish { # last whitespace didn't end here - [ [ <.unspace> | '\\' ] ]? + [ + [ <.unspace> | '\\' ] + ]? :dba('postfix') - [ ['.' <.unspace>?]? <.unspace>?]? [ - | - | '.' ## dotted form of postfix operator (non-wordy only) - | - | '.' - | - | - | && !$*QSIGIL }> + ['.' <.unspace>?]? <.unspace>?]? + [ + | + + # dotted form of postfix operator (non-wordy only) + | '.' + + | + + | '.' + + | + + | + + | && !$*QSIGIL }> [ - || <.missing: "postfix"> - || <.missing: "dot on method call"> - || <.malformed: "postfix"> + || <.missing: "postfix"> + || <.missing: "dot on method call"> + || <.malformed: "postfix"> ] ] { $*LEFTSIGIL := '@'; } @@ -1825,11 +1875,25 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { } token postop { - | $ = {$} $ = {$} - | $ = {$} $ = {$} + | + $ = {$} + $ = {$} + + | + $ = {$} + $ = {$} } +#------------------------------------------------------------------------------- + proto token postcircumfix {*} + + token postcircumfix:sym<( )> { + :dba('argument list') + '(' ~ ')' [ <.ws> ] + + } + token postcircumfix:sym<[ ]> { :my $*QSIGIL := ''; :dba('subscript') @@ -1847,10 +1911,19 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { token postcircumfix:sym { '<' [ - || ", ['q', 'w', 'v']))> '>' - || '='* | ':' ] > - { $/.panic("Whitespace required before $/ operator") } - || { $/.panic("Unable to parse quote-words subscript; couldn't find '>' (corresponding '<' was at line {HLL::Compiler.lineof($/.orig(), $/.from(), :cache(1))})") } + || ", ['q', 'w', 'v'] + ))> + '>' + + || '='* | ':' ] > + { $/.panic: "Whitespace required before $/ operator" } + + || { $/.typed-panic: 'X::QuoteWords::Missing::Closer', + opener => '<', + closer => '>', + line => HLL::Compiler.lineof($/.orig, $/.from, :cache(1)) + } ] } @@ -1859,8 +1932,16 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { :dba('shell-quote words') '<<' [ - || >", ['qq', 'ww', 'v']))> '>>' - || { $/.panic("Unable to parse quote-words subscript; couldn't find '>>' (corresponding '<<' was at line {HLL::Compiler.lineof($/.orig(), $/.from(), :cache(1))})") } + || >", ['qq', 'ww', 'v'] + ))> + '>>' + + || { $/.typed-panic: 'X::QuoteWords::Missing::Closer', + opener => '<<', + closer => '>>', + line => HLL::Compiler.lineof($/.orig, $/.from, :cache(1)) + } ] } @@ -1869,36 +1950,44 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { :dba('shell-quote words') '«' [ - || '»' - || { $/.panic("Unable to parse quote-words subscript; couldn't find '»' (corresponding '«' was at line {HLL::Compiler.lineof($/.orig(), $/.from(), :cache(1))})") } + || + '»' + + || { $/.typed-panic: 'X::QuoteWords::Missing::Closer', + opener => '«', + closer => '»', + line => HLL::Compiler.lineof($/.orig, $/.from, :cache(1)) + } ] } - token postcircumfix:sym<( )> { - :dba('argument list') - '(' ~ ')' [ <.ws> ] - - } +#------------------------------------------------------------------------------- proto token dotty {*} token dotty:sym<.> { - + + } token dotty:sym<.^> { - + + } token dotty:sym<.?> { - + + } token dotty:sym<.&> { - + + } @@ -1906,19 +1995,24 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { :dba('dotty method or postfix') <.unspace>? [ - | - | - | $ = {$} $ = {$} - <.dotty-non-ident($special)> + | + + | + + | + + $ = {$} $ = {$} + <.dotty-non-ident($special)> ] } token privop { - '!' + '!' + } - token methodop($*special) { + token methodop($*DOTTY) { [ | { self.malformed("class-qualified postfix call") @@ -1929,24 +2023,27 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { [ || *? [\s|$] > ] # dwim on "$foo." [ || <.panic: "Quoted method name requires parenthesized arguments. If you meant to concatenate two strings, use '~'."> ] - <.dotty-non-ident($*special)> - ] <.unspace>? + <.dotty-non-ident($*DOTTY)> + ] + <.unspace>? :dba('method arguments') [ - [ + [ | | ':' - ] - || - || - ] <.unspace>? + ] + || + || + ] + <.unspace>? } - token dotty-non-ident($special) { - | - | <.panic("Cannot use $special on a non-identifier method call")> + token dotty-non-ident($dotty) { + | + | <.panic: "Cannot use $dotty on a non-identifier method call"> } +#------------------------------------------------------------------------------- token super-sign { <[⁻⁺¯]> } token sub-sign { <[₊₋]> } @@ -1977,8 +2074,10 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { token postfix:sym«->» { $=[ '->' | '→' ] [ - | ['[' | '{' | '(' ] <.obs('->(), ->{} or ->[] as postfix dereferencer', '.(), .[] or .{} to deref, or whitespace to delimit a pointy block')> - | <.obs('-> as postfix', 'either . to call a method, or whitespace to delimit a pointy block')> + | ['[' | '{' | '(' ] + <.obs('->(), ->{} or ->[] as postfix dereferencer', '.(), .[] or .{} to deref, or whitespace to delimit a pointy block')> + + | <.obs('-> as postfix', 'either . to call a method, or whitespace to delimit a pointy block')> ] } @@ -2080,7 +2179,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { } token infix:sym«+>» { - [ + [ || >'> || ]> @@ -2089,7 +2188,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { } token infix:sym«~<» { - [ + [ || || @@ -2098,11 +2197,11 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { } token infix:sym«~>» { - [ + [ || >'> || ]> - ] + ] } @@ -2246,7 +2345,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { $='??' <.ws> - [ + [ '!!' || > <.typed-panic: "X::Syntax::ConditionalOperator::SecondPartInvalid", second-part => "::">