Skip to content

Commit

Permalink
RakuAST: prevent some more unnecessary captures
Browse files Browse the repository at this point in the history
And somei grammar streamlining
  • Loading branch information
lizmat committed Sep 16, 2023
1 parent 40a94e2 commit 97683f9
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions src/Raku/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -3202,13 +3202,19 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
proto token routine-declarator {*}
token routine-declarator:sym<sub> {
<sym> <.end-keyword> <routine-def=.key-origin('routine-def', 'sub')>
<.sym>
<.end-keyword>
<routine-def=.key-origin('routine-def', 'sub')>
}
token routine-declarator:sym<method> {
<sym> <.end-keyword> <method-def=.key-origin('method-def', 'method')>
<.sym>
<.end-keyword>
<method-def=.key-origin('method-def', 'method')>
}
token routine-declarator:sym<submethod> {
<sym> <.end-keyword> <method-def=.key-origin('method-def', 'submethod')>
<.sym>
<.end-keyword>
<method-def=.key-origin('method-def', 'submethod')>
}
rule routine-def($declarator) {
Expand Down Expand Up @@ -3290,7 +3296,8 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
proto token regex-declarator {*}
token regex-declarator:sym<rule> {
<sym><.kok>
<.sym>
<.kok>
:my %*RX;
:my $*INTERPOLATE := 1;
:my $*IN-DECL := 'rule';
Expand All @@ -3299,15 +3306,17 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
}
token regex-declarator:sym<token> {
<sym><.kok>
<.sym>
<.kok>
:my %*RX;
:my $*INTERPOLATE := 1;
:my $*IN-DECL := 'token';
<regex-def>
}
token regex-declarator:sym<regex> {
<sym><.kok>
<.sym>
<.kok>
:my %*RX;
:my $*INTERPOLATE := 1;
:my $*IN-DECL := 'regex';
Expand Down Expand Up @@ -3338,51 +3347,59 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
token type-declarator:sym<constant> {
:my $*IN-DECL := 'constant';
<sym><.kok>
<.sym>
<.kok>
[
| '\\'? <defterm>
| <variable> # for new &infix:<foo> synonyms
| <?>
| '\\'?
<defterm>
| <variable> # for new &infix:<foo> synonyms
| <?>
]
{ $*IN-DECL := ''; }
<.ws>
<trait>*
[ <.ws> <term_init=initializer> || <.typed-panic: "X::Syntax::Term::MissingInitializer"> ]
[ <.ws>
<term_init=initializer>
|| <.typed-panic: "X::Syntax::Term::MissingInitializer">
]
<.cheat-heredoc>?
}
token type-declarator:sym<enum> {
<sym><.kok>
<.sym>
<.kok>
:my $*IN-DECL := 'enum';
[
| <longname>
| <variable>
| <?>
| <longname>
| <variable>
| <?>
]
{ $*IN-DECL := '' }
<.ws>
<trait>*
[ <?[<(«]> <term> <.ws> || <.panic: 'An enum must supply an expression using <>, «», or ()'> ]
[ <?[<(«]>
<term>
<.ws>
|| <.panic: 'An enum must supply an expression using <>, «», or ()'>
]
}
rule type-declarator:sym<subset> {
<.sym><.kok>
:my $*IN-DECL := 'subset';
<sym><.kok>
[
[
[
<longname>
]
{ $*IN-DECL := '' }
<trait>*
[ where <EXPR('e=')> ]?
]
|| <.malformed: 'subset'>
[
[ <longname> ]
{ $*IN-DECL := '' }
<trait>*
[ where <EXPR('e=')> ]?
]
|| <.malformed: 'subset'>
]
}
Expand Down

0 comments on commit 97683f9

Please sign in to comment.