Skip to content

Commit 74ca920

Browse files
committed
Simplify and correct the backslashes with .. in charclass patch. Needs more testing.
1 parent 0f3407b commit 74ca920

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/QRegex/P6Regex/Actions.nqp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -412,45 +412,42 @@ class QRegex::P6Regex::Actions is HLL::Actions {
412412
else {
413413
my @alts;
414414
for $<charspec> {
415-
if $_<backslashonly> {
416-
my $bs := $_<backslash>.ast;
417-
$bs.negate(!$bs.negate) if $<sign> eq '-';
418-
@alts.push($bs);
419-
}
420-
elsif $_[1] {
415+
if $_[1] {
421416
my $node;
422417
my $lhs;
423418
my $rhs;
424419
if $_[0]<backslash> {
425-
nqp::say(pir::typeof__sP($_[0]<backslash>.ast));
426420
$node := $_[0]<backslash>.ast;
427421
$/.CURSOR.panic("Illegal range endpoint in regex: " ~ ~$_)
428422
if $node.rxtype ne 'literal' && $node.rxtype ne 'enumcharlist'
429423
|| $node.negate || nqp::chars($node[0]) != 1;
430424
$lhs := $node[0];
431425
}
432426
else {
433-
$lhs := $_[0][0];
427+
$lhs := ~$_[0][0];
434428
}
435-
if $_[1]<backslash> {
436-
nqp::say(pir::typeof__sP($_[1]<backslash>));
437-
nqp::say(pir::typeof__sP($_[1]<backslash>.ast));
438-
$node := $_[1]<backslash>.ast;
429+
if $_[1][0]<backslash> {
430+
$node := $_[1][0]<backslash>.ast;
439431
$/.CURSOR.panic("Illegal range endpoint in regex: " ~ ~$_)
440432
if $node.rxtype ne 'literal' && $node.rxtype ne 'enumcharlist'
441433
|| $node.negate || nqp::chars($node[0]) != 1;
442434
$rhs := $node[0];
443435
}
444436
else {
445-
$rhs := $_[1][0];
437+
$rhs := ~$_[1][0][0];
446438
}
447439
my $ord0 := nqp::ord($lhs);
448440
my $ord1 := nqp::ord($rhs);
449441
$/.CURSOR.panic("Illegal reversed character range in regex: " ~ ~$_)
450442
if $ord0 > $ord1;
451443
$str := nqp::concat($str, nqp::chr($ord0++)) while $ord0 <= $ord1;
452444
}
453-
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]; }
454451
}
455452
@alts.push(QAST::Regex.new( $str, :rxtype<enumcharlist>, :node($/), :negate( $<sign> eq '-' ) ))
456453
if nqp::chars($str);

src/QRegex/P6Regex/Grammar.nqp

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> || (<-[\]\\]>) ) [ \s* '..' \s* ( '\\' <backslash> || (<-[\]\\]>) ) ]?
205-
|| \s* '\\' $<backslashonly>=[<backslash>]
204+
|| \s* ( '\\' <backslash> || (<-[\]\\]>) )
205+
[
206+
\s* '..' \s*
207+
( '\\' <backslash> || (<-[\]\\]>) )
208+
]?
206209
)*
207210
\s* ']'
208211
| $<name>=[\w+]

0 commit comments

Comments
 (0)