Project

General

Profile

Actions

Bug #3319

closed

Regexp#unionの説明と動作で食い違いがある。

Added by tarui (Masaya Tarui) almost 14 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2dev (2010-05-18 revision 27873) [i386-mswin32_90]
Backport:
[ruby-dev:41354]

Description

=begin
樽家です。

[ruby-dev:41247]から議論したもので、Regexp#unionの説明と動作で食い違いがあります。

食い違いの具体的な例については、
[ruby-dev:41247]及び[ruby-dev:41267]を参照ください。
内容としては、
ドキュメントでは要素のどれにでもマッチする正規表現を返すとしているのに対し、
実装では、
・後方参照を含む場合に他の要素の影響を受けて参照対象がずれる可能性がある。
・文字コード10を意味していた'\10'が後方参照として扱われる可能性がある。
・同じ名前の名前付き捕獲式集合を持つ要素同士のunionではエラーになる。
といったものです。

スレッドの中では動作の方を仕様とするという意見でしたので、苦手ながら英語ドキュメントの修正版を考えてみました。
結局 string-operated と probably を追加しただけですが、こんなのでいいんでしょうか?。。。

Return a Regexp object that is the string-operated union of the given patterns, i.e.,
will probably match any of its parts. The patterns can be Regexp objects, in
which case their options will be preserved, or Strings. If no
arguments are given, returns /(?!)/.
=end

Actions #1

Updated by mame (Yusuke Endoh) almost 14 years ago

=begin
遠藤です。

2010年5月19日21:43 Masaya Tarui :

ドキュメントでは要素のどれにでもマッチする正規表現を返すとしているのに対し、
実装では、
・後方参照を含む場合に他の要素の影響を受けて参照対象がずれる可能性がある。
・文字コード10を意味していた'\10'が後方参照として扱われる可能性がある。
・同じ名前の名前付き捕獲式集合を持つ要素同士のunionではエラーになる。
といったものです。

当面は「与えられたパターンにキャプチャがあったら不定」ってことで
どうでしょうか。

diff --git a/re.c b/re.c
index dddd941..e272146 100644
--- a/re.c
+++ b/re.c
@@ -3195,6 +3195,7 @@ rb_reg_s_union(VALUE self, VALUE args0)

  • patterns, i.e., will match any of its parts. The patterns
  • can be Regexp objects, in which case their options will be preserved, or
  • Strings. If no patterns are given, returns /(?!)/.
    • The behavior is unspecified if any given pattern contains capture.
    • Regexp.union                         #=> /(?!)/
      
    • Regexp.union("penzance")             #=> /penzance/
      

--
Yusuke Endoh

=end

Actions #2

Updated by tarui (Masaya Tarui) almost 14 years ago

=begin
樽家です。

probablyは酷かったですね。すいません。
代案ありがとうございます。これで個人的には特に不満ありません。

=end

Actions #3

Updated by mame (Yusuke Endoh) almost 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r27929.
Masaya, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0