Skip to content

Commit 05affcf

Browse files
committed
Merge pull request #23 from ruz/regexp-fixes
Fixes for character classes in regexes
2 parents fbe7f0b + f058ab5 commit 05affcf

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/QRegex/Cursor.nqp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ role NQPCursorRole {
142142
method wb() {
143143
my $cur := self."!cursor_start"();
144144
$cur."!cursor_pass"($!pos, "wb")
145-
if $!pos == 0
146-
|| $!pos == nqp::chars($!target)
145+
if ($!pos == 0 && nqp::iscclass(pir::const::CCLASS_WORD, $!target, $!pos))
146+
|| ($!pos == nqp::chars($!target)
147+
&& nqp::iscclass(pir::const::CCLASS_WORD, $!target, $!pos-1))
147148
|| nqp::iscclass(pir::const::CCLASS_WORD, $!target, $!pos-1)
148149
!= nqp::iscclass(pir::const::CCLASS_WORD, $!target, $!pos);
149150
$cur;

src/QRegex/P6Regex/Grammar.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
192192
<.normspace>?
193193
[
194194
| '[' $<charspec>=(
195-
| \s* '-' <.obs: '- as character range','..'>
195+
| \s* '-' <!before \s* ']'> <.obs: '- as character range','.. for range, for explicit - in character class, escape it or place as last thing'>
196196
| \s* [ \\ (.) | (<-[\]\\]>) ] [ \s* '..' \s* (.) ]?
197197
)*
198198
\s* ']'

t/qregex/rx_charclass

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@
2424
<-[b..d]> bbccdd n negated character range
2525
# todo :pge<reversed character range>
2626
<-[d..b]> bbccdd /parse error/ illegal character range
27-
<[-]> ab-def /Unsupported/ unescaped hyphen
27+
<[x-z]> ab-def <Unsupported> perl5 range
28+
<[-]> ab-def y unescaped hyphen, the only thing
29+
<[ - ]> ab-def y unescaped hyphen, the only thing w spaces
30+
<[x-]> ab-def y unescaped hyphen, at the end
31+
<[x - ]> ab-def y unescaped hyphen, at the end w spaces
32+
# todo :pge<feature>
33+
<[-x]> ab-def y unescaped hyphen, at the beginning
34+
# todo :pge<feature>
35+
<[ -x]> ab-def y unescaped hyphen, at the beginning w spaces
2836
<[\-]> ab-def y escaped hyphen
2937
<[\-]> abcdef n escaped hyphen
3038
<-[\-]> ---x-- y negated escaped hyphen

t/qregex/rx_subrules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

66
<?wb>def abc\ndef\n-==\nghi y word boundary \W\w
77
abc<?wb> abc\ndef\n-==\nghi y word boundary \w\W
8+
<wb> - n no boundary at all
89
<?wb>abc abc\ndef\n-==\nghi y BOS word boundary
10+
^^<wb> -ab n BOS is not boundary
911
ghi<?wb> abc\ndef\n-==\nghi y EOS word boundary
12+
<wb>$$ ab- n EOS is not boundary
1013
a<?wb> abc\ndef\n-==\nghi n \w\w word boundary
1114
\-<?wb> abc\ndef\n-==\nghi n \W\W word boundary
1215
<!wb>def abc\ndef\n-==\nghi n nonword boundary \W\w

0 commit comments

Comments
 (0)