[#33567] rational, complex and nuby — Tadayoshi Funaba <tadf@...>

ruby に rational と complex を組みこもうと試していて nuby という派生物

21 messages 2008/02/02

[#33580] Re: cgi.rb再構築案 — "Makoto Kuwata" <kwa@...>

桑田といいます。

17 messages 2008/02/03

[#33611] Solaris で timeout.rb が Segmentation fault する。 — shiiya@...

はじめまして。椎屋と申します。

15 messages 2008/02/06
[#33612] Re: Solaris で timeout.rb が Segmentation fault する。 — Nobuyoshi Nakada <nobu@...> 2008/02/06

なかだです。

[#33613] Re: Solaris で timeout.rb が Segmentation fault する。 — shiiya yoshitaka <shiiya@...> 2008/02/06

椎屋です。反応ありがとうございます。

[#33650] Re: Solaris で timeout.rb が Segmentation fault する。 — Nobuyoshi Nakada <nobu@...> 2008/02/08

なかだです。

[#33621] EUC-KR <-> UTF-8 transition table — "Park Ji-In" <tisphie@...>

朴 芝印です。

15 messages 2008/02/06

[#33628] encdet.rb — Tanaka Akira <akr@...>

前から考えていたのですが、ファイル先頭の magic comment や

18 messages 2008/02/07

[#33662] rational, complex and mathn — Tadayoshi Funaba <tadf@...>

rational は floor、truncate、ceil、round を定義していません。Numeric

66 messages 2008/02/08
[#33663] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/08

他にも問題、課題はあると思います。すぐに解決できるものと、そうでないも

[#33664] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/08

ひとつ書き忘れました。

[#33707] Re: rational, complex and mathn — Yukihiro Matsumoto <matz@...> 2008/02/12

まつもと ゆきひろです

[#33714] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/12

> 原さんのrationalは導入予定がありますので、この機会にもう一度

[#33727] Re: rational, complex and mathn — Shin-ichiro HARA <sinara@...> 2008/02/13

原です。

[#33761] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/13

> 前にふなばさんと個人的なメールのやりとりで、結局また私がrationalをまと

[#33788] Re: rational, complex and mathn — Shin-ichiro HARA <sinara@...> 2008/02/15

原です。

[#33795] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/15

> > それなりに速くはなるし、単純なところでそれなりに満足していますが、一度、

[#33806] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/16

nurat 0.0.2 を出しました (ついでに nucomp も)。

[#33812] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/16

仕様を確認していきたいと思います。

[#33815] Re: rational, complex and mathn — Yukihiro Matsumoto <matz@...> 2008/02/16

まつもと ゆきひろです

[#33818] Re: rational, complex and mathn — Shin-ichiro HARA <sinara@...> 2008/02/16

原です。

[#33819] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/17

> > new!はRubyで実装しているためにだけ必要なので、Cで実装するな

[#33821] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/17

> Rational() は、1つか2つの引数をとる。

[#33827] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/17

> 実際的に重要な機能が Rational() という名前で固定されるのはクラスの定義

[#33845] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/18

もうあまり手を入れないでおこうと思ったのです、つい手を入れてしまいまし

[#33886] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/21

ちょっと実験してみました。原さんの rational は、かけ算割り算が速いので、

[#33888] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/21

で、考えていたんですが、目的は、最速の rational を作ることではなくて、

[#33903] Re: rational, complex and mathn — Shin-ichiro HARA <sinara@...> 2008/02/22

原です。

[#33905] Re: rational, complex and mathn — "NARUSE, Yui" <naruse@...> 2008/02/22

成瀬です。

[#33908] Re: rational, complex and mathn — Yukihiro Matsumoto <matz@...> 2008/02/22

まつもと ゆきひろです

[#33914] Re: rational, complex and mathn — Tadayoshi Funaba <tadf@...> 2008/02/23

> はい。Complexについても1.9の間に組み込んでよいと思います。

[#33679] bigdecimal — Tadayoshi Funaba <tadf@...>

bigdecimal/math.rb の BigMath は、利用者が include してつかうことを前

23 messages 2008/02/09
[#33680] Re: bigdecimal — Tadayoshi Funaba <tadf@...> 2008/02/09

Integer や Float に比べると、BigDicimal() は、1 や 1.1 を受けつけない、

[#33686] Re: bigdecimal — Tadashi Saito <[email protected]> 2008/02/10

斎藤と申します。

[#33698] Re: bigdecimal — Tadayoshi Funaba <tadf@...> 2008/02/11

> 仮にBigDecimal(1.1)を、(二進小数として)受け付けると、「BigDecimalでは、

[#33705] Re: bigdecimal — Yukihiro Matsumoto <matz@...> 2008/02/12

まつもと ゆきひろです

[#33726] Re: [ruby-cvs:22680] Ruby:r15443 (trunk): * bootstraptest/runner.rb, bootstraptest/test_method.rb, enc/depend, — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

14 messages 2008/02/13
[#33730] Re: [ruby-cvs:22680] Ruby:r15443 (trunk): * bootstraptest/runner.rb, bootstraptest/test_method.rb, enc/depend, — "NARUSE, Yui" <naruse@...> 2008/02/13

成瀬です。

[#33889] Re: [ ruby-Bugs-17454 ] irb crash while iterating over all objects — Urabe Shyouhei <shyouhei@...>

卜部です。ちょっとお知恵を拝借したく。

22 messages 2008/02/21
[#33892] Re: [ ruby-Bugs-17454 ] irb crash while iterating over all objects — Nobuyoshi Nakada <nobu@...> 2008/02/21

なかだです。

[#33909] Re: [ ruby-Bugs-17454 ] irb crash while iterating over all objects — Urabe Shyouhei <shyouhei@...> 2008/02/22

Nobuyoshi Nakada さんは書きました:

[#36081] Re: [ ruby-Bugs-17454 ] irb crash while iterating over all objects — TOYOFUKU Chikanobu <nobu_toyofuku@...> 2008/09/01

豊福です。

[#36085] Re: [ ruby-Bugs-17454 ] irb crash while iterating over all objects — Yukihiro Matsumoto <matz@...> 2008/09/01

まつもと ゆきひろです

[ruby-dev:33768] Re: [ruby-cvs:22680] Ruby:r15443 (trunk): * bootstraptest/runner.rb, bootstraptest/test_method.rb, enc/depend,

From: Nobuyoshi Nakada <nobu@...>
Date: 2008-02-13 17:16:32 UTC
List: ruby-dev #33768
なかだです。

At Wed, 13 Feb 2008 14:24:03 +0900,
Nobuyoshi Nakada wrote in [ruby-dev:33743]:
> 簡単に#{Regexp.quote()}を書く方法があって、sub/gsubの第二引数が
> Regexpだったらsourceを使う、とかならできるかもしれませんが、前者
> が難問です。

/\q#{string_expr}/で/#{Regexp.quote(string_expr)}/になるようにし
てみました。しかし、1.8だと/\1/でも問題ないんですが、1.9では厳密
になっているらしくて invalid backref number/name というエラーに
なってしまいます。いまいち使えない…。


Index: parse.y
===================================================================
--- parse.y	(revision 15457)
+++ parse.y	(working copy)
@@ -438,4 +438,5 @@ extern int rb_dvar_defined(ID);
 extern int rb_local_defined(ID);
 extern int rb_parse_in_eval(void);
+extern VALUE rb_reg_quote(VALUE);
 
 static VALUE reg_compile_gen(struct parser_params*, VALUE, int);
@@ -708,5 +709,5 @@ static void ripper_compile_error(struct 
 %token tLAMBDA		/* -> */
 %token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG
-%token tSTRING_DBEG tSTRING_DVAR tSTRING_END tLAMBEG
+%token tSTRING_DBEG tSTRING_DVAR tSTRING_END tREGEXP_QUOTE tLAMBEG
 
 /*
@@ -3851,4 +3852,32 @@ string_content	: tSTRING_CONTENT
 		    %*/
 		    }
+		| tREGEXP_QUOTE
+		    {
+			$<node>$ = lex_strterm;
+			lex_strterm = 0;
+			lex_state = EXPR_BEG;
+			COND_PUSH(0);
+			CMDARG_PUSH(0);
+		    }
+		  compstmt '}'
+		    {
+			lex_strterm = $<node>2;
+			COND_LEXPOP();
+			CMDARG_LEXPOP();
+		    /*%%%*/
+			if ($3) $3->flags &= ~NODE_NEWLINE;
+			$$ = new_evstr($3);
+			if (nd_type($$) == NODE_STR) {
+			    $$->nd_lit = rb_reg_quote($$->nd_lit);
+			}
+			else {
+			    $$ = NEW_CALL(NEW_LIT(rb_cRegexp), rb_intern("quote"),
+					  NEW_LIST($$));
+			    $$ = NEW_EVSTR($$);
+			}
+		    /*%
+			$$ = dispatch1(regexp_quote, $3);
+		    %*/
+		    }
 		;
 
@@ -5342,4 +5371,24 @@ parser_tokadd_mbchar(struct parser_param
 
 static int
+parser_regexp_quote_p(struct parser_params *parser, int func)
+{
+    if (!(func & STR_FUNC_EXPAND)) return 0;
+    if (lex_p + 1 >= lex_pend) return 0;
+    switch (lex_p[1]) {
+      case '{':
+	lex_p += 2;
+	return 1;
+      case '#':
+	if (lex_p + 2 < lex_pend && lex_p[2] == '{') {
+	    lex_p += 3;
+	    return 1;
+	}
+    }
+    return 0;
+}
+
+#define regexp_quote_p(func) parser_regexp_quote_p(parser, func)
+
+static int
 parser_tokadd_string(struct parser_params *parser,
 		     int func, int term, int paren, long *nest,
@@ -5414,4 +5463,9 @@ parser_tokadd_string(struct parser_param
 		continue;
 
+	      case 'q':
+		if (regexp_quote_p(func)) {
+		    lex_p = beg;
+		    goto exit;
+		}
 	      default:
 		if (func & STR_FUNC_REGEXP) {
@@ -5464,4 +5518,5 @@ parser_tokadd_string(struct parser_param
 	tokadd(c);
     }
+  exit:
     *encp = enc;
     return c;
@@ -5511,4 +5566,7 @@ parser_parse_string(struct parser_params
 	tokadd('#');
     }
+    else if (c == '\\' && peek('q') && regexp_quote_p(func)) {
+	return tREGEXP_QUOTE;
+    }
     pushback(c);
     if (tokadd_string(func, term, paren, &quote->nd_nest,
Index: re.c
===================================================================
--- re.c	(revision 15457)
+++ re.c	(working copy)
@@ -306,5 +306,5 @@ rb_reg_desc(const char *s, long len, VAL
  */
 
-static VALUE
+VALUE
 rb_reg_source(VALUE re)
 {
@@ -2837,4 +2837,5 @@ rb_reg_regsub(VALUE str, VALUE src, stru
     rb_encoding *str_enc = rb_enc_get(str);
     rb_encoding *src_enc = rb_enc_get(src);
+    int quote = 0;
 
     p = s = RSTRING_PTR(str);
@@ -2867,4 +2868,18 @@ rb_reg_regsub(VALUE str, VALUE src, stru
         s += clen;
 
+	switch (c) {
+	  case 'Q':
+	    quote = 1;
+	    p = s;
+	    continue;
+	  case 'E':
+	    quote = 0;
+	    p = s;
+	    continue;
+	  default:
+	    if (quote) continue;
+	    break;
+	}
+
 	p = s;
 	switch (c) {
Index: string.c
===================================================================
--- string.c	(revision 15457)
+++ string.c	(working copy)
@@ -2751,4 +2751,13 @@ get_pat(VALUE pat, int quote)
 }
 
+extern VALUE rb_reg_source(VALUE);
+static VALUE
+get_repl(VALUE repl)
+{
+    if (TYPE(repl) == T_REGEXP) {
+	return rb_reg_source(repl);
+    }
+    return repl;
+}
 
 /*
@@ -2775,5 +2784,5 @@ rb_str_sub_bang(int argc, VALUE *argv, V
     }
     else if (argc == 2) {
-	repl = argv[1];
+	repl = get_repl(argv[1]);
 	StringValue(repl);
 	if (OBJ_TAINTED(repl)) tainted = 1;
@@ -2903,5 +2912,5 @@ str_gsub(int argc, VALUE *argv, VALUE st
 	break;
       case 2:
-	repl = argv[1];
+	repl = get_repl(argv[1]);
 	StringValue(repl);
 	if (OBJ_TAINTED(repl)) tainted = 1;


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread

Prev Next