Skip to content

Commit d20fe35

Browse files
authored
Merge pull request #1717 from 0/regex
Minor adjustments
2 parents 5b3f34b + df41c1a commit d20fe35

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

doc/Language/regexes.pod6

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,12 @@ string of non-whitespace characters.
523523
524524
=head1 X<Longest Alternation: C<|>|regex,|>
525525
526-
In short, in regexes branches separated by C<|>, the longest token match wins,
527-
independent of the textual ordering in the regexes. However, what C<|> really
526+
In short, in regex branches separated by C<|>, the longest token match wins,
527+
independent of the textual ordering in the regex. However, what C<|> really
528528
does is more than that.
529-
530-
C<|> does not decide which branch to win after finishing the whole match,
531-
but follows the L<longest token match, for short, LTM|
532-
https://design.perl6.org/S05.html#Longest-token_matching> strategy.
529+
It does not decide which branch wins after finishing the whole match,
530+
but follows the L<longest-token matching (LTM) strategy|
531+
https://design.perl6.org/S05.html#Longest-token_matching>.
533532
534533
Briefly, what C<|> does is this:
535534

doc/Language/traps.pod6

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,17 +593,15 @@ say %h.perl
593593
594594
=head2 C«<{$x}>» vs C«$($x)»: Implicit EVAL
595595
596-
Sometimes you may need to match a generated string in a regex. The
597-
right way to do it is to use C<$(…)> or C«<{…}>» syntax.
596+
Sometimes you may need to match a generated string in a regex. This can be done
597+
using C<$(…)> or C«<{…}>» syntax:
598598
599599
=for code
600600
my $x = ‘ailemac’;
601601
say ‘I ♥ camelia’ ~~ / $($x.flip) /; # OUTPUT: «「camelia」␤»
602-
my $x = ‘ailemac’;
603602
say ‘I ♥ camelia’ ~~ / <{$x.flip}> /; # OUTPUT: «「camelia」␤»
604603
605-
However, there is a wrong way to write it, and the problem is that
606-
it works I<sometimes>.
604+
However, the latter only works I<sometimes>.
607605
608606
Internally C«<{…}>» EVAL-s the given string inside an anonymous regex, while
609607
C<$(…)> lexically interpolates the given string. So C«<{…}>» immediately breaks
@@ -613,7 +611,7 @@ with more complicated inputs. For example:
613611
my $x = ‘ailemac#’;
614612
say ‘I ♥ #camelia’ ~~ / $($x.flip) /; # OUTPUT: «「#camelia」␤»
615613
# ⚠ ↓↓ WRONG ↓↓ ⚠
616-
say ‘I ♥ camelia’ ~~ / <{$x.flip}> /; # OUTPUT: «「camelia」␤»
614+
say ‘I ♥ #camelia’ ~~ / <{$x.flip}> /;
617615
# OUTPUT:
618616
# ===SORRY!===
619617
# Regex not terminated.
@@ -639,13 +637,13 @@ thrown, and should not introduce security issues.
639637
To match one of several possible alternatives, C<||> or C<|> will be used. But
640638
they are so different.
641639
642-
While there are more alternations than one matched, for those separated by
640+
When there are multiple matching alternations, for those separated by
643641
C<||>, the first matching alternation wins; for those separated by C<|>,
644642
which to win is decided by LTM strategy. See also:
645643
L<documentation on C<||>|/language/regexes#Alternation:_||> and
646644
L<documentation on C<|>|/language/regexes#Longest_Alternation:_|>.
647645
648-
For advice of which to use: for simple regexes just using C<||> instead of C<|>
646+
For simple regexes just using C<||> instead of C<|>
649647
will get you familiar semantics, but if writing grammars then it's useful to
650648
learn about LTM and declarative prefixes and prefer C<|>. And keep yourself
651649
away from using them in one regex. When you have to do that, add parentheses

0 commit comments

Comments
 (0)