Skip to content

Commit f252dce

Browse files
committed
remove eval-level confusion from / $x / and / @x /
1 parent 90fffba commit f252dce

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

S05-regex.pod

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Synopsis 5: Regexes and Rules
1717

1818
Created: 24 Jun 2002
1919

20-
Last Modified: 3 Apr 2013
21-
Version: 161
20+
Last Modified: 6 May 2013
21+
Version: 162
2222

2323
This document summarizes Apocalypse 5, which is about the new regex
2424
syntax. We now try to call them I<regex> rather than "regular
@@ -1201,7 +1201,7 @@ how to handle them (more on that below).
12011201
=item *
12021202

12031203
The default way in which the engine handles a string scalar is to match it
1204-
as a C<< '...' >> literal (i.e. it does not treat the interpolated string
1204+
as a C<< "..." >> literal (i.e. it does not treat the interpolated string
12051205
as a subpattern). In other words, a Perl 6:
12061206

12071207
/ $var /
@@ -1210,13 +1210,16 @@ is like a Perl 5:
12101210

12111211
/ \Q$var\E /
12121212

1213-
However, if C<$var> contains a C<Regex> object, instead of attempting to
1214-
convert it to a string, it is called as a subrule, as if you said
1215-
C<< <$var> >>. (See assertions below.) This form does not capture,
1216-
and it fails if C<$var> is tainted.
1213+
To interpolate a C<Regex> object, use C<< <$var> >> instead.
12171214

12181215
If C<$var> is undefined, a warning is issued and the match fails.
12191216

1217+
When matching against a Stringy type that is not Str, the variable must
1218+
be interpretable as a value of that Stringy type (or a related type
1219+
that can be coerced to that type). For example, when regex matching a
1220+
Buf type, the variable will be matched under the Buf type's semantics,
1221+
not Str semantics.
1222+
12201223
[Conjecture: when we allow matching against non-string types, doing a
12211224
type match on the current node will require the syntax of an embedded
12221225
signature, not just a bare variable, so there is no need to account for
@@ -1271,7 +1274,7 @@ An interpolated array:
12711274

12721275
/ @cmds /
12731276

1274-
is matched as if it were an alternation of its elements. Ordinarily it
1277+
is matched as if it were an alternation of its literal elements. Ordinarily it
12751278
matches using junctive semantics:
12761279

12771280
/ [ @cmds[0] | @cmds[1] | @cmds[2] | ... ] /
@@ -1293,16 +1296,18 @@ Or course, you can also
12931296

12941297
to be clear that you mean junctive semantics.
12951298

1299+
Since C<$x> is interpolated as if you'd said C<"$x">, if C<$x> contains
1300+
a list, it is stringified first. To get alternation you must use the
1301+
C<@$x> or C<@($x)> form to indicate that you're intending the scalar
1302+
variable to be treated as a list.
1303+
12961304
An interpolated array using junctive semantics is declarative
12971305
(participates in external longest token matching) only if it's
12981306
known to be constant at the time the regex is compiled.
12991307

1300-
As with a scalar variable, each element is matched as a literal
1301-
unless it happens to be a C<Regex> object, in which case it is matched
1302-
as a subrule. As with scalar subrules, a tainted subrule always fails.
1303-
All string values pay attention to the current C<:ignorecase>
1304-
and C<:ignoremark> settings, while C<Regex> values use their own
1305-
C<:ignorecase> and C<:ignoremark> settings.
1308+
As with a scalar variable, each element is matched as a literal.
1309+
All such values pay attention to the current C<:ignorecase>
1310+
and C<:ignoremark> settings.
13061311

13071312
When you get tired of writing:
13081313

0 commit comments

Comments
 (0)