Skip to content

Commit 9a42dc5

Browse files
committed
Various bits of alignment with STD_P5.
This also allows the empty alternation branch.
1 parent ea7a053 commit 9a42dc5

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

src/QRegex/P5Regex/Actions.nqp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,41 @@ class QRegex::P5Regex::Actions is HLL::Actions {
33
make qbuildsub($<nibbler>.ast, :anon(1), :addself(1));
44
}
55

6-
method nibbler($/) { make $<termaltseq>.ast }
6+
method nibbler($/) { make $<alternation>.ast }
77

8-
method termaltseq($/) {
9-
my $qast := $<termish>[0].ast;
10-
if +$<termish> > 1 {
8+
method alternation($/) {
9+
my $qast := $<sequence>[0].ast;
10+
if +$<sequence> > 1 {
1111
$qast := QAST::Regex.new( :rxtype<altseq>, :node($/) );
12-
for $<termish> { $qast.push($_.ast); }
12+
for $<sequence> { $qast.push($_.ast); }
1313
}
1414
make $qast;
1515
}
1616

17-
method termish($/) {
18-
my $qast := QAST::Regex.new( :rxtype<concat>, :node($/) );
19-
my $lastlit := 0;
20-
for $<noun> {
21-
my $ast := $_.ast;
22-
if $ast {
23-
if $lastlit && $ast.rxtype eq 'literal'
24-
&& !QAST::Node.ACCEPTS($ast[0]) {
25-
$lastlit[0] := $lastlit[0] ~ $ast[0];
26-
}
27-
else {
28-
$qast.push($_.ast);
29-
$lastlit := $ast.rxtype eq 'literal'
30-
&& !QAST::Node.ACCEPTS($ast[0])
31-
?? $ast !! 0;
17+
method sequence($/) {
18+
if $<quantified_atom> {
19+
my $qast := QAST::Regex.new( :rxtype<concat>, :node($/) );
20+
my $lastlit := 0;
21+
for $<quantified_atom> {
22+
my $ast := $_.ast;
23+
if $ast {
24+
if $lastlit && $ast.rxtype eq 'literal'
25+
&& !QAST::Node.ACCEPTS($ast[0]) {
26+
$lastlit[0] := $lastlit[0] ~ $ast[0];
27+
}
28+
else {
29+
$qast.push($_.ast);
30+
$lastlit := $ast.rxtype eq 'literal'
31+
&& !QAST::Node.ACCEPTS($ast[0])
32+
?? $ast !! 0;
33+
}
3234
}
3335
}
36+
make $qast;
37+
}
38+
else {
39+
make QAST::Regex.new( :rxtype<anchor>, :name<pass>, :node($/) );
3440
}
35-
make $qast;
3641
}
3742

3843
method quantified_atom($/) {
@@ -86,9 +91,7 @@ class QRegex::P5Regex::Actions is HLL::Actions {
8691

8792
method p5metachar:sym<( )>($/) {
8893
make QAST::Regex.new( :rxtype<subcapture>, :node($/),
89-
$<nibbler>
90-
?? $<nibbler>[0].ast
91-
!! QAST::Regex.new( :rxtype<anchor>, :subtype<pass> ) );
94+
$<nibbler>.ast );
9295
}
9396

9497
method p5metachar:sym<[ ]>($/) {

src/QRegex/P5Regex/Grammar.nqp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
1515
{
1616
for $OLDRX { %*RX{$_.key} := $_.value; }
1717
}
18-
<termaltseq>
18+
<alternation>
1919
}
2020

21-
token termaltseq {
22-
<termish>
23-
[ '|' <![|]> [ <termish> || <.panic: 'Null pattern not allowed'> ] ]*
21+
token alternation {
22+
<sequence>+ % '|'
2423
}
2524

26-
token termish {
25+
token sequence {
2726
<.ws> # XXX assuming old /x here?
28-
<noun=.quantified_atom>+
27+
<quantified_atom>*
2928
}
3029

3130
token quantified_atom {
@@ -59,7 +58,7 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
5958
'(?' {} <assertion=p5assertion>
6059
[ ')' || <.panic: "Perl 5 regex assertion not terminated by parenthesis"> ]
6160
}
62-
token p5metachar:sym<( )> { '(' {} <nibbler>? ')' }
61+
token p5metachar:sym<( )> { '(' {} <nibbler> ')' }
6362
token p5metachar:sym<[ ]> { <?before '['> <cclass> }
6463

6564
token cclass {

0 commit comments

Comments
 (0)