[#20036] Re: Roundoff problem with Float and Marshal — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

16 messages 2003/04/18
[#20045] Re: Roundoff problem with Float and Marshal — nobu.nakada@... 2003/04/20

なかだです。

[#20063] Re: Roundoff problem with Float and Marshal — matz@... (Yukihiro Matsumoto) 2003/04/22

まつもと ゆきひろです

[#20097] jcode.rb — akira yamada / やまだあきら <akira@...>

25 messages 2003/04/26
[#20098] Re: jcode.rb — matz@... (Yukihiro Matsumoto) 2003/04/27

まつもと ゆきひろです

[#20105] Re: jcode.rb — WATANABE Hirofumi <eban@...> 2003/04/28

わたなべです。

[#20108] Re: jcode.rb — matz@... (Yukihiro Matsumoto) 2003/04/28

まつもと ゆきひろです

[ruby-dev:19976] Re: How do we parse Regular Expressions in our brain?

From: Tanaka Akira <akr@...17n.org>
Date: 2003-04-09 11:11:54 UTC
List: ruby-dev #19976
In article <1049302728.174278.6223.nullmailer@picachu.netlab.jp>,
  matz@ruby-lang.org (Yukihiro Matsumoto) writes:

> |>  /a]/ とかでしょうか。これは警告してもいいんじゃないかと私も思います。
> |
> |さて、どうしましょうね。
>
> この警告には賛成。

> |> [abcd-f-hijk]        
> |> [--abc], [ab%--]
>
> に警告でどうでしょう。

そうするんであれば、こうですかねぇ。

Index: regex.c
===================================================================
RCS file: /src/ruby/regex.c,v
retrieving revision 1.85
diff -u -r1.85 regex.c
--- regex.c	8 Apr 2003 05:40:29 -0000	1.85
+++ regex.c	9 Apr 2003 11:04:34 -0000
@@ -1487,7 +1487,9 @@
 	}
 	had_char_class = 0;
 
-	if (c == '-' && p != p0 + 1 && *p != ']')
+	if (c == '-' && ((p != p0 + 1 && *p != ']') ||
+                         (p[0] == '-' && p[1] != ']') ||
+                         range))
           re_warning("character class has `-' without escape");
         if (c == '[' && *p != ':')
           re_warning("character class has `[' without escape");
@@ -1675,8 +1677,6 @@
 	  if (last > c)
 	    goto invalid_pattern;
 
-	  if (last == '-' || c == '-')
-	    re_warning("character class has `-' without escape");
 	  range = 0;
 	  if (had_mbchar == 0) {
 	    for (;last<=c;last++)
@@ -2349,6 +2349,8 @@
       if (options & RE_OPTION_EXTENDED)
 	break;
 
+    case ']':
+      re_warning("regexp has `]' without escape");
     default:
     normal_char:		/* Expects the character in `c'.  */
       had_mbchar = 0;

今のだと、

% ./ruby -e '/[\--a]/'
-e:1: warning: character class has `-' without escape

となっちゃうし。

私としてはさらに p0 の所を変えたいわけではありますが...
-- 
[田中 哲][たなか あきら][Tanaka Akira]

In This Thread