Skip to content

Commit

Permalink
xt/rakudoc-c.rakutest: respect Z<ignore-code-ws>
Browse files Browse the repository at this point in the history
Z<ignore-code-ws> indicates that the following whitespace check ought to
be skipped.

Add a couple of these Z<>s to doc/Language/regexes.rakudoc, pass.
  • Loading branch information
cfa authored and coke committed Mar 5, 2023
1 parent fa65dcc commit 68c898c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 7 additions & 6 deletions doc/Language/regexes.rakudoc
Expand Up @@ -2410,8 +2410,8 @@ it will turn into C«<.ws>».
In addition, if whitespace comes after a term but I<before> a quantifier
(C<+>, C<*>, or C<?>), C«<.ws>» will be matched after every match of the
term. So, C<foo +> becomes C«[ foo <.ws> ]+». On the other hand, whitespace
I<after> a quantifier acts as normal significant whitespace; e.g., "C<foo+ >"
becomes C«foo+ <.ws>».
I<after> a quantifier acts as normal significant whitespace; e.g.,
Z<ignore-code-ws>"C<foo+ >" becomes C«foo+ <.ws>».

In all, this code:

Expand Down Expand Up @@ -2807,10 +2807,11 @@ say $string ~~ / :r (.+)(SQL) (.+) $1/; # OUTPUT: «Nil␤»
=end code

The fact is that, as shown in the I<iteration 1> output, the first match of the
regular expression engine will be C<PostgreSQL is an >, C<SQL>, C< database>
that does not leave out any room for matching another occurrence of the word
I<SQL> (as C<$1> in the regular expression). Since the engine is not able to get
backward and change the path to match, the regular expression fails.
regular expression engine will be Z<ignore-code-ws>C<PostgreSQL is an >,
C<SQL>, C< database> that does not leave out any room for matching another
occurrence of the word I<SQL> (as C<$1> in the regular expression). Since the
engine is not able to get backward and change the path to match, the regular
expression fails.

It is worth noting that disabling backtracking will not prevent the engine
to try several ways to match the regular expression.
Expand Down
10 changes: 9 additions & 1 deletion xt/rakudoc-c.rakutest
Expand Up @@ -27,11 +27,19 @@ sub is-valid-c($contents) {
}

sub walk-content($x) {
my $trailing-ok = False;
for $x.contents -> $contents {
next unless $contents;
for @$contents -> $item {
if $item ~~ Pod::FormattingCode and $item.type eq 'Z' {
if $item.contents.lc ~~ 'ignore-code-ws' {
# skip the validity check for the next C<>
$trailing-ok = True;
}
}
if $item ~~ Pod::FormattingCode and $item.type eq 'C' {
is-valid-c($item.contents);
is-valid-c($item.contents) unless $trailing-ok;
$trailing-ok = False;
} elsif $item !~~ Str {
walk-content($item);
}
Expand Down

0 comments on commit 68c898c

Please sign in to comment.