diff --git a/src/Raku/Grammar.nqp b/src/Raku/Grammar.nqp index 127802cd535..e6543bd4a9b 100644 --- a/src/Raku/Grammar.nqp +++ b/src/Raku/Grammar.nqp @@ -3316,8 +3316,9 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { :dba('contextualizer') [ <.panic: "Cannot declare a contextualizer"> ]? [ - | '(' ~ ')' - | + | '(' ~ ')' + + | ] } @@ -3354,25 +3355,27 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { ? {} [ :dba('generic role') - - '[' ~ ']' - { $*IN-DECL := ''; } + + '[' ~ ']' + { $*IN-DECL := ''; } ]? <.stub-package($)> - { $/.set_package($*PACKAGE) } + { $/.set_package($*PACKAGE) } :my $*ALSO-TARGET := $*PACKAGE; * <.enter-package-scope($)> [ - || { $*START-OF-COMPUNIT := 0; } - || ';' - [ - || - { $*START-OF-COMPUNIT := 0; } - - || { $/.typed-panic("X::UnitScope::TooLate", what => $*PKGDECL); } - ] - || <.panic("Unable to parse $*PKGDECL definition")> + || { $*START-OF-COMPUNIT := 0; } + || ';' + [ + || + { $*START-OF-COMPUNIT := 0; } + + + || { $/.typed-panic: "X::UnitScope::TooLate", what => $*PKGDECL } + ] + + || <.panic("Unable to parse $*PKGDECL definition")> ] <.leave-block-scope> <.leave-package-scope> @@ -3629,19 +3632,26 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { <.enter-block-scope(nqp::tclc($declarator))> ? { - if $ && $[0] -> $cf { + my $deflongname := $; + if $deflongname && $deflongname[0] -> $cf { # It's an (potentially new) operator, circumfix, etc. that we # need to tweak into the grammar. - my $category := $.Str; - - my $opname := $cf - ?? $cf - ?? $cf.ast.literal-value // ~$cf - !! $cf - !! ''; - my $canname := $category ~ ':sym' ~ self.actions.r('ColonPairish').IMPL-QUOTE-VALUE($opname.Str); + my $name := $deflongname; + my $category := $name.Str; + + my $opname := ''; + if $cf -> $ccf { + $opname := (my $nibble := $ccf) + ?? $nibble.ast.literal-value // ~$nibble + !! $ccf; + } + my $canname := $category + ~ ':sym' + ~ self.actions.r('ColonPairish').IMPL-QUOTE-VALUE(~$opname); - $/.add-categorical($category, $opname, $canname, $.ast.canonicalize, $*BLOCK); + $/.add-categorical( + $category, $opname, $canname, $name.ast.canonicalize, $*BLOCK + ); } } [ '(' ')' ]? @@ -3649,29 +3659,33 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { * :!s { $*IN-DECL := ''; } [ - || ';' - { - if $ ne 'MAIN' { - $/.typed-panic("X::UnitScope::Invalid", what => "sub", - where => "except on a MAIN sub", suggestion => - 'Please use the block form. If you did not mean to ' - ~ "declare a unit-scoped sub,\nperhaps you accidentally " - ~ "placed a semicolon after routine's definition?" - ); - } - unless $*START-OF-COMPUNIT { - $/.typed-panic("X::UnitScope::TooLate", what => "sub"); - } - unless $*MULTINESS eq '' || $*MULTINESS eq 'only' { - $/.typed-panic("X::UnitScope::Invalid", what => "sub", where => "on a $*MULTINESS sub"); - } - unless $*R.outer-scope =:= $*UNIT { - $/.typed-panic("X::UnitScope::Invalid", what => "sub", where => "in a subscope"); - } - $*START-OF-COMPUNIT := 0; - } - || - || + || ';' + { + if $ ne 'MAIN' { + $/.typed-panic: "X::UnitScope::Invalid", + what => "sub", + where => "except on a MAIN sub", + suggestion => "Please use the block form. If you did not mean to declare a unit-scoped sub,\nperhaps you accidentally placed a semicolon after routine's definition?"; + } + unless $*START-OF-COMPUNIT { + $/.typed-panic: "X::UnitScope::TooLate", what => "sub"; + } + unless $*MULTINESS eq '' || $*MULTINESS eq 'only' { + $/.typed-panic: "X::UnitScope::Invalid", + what => "sub", + where => "on a $*MULTINESS sub"; + } + unless $*R.outer-scope =:= $*UNIT { + $/.typed-panic: "X::UnitScope::Invalid", + what => "sub", + where => "in a subscope"; + } + $*START-OF-COMPUNIT := 0; + } + + || + + || ] <.leave-block-scope> } @@ -3686,8 +3700,8 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { * :!s { $*IN-DECL := ''; } [ - || - || + || + || ] <.leave-block-scope> } @@ -3740,8 +3754,8 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { * '{' [ -# | ['*'|'<...>'|'<*>'] $={1} - | ), '{', '}'))> +# | ['*'|'<...>'|'<*>'] $={1} + | ), '{', '}'))> ] '}' <.leave-block-scope> @@ -3803,8 +3817,7 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { { $*IN-DECL := '' } * [ <.constraint-where> ]? - ] - || <.malformed: 'subset'> + ] || <.malformed: 'subset'> ] } @@ -3866,15 +3879,15 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { token numish { [ - | 'NaN' » - | - | - | - | - | - | 'Inf' » - | $='∞' - | + | 'NaN' » + | + | + | + | + | + | 'Inf' » + | $='∞' + | ] } @@ -3924,9 +3937,9 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { token decimal-number { :dba('decimal number') [ - | $ = [ '.' ] ? - | $ = [ '.' ] ? - | $ = [ ] + | $ = [ '.' ] ? + | $ = [ '.' ] ? + | $ = [ ] ] } @@ -3942,15 +3955,23 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { :my $rad_digit := token rad_digit { \d | <[ a..z A..Z a..z A..Z ]> }; :my $rad_digits := token rad_digits { + [ _ + ]* }; [ - || '<' - $ = [ '0x' | '0o' | '0d' | '0b' ]**0..1 - $ = - $ = [ '.' ]**0..1 - [ '*' '**' ]**0..1 - '>' - || - || - || <.malformed: 'radix number'> + || '<' + $=[ + '0x' + | '0o' + | '0d' + | '0b' + ]**0..1 + $ = + $ = [ '.' ]**0..1 + [ '*' '**' ]**0..1 + '>' + + || + + || + + || <.malformed: 'radix number'> ] } @@ -4143,19 +4164,35 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { :my $stop; - { my $B := $.ast; $lang := $B[0]; $start := $B[1]; $stop := $B[2]; } + { + my $B := $.ast; + $lang := $B[0]; + $start := $B[1]; + $stop := $B[2]; + } - $start [ $stop || { self.fail-terminator($/, $start, $stop) } ] + $start + + [ $stop || { self.fail-terminator: $/, $start, $stop } ] [ - <.ws> - [ <.obs: 'brackets around replacement', 'assignment syntax'> ]? - [ || <.missing: "assignment operator"> ] - [ .Str eq '=' || $ }> || <.malformed: "assignment operator"> ] - <.ws> - [ || <.panic: "Assignment operator missing its expression"> ] - || - { $lang := self.quote-lang($lang2, $stop, $stop, @lang2tweaks); } - $stop || <.malformed: "Replacement part; couldn't find final $stop"> + <.ws> + [ + <.obs: 'brackets around replacement', 'assignment syntax'> + ]? + [ || <.missing: "assignment operator"> ] + [ .Str eq '=' + || $ + }> || <.malformed: "assignment operator"> + ] + <.ws> + [ + || <.panic: "Assignment operator missing its expression"> + ] || { + $lang := self.quote-lang($lang2, $stop, $stop, @lang2tweaks) + } + + $stop || <.malformed: "Replacement part; couldn't find final $stop"> ] } @@ -4225,41 +4262,47 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common { token typename { [ - | # parse ::?CLASS as special case - '::?' * - | - :my $*IN-TYPENAME := 1; - - , '::', 0) || $*R.is-name-known($.ast.without-colonpairs) - }> + # parse ::?CLASS as special case + | '::?' * + + | :my $*IN-TYPENAME := 1; + + , '::', 0) + || $*R.is-name-known($.ast.without-colonpairs) + }> ] # parametric/coercion type? - <.unspace>? [ - - '[' ~ ']' + <.unspace>? + [ '[' ~ ']' ]? + <.unspace>? + [ + <.NYI: 'Autovivifying object closures'> + ]? - <.unspace>? [ <.NYI: 'Autovivifying object closures'> - ]? - <.unspace>? [ '(' ~ ')' [<.ws> [ || $=] <.ws>] ]? - [<.ws> 'of' <.ws> ]? + <.unspace>? + [ + '(' ~ ')' [<.ws> [ || $=] <.ws>] + ]? + [<.ws> <.trait-of> <.ws> ]? } token typo-typename($panic = 0) { { - #TODO bring back suggestions for which types may have been meant - my $method := $panic ?? 'typed-panic' !! 'typed-sorry'; - $/."$method"('X::Undeclared', - what => "Type", - symbol => $.ast.canonicalize); + #TODO bring back suggestions for which types may have been meant + my $method := $panic ?? 'typed-panic' !! 'typed-sorry'; + $/."$method"('X::Undeclared', + what => "Type", + symbol => $.ast.canonicalize + ); } } method maybe-typename() { - return self.typename(); CATCH { return self.new-cursor } + self.typename; } #-------------------------------------------------------------------------------