argra****@users*****
argra****@users*****
2018年 7月 22日 (日) 19:01:29 JST
Index: docs/perl/5.14.1/perlre.pod diff -u docs/perl/5.14.1/perlre.pod:1.9 docs/perl/5.14.1/perlre.pod:1.10 --- docs/perl/5.14.1/perlre.pod:1.9 Mon Sep 18 02:33:10 2017 +++ docs/perl/5.14.1/perlre.pod Sun Jul 22 19:01:29 2018 @@ -438,14 +438,13 @@ これはパターンマッチングのときに現在のロケールの規則 (L<perllocale> 参照) を 使うことを意味します。 -For example, C<\w> will match the "word" characters of that -locale, and C<"/i"> case-insensitive matching will match according to -the locale's case folding rules. The locale used will be the one in -effect at the time of execution of the pattern match. This may not be -the same as the compilation-time locale, and can differ from one match -to another if there is an intervening call of the -L<setlocale() function|perllocale/The setlocale function>. -(TBT) +例えば、C<\w> はこのロケールの「単語」文字にマッチングし、 +C<"/i"> の大文字小文字マッチングは、現在のロケールの大文字小文字畳み込み規則に +従ってマッチングします。 +使われるロケールはパターンマッチングが実行される時点で有効なものです。 +これはコンパイル時のロケールと同じではないかもしれませんし、 +L<setlocale() 関数|perllocale/The setlocale function> +の呼び出しが間に入ると、呼び出し毎に異なることもあります。 =begin original @@ -461,16 +460,18 @@ =end original -Perl only supports single-byte locales. This means that code points -above 255 are treated as Unicode no matter what locale is in effect. -Under Unicode rules, there are a few case-insensitive matches that cross -the 255/256 boundary. These are disallowed under C</l>. For example, -0xFF does not caselessly match the character at 0x178, C<LATIN CAPITAL -LETTER Y WITH DIAERESIS>, because 0xFF may not be C<LATIN SMALL LETTER Y -WITH DIAERESIS> in the current locale, and Perl has no way of knowing if -that character even exists in the locale, much less what code point it -is. -(TBT) +Perl は単一バイトロケールのみに対応します。 +つまり、255 を越える符号位置は、どのロケールが有効であるかに関わらず +Unicode として扱われるということです。 +Unicode の規則の基では、255/256 の境界をまたぐ大文字小文字を無視した +マッチングがいくつかあります。 +これらは C</l> の基では認められません。 +例えば、0xFF は 0x178, +C<LATIN CAPITAL LETTER Y WITH DIAERESIS> と大文字小文字を無視した +マッチングをしません; なぜなら 0xFF は現在のロケールでは +C<LATIN SMALL LETTER Y WITH DIAERESIS> ではないかもしれず、Perl は +このロケールでこの文字があるかどうかすら知る方法がなく、ましてや +これがどの符号位置かを知る方法もないからです。 =begin original @@ -480,10 +481,9 @@ =end original -This modifier may be specified to be the default by C<use locale>, but -see L</Which character set modifier is in effect?>. +この修飾子は C<use locale> によってデフォルトで設定されますが、 +L</Which character set modifier is in effect?> を参照してください。 X</l> -(TBT) =head4 /u @@ -499,13 +499,12 @@ =end original これはパターンマッチングのときに Unicode の規則を使うことを意味します。 -On ASCII platforms, -this means that the code points between 128 and 255 take on their -Latin-1 (ISO-8859-1) meanings (which are the same as Unicode's), whereas -in strict ASCII their meanings are undefined. Thus the platform -effectively becomes a Unicode platform, hence, for example, C<\w> will -match any of the more than 100_000 word characters in Unicode. -(TBT) +ASCII プラットフォームでは、これは符号位置 128 から 255 は +Latin-1 (ISO-8859-1) という意味になり (これは Unicode と同じです)、 +一方厳密な ASCII ではこれらの意味は未定義です。 +従って、事実上 Unicode プラットフォームになるプラットフォームでは、 +例えば、C<\w> は Unicode の 100,000 以上の単語文字のどれにも +マッチングします。 =begin original @@ -912,15 +911,14 @@ =end original -Prior to 5.14, there were no explicit modifiers, but C</l> was implied -for regexes compiled within the scope of C<use locale>, and C</d> was -implied otherwise. However, interpolating a regex into a larger regex -would ignore the original compilation in favor of whatever was in effect -at the time of the second compilation. There were a number of -inconsistencies (bugs) with the C</d> modifier, where Unicode rules -would be used when inappropriate, and vice versa. C<\p{}> did not imply -Unicode rules, and neither did all occurrences of C<\N{}>, until 5.12. -(TBT) +5.14 より前では、明示的な修飾子はありませんが、 +C<use locale> のスコープ内でコンパイルされた正規表現に関しては +C</l> が仮定され、さもなければ C</d> が仮定されます。 +しかし、ある正規表現をより大きな正規表現に展開した場合、元のコンパイル時の +状況は、2 回目のコンパイル時点で有効なもので上書きされます。 +C</d> 演算子には、不適切なときに Unicode 規則が使われる、あるいはその逆の +多くの非一貫性(バグ)があります。 +C<\p{}> および C<\N{}> は 5.12 まで Unicode 規則を仮定していません。 =head2 Regular Expressions @@ -1636,18 +1634,16 @@ =end original -You can dispense with numbers altogether and create named capture groups. -The notation is C<(?E<lt>I<name>E<gt>...)> to declare and C<\g{I<name>}> to -reference. (To be compatible with .Net regular expressions, C<\g{I<name>}> may -also be written as C<\k{I<name>}>, C<\kE<lt>I<name>E<gt>> or C<\k'I<name>'>.) -I<name> must not begin with a number, nor contain hyphens. -When different groups within the same pattern have the same name, any reference -to that name assumes the leftmost defined group. Named groups count in -absolute and relative numbering, and so can also be referred to by those -numbers. -(It's possible to do things with named capture groups that would otherwise -require C<(??{})>.) -(TBT) +数値を全く使わずに、名前付き捕捉グループを作ることが出来ます。 +記法は、宣言が C<(?E<lt>I<name>E<gt>...)>、参照が C<\g{I<name>}> です。 +(.Net 正規表現との互換性のために、C<\g{I<name>}> は C<\k{I<name>}>, +C<\kE<lt>I<name>E<gt>>, C<\k'I<name>'> とも書けます。) +I<name> は数字で始まってはならず、ハイフンを含んではなりません。 +同じパターンの中に同じ名前の違うグループがある場合、 +この名前での参照は一番左で定義されたものを仮定します。 +名前付きグループも絶対や相対番号付けに含まれるので、 +番号で参照することも出来ます。 +(C<(??{})> が必要な場合でも名前付き捕捉グループを使うことが出来ます。) =begin original @@ -1675,12 +1671,12 @@ =end original -Braces are required in referring to named capture groups, but are optional for -absolute or relative numbered ones. Braces are safer when creating a regex by -concatenating smaller strings. For example if you have C<qr/$a$b/>, and C<$a> -contained C<"\g1">, and C<$b> contained C<"37">, you would get C</\g137/> which -is probably not what you intended. -(TBT) +名前付き捕捉グループを参照するには中かっこが必要です; +しかし、絶対数値や相対数値の場合はオプションです。 +より小さい文字列を結合して正規表現を作る場合は中かっこを使う方が安全です。 +例えば C<qr/$a$b/> で C<$a> に C<"\g1"> を含み、 +C<$b> に C<"37"> を含んでいるとき、 +結果は C</\g137/> となりますが、おそらく望んでいたものではないでしょう。 =begin original @@ -1703,23 +1699,26 @@ =end original -The C<\g> and C<\k> notations were introduced in Perl 5.10.0. Prior to that -there were no named nor relative numbered capture groups. Absolute numbered -groups were referred to using C<\1>, -C<\2>, etc., and this notation is still -accepted (and likely always will be). But it leads to some ambiguities if -there are more than 9 capture groups, as C<\10> could mean either the tenth -capture group, or the character whose ordinal in octal is 010 (a backspace in -ASCII). Perl resolves this ambiguity by interpreting C<\10> as a backreference -only if at least 10 left parentheses have opened before it. Likewise C<\11> is -a backreference only if at least 11 left parentheses have opened before it. -And so on. C<\1> through C<\9> are always interpreted as backreferences. -There are several examples below that illustrate these perils. You can avoid -the ambiguity by always using C<\g{}> or C<\g> if you mean capturing groups; -and for octal constants always using C<\o{}>, or for C<\077> and below, using 3 -digits padded with leading zeros, since a leading zero implies an octal -constant. -(TBT) +C<\g> と C<\k> の記法は Perl 5.10.0 で導入されました。 +それより前には名前付きや相対数値指定の捕捉グループはありませんでした。 +絶対数値指定のグループは C<\1>, C<\2> などとして参照でき、この記法はまだ +受け付けられます (そしておそらくいつも受け付けられます)。 +しかし、これは 9 を越える捕捉グループがあるとあいまいさがあります; +C<\10> は 10 番目の捕捉グループとも、8 進数で 010 の文字(ASCII で +バックスペース)とも解釈できます。 +Perl はこのあいまいさを以下のように解決します; +C<\10> の場合、これの前に少なくとも 10 の左かっこがある場合にのみ +これを後方参照として解釈します。 +同様に、C<\11> はその前に少なくとも 11 の左かっこがある場合にのみ +これを後方参照として解釈します。 +以下同様です。 +C<\1> から C<\9> は常に後方参照として解釈されます。 +これを図示するいくつかの例が後にあります。 +捕捉グループを意味する場合は常に C<\g{}> や C<\g> を使うことで +あいまいさを避けられます; +そして 8 進定数については常に C<\o{}> を使うか、C<\077> 以下の場合は、 +先頭に 0 を付けて 3 桁にします; なぜなら先頭に 0 が付くと +8 進定数を仮定するからです。 =begin original