re-0.08 > 0.09 との差分

re 0.09 と 0.08 の差分

11
22=encoding euc-jp
33
44=head1 NAME
55
66=begin original
77
88re - Perl pragma to alter regular expression behaviour
99
1010=end original
1111
1212re - 正規表現の振る舞いを変えるための Perl プラグマ
1313
1414=head1 SYNOPSIS
1515
1616=begin original
1717
1818 use re 'taint';
1919 ($x) = ($^X =~ /^(.*)$/s); # $x is tainted here
2020
2121=end original
2222
2323 use re 'taint';
2424 ($x) = ($^X =~ /^(.*)$/s); # $x はここで汚染されている
2525
2626=begin original
2727
2828 $pat = '(?{ $foo = 1 })';
2929 use re 'eval';
3030 /foo${pat}bar/; # won't fail (when not under -T switch)
3131
3232=end original
3333
3434 $pat = '(?{ $foo = 1 })';
3535 use re 'eval';
3636 /foo${pat}bar/; # 失敗しない (-T スイッチがないとき)
3737
3838=begin original
3939
4040 {
4141 no re 'taint'; # the default
4242 ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here
4343
4444=end original
4545
4646 {
4747 no re 'taint'; # デフォルト
4848 ($x) = ($^X =~ /^(.*)$/s); # $x はここで汚染されていない
4949
5050=begin original
5151
5252 no re 'eval'; # the default
5353 /foo${pat}bar/; # disallowed (with or without -T switch)
5454 }
5555
5656=end original
5757
5858 no re 'eval'; # デフォルト
5959 /foo${pat}bar/; # 許されない (-T スイッチの有無に関係なく)
6060 }
6161
6262=begin original
6363
6464 use re 'debug'; # output debugging info during
6565 /^(.*)$/s; # compile and run time
6666
6767=end original
6868
6969 use re 'debug'; # コンパイル時と実行時に
7070 /^(.*)$/s; # デバッグ情報を出力する
7171
7272=begin original
7373
7474 use re 'debugcolor'; # same as 'debug', but with colored output
7575 ...
7676
7777=end original
7878
7979 use re 'debugcolor'; # 'debug' と同じだが、出力に色がつく
8080 ...
8181
8282=begin original
8383
8484 use re qw(Debug All); # Finer tuned debugging options.
8585 use re qw(Debug More);
8686 no re qw(Debug ALL); # Turn of all re debugging in this scope
8787
8888=end original
8989
9090 use re qw(Debug All); # より細かいデバッグオプション
9191 use re qw(Debug More);
9292 no re qw(Debug ALL); # このスコープ内で全ての re デバッグを有効化
9393
9494 use re qw(is_regexp regexp_pattern); # import utility functions
9595 my ($pat,$mods)=regexp_pattern(qr/foo/i);
9696 if (is_regexp($obj)) {
9797 print "Got regexp: ",
9898 scalar regexp_pattern($obj); # just as perl would stringify it
9999 } # but no hassle with blessed re's.
100100
101101=begin original
102102
103103(We use $^X in these examples because it's tainted by default.)
104104
105105=end original
106106
107107(これらの例では、デフォルトで汚染されているので $^X を使っています。)
108108
109109=head1 DESCRIPTION
110110
111111=head2 'taint' mode
112112
113113('taint' モード)
114114
115115=begin original
116116
117117When C<use re 'taint'> is in effect, and a tainted string is the target
118118of a regex, the regex memories (or values returned by the m// operator
119119in list context) are tainted. This feature is useful when regex operations
120120on tainted data aren't meant to extract safe substrings, but to perform
121121other transformations.
122122
123123=end original
124124
125125C<use re 'taint'> が有効で、汚染された文字列が正規表現の
126126ターゲットであるとき、正規表現のメモリ(もしくはリストコンテキストで
127127m// 演算子が返す値)は汚染されます。
128128この機能は汚染されたデータに対する正規表現演算が安全な部分文字列を
129129取り出すものでないときに便利ですが、その他の変換は働きます。
130130
131131=head2 'eval' mode
132132
133133('eval' モード)
134134
135135=begin original
136136
137137When C<use re 'eval'> is in effect, a regex is allowed to contain
138138C<(?{ ... })> zero-width assertions even if regular expression contains
139139variable interpolation. That is normally disallowed, since it is a
140140potential security risk. Note that this pragma is ignored when the regular
141141expression is obtained from tainted data, i.e. evaluation is always
142142disallowed with tainted regular expressions. See L<perlre/(?{ code })>.
143143
144144=end original
145145
146146C<use re 'eval'> が有効なとき、変数展開を含む正規表現でも
147147ゼロ幅表明 C<(?{ ... })> を持つことができます。
148148これは通常はセキュリティ上のリスクとなる可能性があるので許されていません。
149149このプラグマは正規表現が汚染されたデータからきたものである場合には
150150無視されることに注意してください。
151151つまり、汚染された正規表現を評価することは常に許されません。
152152L<perlre/(?{ code })> を参照してください。
153153
154154=begin original
155155
156156For the purpose of this pragma, interpolation of precompiled regular
157157expressions (i.e., the result of C<qr//>) is I<not> considered variable
158158interpolation. Thus:
159159
160160=end original
161161
162162このプラグマの目的のため、プリコンパイルされた正規表現
163163(つまり、C<qr//> の結果)の展開(interpolation)は変数展開とは
164164I<みなされません>。
165165したがって:
166166
167167 /foo${pat}bar/
168168
169169=begin original
170170
171171I<is> allowed if $pat is a precompiled regular expression, even
172172if $pat contains C<(?{ ... })> assertions.
173173
174174=end original
175175
176176は、$pat がプリコンパイルされた正規表現であれば、たとえ $pat が
177177C<(?{ ... })> 表明を含んでいたとしても I<許されます>。
178178
179179=head2 'debug' mode
180180
181181('debug' モード)
182182
183183=begin original
184184
185185When C<use re 'debug'> is in effect, perl emits debugging messages when
186186compiling and using regular expressions. The output is the same as that
187187obtained by running a C<-DDEBUGGING>-enabled perl interpreter with the
188188B<-Dr> switch. It may be quite voluminous depending on the complexity
189189of the match. Using C<debugcolor> instead of C<debug> enables a
190190form of output that can be used to get a colorful display on terminals
191191that understand termcap color sequences. Set C<$ENV{PERL_RE_TC}> to a
192192comma-separated list of C<termcap> properties to use for highlighting
193193strings on/off, pre-point part on/off.
194194See L<perldebug/"Debugging regular expressions"> for additional info.
195195
196196=end original
197197
198198C<use re 'debug'> が有効なとき、perl は正規表現をコンパイルするときと
199199使うときにデバッグ用メッセージを出力します。
200200その出力は C<-DDEBUGGING> が有効になっている perl インタプリタに
201201B<-Dr> スイッチを与えたときと同じです。
202202これはマッチの複雑さに応じて非常に多弁になる可能性があります。
203203C<debug> の代わりに C<debugcolor> を使うと、termcap カラーシーケンスを
204204使ったカラフルな出力を端末に行います。
205205C<termcap> プロパティのカンマ区切りのリストを C<$ENV{PERL_RE_TC}> に
206206セットすることで、文字列のオン/オフや pre-point 部分のオン/オフを
207207ハイライトできます。
208208更なる情報については
209209L<perldebug/"Debugging regular expressions"> を参照してください。
210210
211211=begin original
212212
213213As of 5.9.5 the directive C<use re 'debug'> and its equivalents are
214214lexically scoped, as the other directives are. However they have both
215215compile-time and run-time effects.
216216
217217=end original
218218
2192195.9.5 現在、
220220C<use re 'debug'> 指示子およびそれと等価な設定は、他の指示子と同様
221221レキシカルスコープです。
222222しかしこれらはコンパイル時と実行時の両方に影響を及ぼします。
223223
224224=begin original
225225
226226See L<perlmodlib/Pragmatic Modules>.
227227
228228=end original
229229
230230L<perlmodlib/Pragmatic Modules> を参照してください。
231231
232232=head2 'Debug' mode
233233
234234('Debug' モード)
235235
236236=begin original
237237
238238Similarly C<use re 'Debug'> produces debugging output, the difference
239239being that it allows the fine tuning of what debugging output will be
240240emitted. Options are divided into three groups, those related to
241241compilation, those related to execution and those related to special
242242purposes. The options are as follows:
243243
244244=end original
245245
246246C<use re 'Debug'> と同様にデバッグ出力を生成しますが、
247247どのデバッグ情報が出力されるかを細かく制御できることが違います。
248248操作は、コンパイル関係、実行関係、特殊用途関係の 3 つのグループに
249249分割されます。
250250オプションは以下の通りです:
251251
252252=over 4
253253
254254=item Compile related options
255255
256256(コンパイル関係オプション)
257257
258258=over 4
259259
260260=item COMPILE
261261
262262=begin original
263263
264264Turns on all compile related debug options.
265265
266266=end original
267267
268268コンパイル関係のオプションを全て有効にします。
269269
270270=item PARSE
271271
272272=begin original
273273
274274Turns on debug output related to the process of parsing the pattern.
275275
276276=end original
277277
278278パターンのパース処理に関係するデバッグ出力を有効にします。
279279
280280=item OPTIMISE
281281
282282=begin original
283283
284284Enables output related to the optimisation phase of compilation.
285285
286286=end original
287287
288288コンパイルの最適化フェーズに関係するデバッグ出力を有効にします。
289289
290290=item TRIEC
291291
292292=begin original
293293
294294Detailed info about trie compilation.
295295
296296=end original
297297
298298トライ木のコンパイルに関する詳細情報。
299299
300300=item DUMP
301301
302302=begin original
303303
304304Dump the final program out after it is compiled and optimised.
305305
306306=end original
307307
308308コンパイルと最適化の後の最終的なプログラムの出力をダンプします。
309309
310310=back
311311
312312=item Execute related options
313313
314314(実行関係オプション)
315315
316316=over 4
317317
318318=item EXECUTE
319319
320320=begin original
321321
322322Turns on all execute related debug options.
323323
324324=end original
325325
326326実行関係のデバッグオプションを全て有効にします。
327327
328328=item MATCH
329329
330330=begin original
331331
332332Turns on debugging of the main matching loop.
333333
334334=end original
335335
336336メインマッチングループのデバッグを有効にします。
337337
338338=item TRIEE
339339
340340=begin original
341341
342342Extra debugging of how tries execute.
343343
344344=end original
345345
346346トライ木をどのように実行するかに関する追加のデバッグ。
347347
348348=item INTUIT
349349
350350=begin original
351351
352352Enable debugging of start point optimisations.
353353
354354=end original
355355
356356開始点最適化のデバッグを有効にします。
357357
358358=back
359359
360360=item Extra debugging options
361361
362362(追加デバッグオプション)
363363
364364=over 4
365365
366366=item EXTRA
367367
368368=begin original
369369
370370Turns on all "extra" debugging options.
371371
372372=end original
373373
374374「追加の」デバッグオプションを全て有効にします。
375375
376376=item BUFFERS
377377
378378=begin original
379379
380380Enable debugging the capture buffer storage during match. Warning,
381381this can potentially produce extremely large output.
382382
383383=end original
384384
385385マッチング中の捕捉バッファのデバッグを有効にします。
386386これは極めて大きい出力を生成する可能性があることを警告しておきます。
387387
388388=item TRIEM
389389
390390=begin original
391391
392392Enable enhanced TRIE debugging. Enhances both TRIEE
393393and TRIEC.
394394
395395=end original
396396
397397拡張された TRIE デバッグを有効にします。
398398TRIEE と TRIEC の両方を拡張します。
399399
400400=item STATE
401401
402402=begin original
403403
404404Enable debugging of states in the engine.
405405
406406=end original
407407
408408エンジンの状態のデバッグを有効にします。
409409
410410=item STACK
411411
412412=begin original
413413
414414Enable debugging of the recursion stack in the engine. Enabling
415415or disabling this option automatically does the same for debugging
416416states as well. This output from this can be quite large.
417417
418418=end original
419419
420420エンジンの再帰スタックのデバッグを有効にします。
421421このオプションを有効または無効にすると、デバッグ状態も同様に
422422同じ状態になります。
423423この出力はかなり大きくなることがあります。
424424
425425=item OPTIMISEM
426426
427427=begin original
428428
429429Enable enhanced optimisation debugging and start point optimisations.
430430Probably not useful except when debugging the regex engine itself.
431431
432432=end original
433433
434434拡張最適化デバッグと開始位置最適化を有効にします。
435435正規表現自身をデバッグするのでなければ、おそらく有用ではありません。
436436
437437=item OFFSETS
438438
439439=begin original
440440
441441Dump offset information. This can be used to see how regops correlate
442442to the pattern. Output format is
443443
444444=end original
445445
446446オフセット情報をダンプします。
447447これは、どのように regops がパターンと関連するかを見るために使えます。
448448出力フォーマットは
449449
450450 NODENUM:POSITION[LENGTH]
451451
452452=begin original
453453
454454Where 1 is the position of the first char in the string. Note that position
455455can be 0, or larger than the actual length of the pattern, likewise length
456456can be zero.
457457
458458=end original
459459
460460文字列の最初の文字の位置は 1 です。
461461位置が 0 であったり、パターンの実際の長さより大きかったり、
462462長さが 0 であったりするかもしれないことに注意してください。
463463
464464=item OFFSETSDBG
465465
466466=begin original
467467
468468Enable debugging of offsets information. This emits copious
469469amounts of trace information and doesn't mesh well with other
470470debug options.
471471
472472=end original
473473
474474オフセット情報のデバッグを有効にします。
475475これは大量のトレース情報を出力し、他のデバッグオプションとはうまく
476476かみ合いません。
477477
478478=begin original
479479
480480Almost definitely only useful to people hacking
481481on the offsets part of the debug engine.
482482
483483=end original
484484
485485ほぼ確実に、デバッグエンジンのオフセット部分をハックする人々によってのみ
486486有用です。
487487
488488=back
489489
490490=item Other useful flags
491491
492492(その他の便利なフラグ)
493493
494494=begin original
495495
496496These are useful shortcuts to save on the typing.
497497
498498=end original
499499
500500タイプ数を節約するための便利な短縮記法があります。
501501
502502=over 4
503503
504504=item ALL
505505
506506=begin original
507507
508508Enable all options at once except OFFSETS, OFFSETSDBG and BUFFERS
509509
510510=end original
511511
512512OFFSETS, OFFSETSDBG, BUFFERS 以外の全てのオプションを有効にします。
513513
514514=item All
515515
516516=begin original
517517
518518Enable DUMP and all execute options. Equivalent to:
519519
520520=end original
521521
522522DUMP と、全ての実行関係のオプションを有効にします。
523523以下と等価です:
524524
525525 use re 'debug';
526526
527527=item MORE
528528
529529=item More
530530
531531=begin original
532532
533533Enable TRIEM and all execute compile and execute options.
534534
535535=end original
536536
537537TRIEM と、全てのコンパイル関係および実行関係のオプションを有効にします。
538538
539539=back
540540
541541=back
542542
543543=begin original
544544
545545As of 5.9.5 the directive C<use re 'debug'> and its equivalents are
546546lexically scoped, as the other directives are. However they have both
547547compile-time and run-time effects.
548548
549549=end original
550550
5515515.9.5 以降、C<use re 'debug'> 指示子およびその等価物は、その他の指示子と同様
552552レキシカルスコープを持ちます。
553553しかし、これらはコンパイル時と実行時の両方で効果があります。
554554
555555=head2 Exportable Functions
556556
557557(エクスポート可能な関数)
558558
559559=begin original
560560
561561As of perl 5.9.5 're' debug contains a number of utility functions that
562562may be optionally exported into the caller's namespace. They are listed
563563below.
564564
565565=end original
566566
567567perl 5.9.5 以降、're' debug には、呼び出し元の名前空間にエクスポートできる、
568568いくつかの便利関数を含んでいます。
569569以下に一覧を示します。
570570
571571=over 4
572572
573573=item is_regexp($ref)
574574
575575=begin original
576576
577577Returns true if the argument is a compiled regular expression as returned
578578by C<qr//>, false if it is not.
579579
580580=end original
581581
582582引数が、C<qr//> から返された、コンパイル済み正規表現の場合は真を、
583583さもなければ偽を返します。
584584
585585=begin original
586586
587587This function will not be confused by overloading or blessing. In
588588internals terms, this extracts the regexp pointer out of the
589589PERL_MAGIC_qr structure so it it cannot be fooled.
590590
591591=end original
592592
593593この関数はオーバーロードや bless によって混乱しません。
594594内部用語で言うと、PERL_MAGIC_qr 構造体から正規表現ポインタを
595595取り出しているので、だまされることはありません。
596596
597597=item regexp_pattern($ref)
598598
599599=begin original
600600
601601If the argument is a compiled regular expression as returned by C<qr//>,
602602then this function returns the pattern.
603603
604604=end original
605605
606606引数が、C<qr//> から返された、コンパイル済み正規表現の場合、
607607この関数はパターンを返します。
608608
609609=begin original
610610
611611In list context it returns a two element list, the first element
612612containing the pattern and the second containing the modifiers used when
613613the pattern was compiled.
614614
615615=end original
616616
617617リストコンテキストでは 2 要素のリストを返し、1 番目の要素はパターン、
6186182 番目はパターンがコンパイルされたときに使われた修飾子です。
619619
620620 my ($pat, $mods) = regexp_pattern($ref);
621621
622622=begin original
623623
624624In scalar context it returns the same as perl would when strigifying a raw
625625C<qr//> with the same pattern inside. If the argument is not a compiled
626626reference then this routine returns false but defined in scalar context,
627627and the empty list in list context. Thus the following
628628
629629=end original
630630
631631スカラコンテキストでは、生の C<qr//> の中に書くことで perl が
632632文字列化したときに同じ内容になるものを返します。
633633引数がコンパイルされたリファレンスではない場合、スカラコンテキストでは
634634「偽だが定義済み」を返し、リストコンテキストでは空リストを返します。
635635従って、以下の文
636636
637637 if (regexp_pattern($ref) eq '(?i-xsm:foo)')
638638
639639=begin original
640640
641641will be warning free regardless of what $ref actually is.
642642
643643=end original
644644
645645は、実際の $ref が何であっても警告は出ません。
646646
647647=begin original
648648
649649Like C<is_regexp> this function will not be confused by overloading
650650or blessing of the object.
651651
652652=end original
653653
654654C<is_regexp> と同様、この関数はオブジェクトのオーバーロードや bless によって
655655混乱しません。
656656
657657=item regmust($ref)
658658
659659=begin original
660660
661661If the argument is a compiled regular expression as returned by C<qr//>,
662662then this function returns what the optimiser consiers to be the longest
663663anchored fixed string and longest floating fixed string in the pattern.
664664
665665=end original
666666
667667引数が C<qr//> で返されたコンパイル済み正規表現の場合、この関数は、
668668パターンの中でオプティマイザが最長の不動不変文字列および最長の
669669浮遊不変文字列と考えたものを返します。
670670
671671=begin original
672672
673673A I<fixed string> is defined as being a substring that must appear for the
674674pattern to match. An I<anchored fixed string> is a fixed string that must
675675appear at a particular offset from the beginning of the match. A I<floating
676676fixed string> is defined as a fixed string that can appear at any point in
677677a range of positions relative to the start of the match. For example,
678678
679679=end original
680680
681681I<不変文字列> (fixed string) とは、マッチングするパターンとして
682682現れなければならない部分文字列として定義されます。
683683I<不動不変文字列> (anchored fixed string) とは、マッチングの開始からの
684684特定の位置に現れなければならない不変文字列です。
685685I<浮遊不変文字列> (floating fixed string) とは、マッチングの開始からの
686686相対位置の範囲でどの位置に現れてもよい不変文字列として定義されます。
687687例えば、
688688
689689 my $qr = qr/here .* there/x;
690690 my ($anchored, $floating) = regmust($qr);
691691 print "anchored:'$anchored'\nfloating:'$floating'\n";
692692
693693=begin original
694694
695695results in
696696
697697=end original
698698
699699これの結果は
700700
701701 anchored:'here'
702702 floating:'there'
703703
704704=begin original
705705
706706Because the C<here> is before the C<.*> in the pattern, its position
707707can be determined exactly. That's not true, however, for the C<there>;
708708it could appear at any point after where the anchored string appeared.
709709Perl uses both for its optimisations, prefering the longer, or, if they are
710710equal, the floating.
711711
712712=end original
713713
714714パターンの中で C<here> は C<.*> の前にあるので、この位置は正確に
715715決定されます。
716716しかし、このことは C<there> には当てはまりません;
717717これは不動不変文字列の後ならどの地点にでも現れる可能性があります。
718718Perl は最適化のためにこれらの両方を、長い方(同じ場合は浮遊)を優先して
719719使います。
720720
721721=begin original
722722
723723B<NOTE:> This may not necessarily be the definitive longest anchored and
724724floating string. This will be what the optimiser of the Perl that you
725725are using thinks is the longest. If you believe that the result is wrong
726726please report it via the L<perlbug> utility.
727727
728728=end original
729729
730730B<注意:> これは最終的な最長の不動及び浮遊文字列とは限りません。
731731これは Perl のオプティマイザが最長と考えたものです。
732732もし結果が間違っていると信じるなら、L<perlbug> ユーティリティ経由で
733733報告を送ってください。
734734
735735=item regname($name,$all)
736736
737737=begin original
738738
739739Returns the contents of a named buffer of the last successful match. If
740740$all is true, then returns an array ref containing one entry per buffer,
741741otherwise returns the first defined buffer.
742742
743743=end original
744744
745745最後に成功したマッチングの名前付きバッファの内容を返します。
746746$all が真なら、バッファごとに一つの要素となる配列リファレンスを返します;
747747さもなければ最初に定義されたバッファを返します。
748748
749749=item regnames($all)
750750
751751=begin original
752752
753753Returns a list of all of the named buffers defined in the last successful
754754match. If $all is true, then it returns all names defined, if not it returns
755755only names which were involved in the match.
756756
757757=end original
758758
759759最後に成功したマッチングで定義された全ての名前付きバッファのリストを
760760返します。
761761$all が真なら、定義された全ての名前を返します;
762762さもなければマッチングに関わった名前のみを返します。
763763
764764=item regnames_count()
765765
766766=begin original
767767
768768Returns the number of distinct names defined in the pattern used
769769for the last successful match.
770770
771771=end original
772772
773773最後に成功したマッチングで使われたパターンで定義された、異なる名前の数を
774774返します。
775775
776776=begin original
777777
778778B<Note:> this result is always the actual number of distinct
779779named buffers defined, it may not actually match that which is
780780returned by C<regnames()> and related routines when those routines
781781have not been called with the $all parameter set.
782782
783783=end original
784784
785785B<注意:> この結果は常に、定義された異なる名前付きバッファの実際の数となり、
786786C<regnames()> や関連するルーチンが $all 引数をセットせずに呼び出された
787787場合に返したものと一致しないことがあります。
788788
789789=back
790790
791791=head1 SEE ALSO
792792
793793L<perlmodlib/Pragmatic Modules>.
794794
795795=begin meta
796796
797797Translate: KIMURA Koichi (0.04)
798Update: Kentaro Shirakata <argrath@ub32.org> (0.08-)
798Update: Kentaro Shirakata <argrath@ub32.org> (0.08)
799799
800800=end meta
801801
802802=cut