Skip to content

Commit 94b174b

Browse files
committed
Use consistent grammar to parse subrule arguments.
This fixes the problem where <subrule(...)> could take any kind of arguments, while <subrule: ...> only accepted a list of strings (and didn't interpolate variables in double-quoted strings). Closes #105.
1 parent 29fc96c commit 94b174b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/NQP/Actions.nqp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,8 @@ class NQP::RegexActions is QRegex::P6Regex::Actions {
17731773
}
17741774
make $qast;
17751775
}
1776+
1777+
method arglist($/) { make $<arglist>.ast }
17761778

17771779
method arg($/) {
17781780
make $<quote_EXPR>.ast;

src/NQP/Grammar.nqp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ grammar NQP::Grammar is HLL::Grammar {
3030
my $*INVOCANT_OK := 0;
3131
my $*RETURN_USED := 0;
3232
my $*CONTROL_USED := 0;
33+
my $*IN_REGEX_ASSERTION := 0;
3334
my %*HANDLERS;
3435
self.comp_unit;
3536
}
@@ -702,7 +703,10 @@ grammar NQP::Grammar is HLL::Grammar {
702703

703704

704705
token infixish { <!infixstopper> <OPER=infix> }
705-
token infixstopper { <?lambda> }
706+
token infixstopper {
707+
| <?{ $*IN_REGEX_ASSERTION }> <?[>]>
708+
| <?lambda>
709+
}
706710

707711
token postcircumfix:sym<[ ]> {
708712
'[' <.ws> <EXPR> ']'
@@ -826,13 +830,18 @@ grammar NQP::Regex is QRegex::P6Regex::Grammar {
826830
$<zw>=[ <[?!]> <?[{]> ] <codeblock>
827831
}
828832

833+
token arglist {
834+
:my $*IN_REGEX_ASSERTION := 1;
835+
<arglist=.LANG('MAIN', 'arglist')>
836+
}
837+
829838
token assertion:sym<name> {
830839
<longname=.identifier>
831840
[
832841
| <?[>]>
833842
| '=' <assertion>
834843
| ':' <arglist>
835-
| '(' <arglist=.LANG('MAIN','arglist')> ')'
844+
| '(' <arglist> ')'
836845
| <.normspace> <nibbler>
837846
]**0..1
838847
}

0 commit comments

Comments
 (0)