Skip to content

Commit d4f6e5c

Browse files
committed
Merge branch 'cclass'
2 parents 13508b4 + 74ca920 commit d4f6e5c

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

src/QRegex/P6Regex/Actions.nqp

100644100755
Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,19 +412,42 @@ class QRegex::P6Regex::Actions is HLL::Actions {
412412
else {
413413
my @alts;
414414
for $<charspec> {
415-
if $_<backslash> {
416-
my $bs := $_<backslash>.ast;
417-
$bs.negate(!$bs.negate) if $<sign> eq '-';
418-
@alts.push($bs);
419-
}
420-
elsif $_[1] {
421-
my $ord0 := nqp::ord($_[0]);
422-
my $ord1 := nqp::ord($_[1][0]);
415+
if $_[1] {
416+
my $node;
417+
my $lhs;
418+
my $rhs;
419+
if $_[0]<backslash> {
420+
$node := $_[0]<backslash>.ast;
421+
$/.CURSOR.panic("Illegal range endpoint in regex: " ~ ~$_)
422+
if $node.rxtype ne 'literal' && $node.rxtype ne 'enumcharlist'
423+
|| $node.negate || nqp::chars($node[0]) != 1;
424+
$lhs := $node[0];
425+
}
426+
else {
427+
$lhs := ~$_[0][0];
428+
}
429+
if $_[1][0]<backslash> {
430+
$node := $_[1][0]<backslash>.ast;
431+
$/.CURSOR.panic("Illegal range endpoint in regex: " ~ ~$_)
432+
if $node.rxtype ne 'literal' && $node.rxtype ne 'enumcharlist'
433+
|| $node.negate || nqp::chars($node[0]) != 1;
434+
$rhs := $node[0];
435+
}
436+
else {
437+
$rhs := ~$_[1][0][0];
438+
}
439+
my $ord0 := nqp::ord($lhs);
440+
my $ord1 := nqp::ord($rhs);
423441
$/.CURSOR.panic("Illegal reversed character range in regex: " ~ ~$_)
424442
if $ord0 > $ord1;
425443
$str := nqp::concat($str, nqp::chr($ord0++)) while $ord0 <= $ord1;
426444
}
427-
else { $str := $str ~ $_[0]; }
445+
elsif $_[0]<backslash> {
446+
my $bs := $_[0]<backslash>.ast;
447+
$bs.negate(!$bs.negate) if $<sign> eq '-';
448+
@alts.push($bs);
449+
}
450+
else { $str := $str ~ ~$_[0]; }
428451
}
429452
@alts.push(QAST::Regex.new( $str, :rxtype<enumcharlist>, :node($/), :negate( $<sign> eq '-' ) ))
430453
if nqp::chars($str);

src/QRegex/P6Regex/Grammar.nqp

100644100755
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,11 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
201201
[
202202
| '[' $<charspec>=(
203203
|| \s* '-' <!before \s* ']'> <.obs: '- as character range','.. for range, for explicit - in character class, escape it or place as last thing'>
204-
|| \s* '\\' <backslash>
205-
|| \s* (<-[\]\\]>) [ \s* '..' \s* (.) ]?
204+
|| \s* ( '\\' <backslash> || (<-[\]\\]>) )
205+
[
206+
\s* '..' \s*
207+
( '\\' <backslash> || (<-[\]\\]>) )
208+
]?
206209
)*
207210
\s* ']'
208211
| $<name>=[\w+]

0 commit comments

Comments
 (0)