[#26266] pragma on ripper — nobuyoshi nakada <nobuyoshi.nakada@...>
なかだです。
こんにちは、なかむら(う)です。
なかだです。
[#26284] ext/tk/sample/tkextlib/tile/demo.rb で TypeError — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp>
山本です。
[#26298] ext/tk/sample/tkextlib/tile/themes — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp>
山本です。
[#26305] ext/tk/sample/tkextlib/ICONS/viewIcons.rb — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp>
山本です。
永井@知能.九工大です.
[#26312] rb_gc_mark_threads spin — Tanaka Akira <akr@...17n.org>
最近、とあるプログラム(五月雨)が、無限ループに陥ることが何回かありました。
なかだです。
In article <TYOMLEM04FRaqbC8wSA00000024@tyomlvem02.e2k.ad.ge.com>,
なかだです。
In article <TYOMLEM04FRaqbC8wSA00000025@tyomlvem02.e2k.ad.ge.com>,
なかだです。
In article <TYOMLEM04Rqf69aZbLA0000002d@tyomlvem02.e2k.ad.ge.com>,
なかだです。
In article <200506101543.j5AFhToG009328@sharui.nakada.niregi.kanuma.tochigi.jp>,
In article <8764wlil9l.fsf@m17n.org>,
なかだです。
In article <200506111335.j5BDZkoG019423@sharui.nakada.niregi.kanuma.tochigi.jp>,
まつもと ゆきひろです
In article <1118583170.298416.26464.nullmailer@x31.priv.netlab.jp>,
まつもと ゆきひろです
In article <1118586617.180748.27381.nullmailer@x31.priv.netlab.jp>,
[#26324] XMLRPC charset — Kazuhiro NISHIYAMA <zn@...>
西山和広です。
[#26358] test failures and errors — Kazuhiro NISHIYAMA <zn@...>
西山和広です。
[#26387] warningを減らす — Kazuhiro NISHIYAMA <zn@...>
西山和広です。
[#26405] WEBrick DoS vulnerability — Tanaka Akira <akr@...17n.org>
NetBSD 2.0 で WEBrick を使って HTTP サーバを動かした場合、クライアント
ごとうゆうぞうです。
In article <20050708.175802.957830318.gotoyuzo@sawara.does.notwork.org>,
In message <87fyupzgcq.fsf@m17n.org>,
In article <20050708.211519.179953950.gotoyuzo@sawara.does.notwork.org>,
In message <87d5ptzdpc.fsf@m17n.org>,
前田です。
In article <42CF1AF2.5000407@ruby-lang.org>,
In message <878y0erpv7.fsf@m17n.org>,
[#26410] irbのlexerが数値認識に失敗 — Kazuhiro NISHIYAMA <zn@...>
西山和広です。
[#26417] test.rb failed 167W: ruby 1.9.0 (2005-06-30) [i686-linux] (boron) — Kazuhiro NISHIYAMA <zn@...>
西山和広です。
[#26421] Subversion — Shugo Maeda <shugo@...>
前田です。
まつもと ゆきひろです
こんにちは、なかむら(う)です。
山本です。
須藤です.
In article <20050703.152549.41008576.kou@cozmixng.org>,
[ruby-dev:26279] match index
ささだです。
正規表現で複数の括弧があったとき、「最後に n 番目($n)の括弧にマッ
チした」という情報を得ることが出来ないでしょうか。
つまり、/(A)|(B)|(C)/ =~ 'B' とあったとき、2 という情報が欲しい、と
いう意味です。
Ruby での文字列のトークン化はよくやる話だと思うのですが、これを正規
表現とあわせて効率よくやる方法を考えていたんですが、素直に書くとパター
ンとアクション(もしくはそのトークンの種別を表すシンボル)の組を作って
ループで回して、みたいな処理になるかと思うんですが、これが楽にならない
かな、と。
case/when でヒットしたらアクションをその場で記述、という場合には今の
VMではあんまり変わらないと思うんですが。
case 'B'
when /A/
...
when /B/
...
when /C/
...
end
正規表現などは全然よく知らないんですが、こういうのは駄目でしょうか。
ベンチマーク結果:
user system total real
0.969000 0.000000 0.969000 ( 0.969000) # /A/, /B/, /C/
0.265000 0.000000 0.265000 ( 0.265000) # /(A)|(B)|(C)/
0.157000 0.000000 0.157000 ( 0.156000) # /A|B|C/
ベンチマークプログラム:
def test_data
open('sample.rb').read * 10
end
# いい加減な Ruby token
$pattens = [
#
[/__LINE__/, :__LINE__],
[/__FILE__/, :__FILE__],
[/BEGIN/, :BEGIN],
[/END/, :END],
[/alias/, :alias],
[/and/, :and],
[/begin/, :begin],
[/break/, :break],
[/case/, :case],
[/class/, :class],
[/def/, :def],
[/defined?/, :defined?],
[/do/, :do],
[/else/, :else],
[/elsif/, :elsif],
[/end/, :end],
[/ensure/, :ensure],
[/false/, :false],
[/for/, :for],
[/if/, :if],
[/in/, :in],
[/module/, :module],
[/next/, :next],
[/nil/, :nil],
[/not/, :not],
[/or/, :or],
[/redo/, :redo],
[/rescue/, :rescue],
[/retry/, :retry],
[/return/, :return],
[/self/, :self],
[/super/, :super],
[/then/, :then],
[/true/, :true],
[/undef/, :undef],
[/unless/, :unless],
[/until/, :until],
[/when/, :when],
[/while/, :while],
[/yield/, :yield],
[/[\+\-\*\/\<\>]/, :_operator],
[/\{/, :_openbrace],
[/\}/, :_closebrace],
[/\(/, :_openparen],
[/\)/, :_closeparen],
[/\[/, :_openbracket],
[/\]/, :_closebracket],
[/\|/, :_bar],
[/\./, :_dot],
[/\,/, :_comma],
[/\===/, :_eqq],
[/\==/, :_eq],
[/\=/, :_asign],
[/::/, :_colon2],
[/:/, :_colon],
[/\&/, :_ampersand],
[/\?/, :_question],
[/\!\=/, :_neq],
[/\!/, :_not],
[/\s+/, :_space],
[/\#.*$/, :_comment],
[/".*"/, :_quotedstring],
[/'.*'/, :_singlequotedstring],
[/\d+\.\d+/, :_floating],
[/\d+/, :_integer],
[/\$[\!\?\"]+/, :_global_id_special],
[/\$[a-zA-z_]+/, :_global_id],
[/\:[a-zA-z_]+/, :_symbol],
[/\@[a-zA-z_]+/, :_attribute],
[/[A-Z][a-zA-z_]+/, :_constant],
[/[a-zA-z_]+/, :id],
]
$pattens = $pattens.map{|pat|
[/\A#{pat[0]}/, pat[1]]
}
$pattens_only = $pattens.map{|pat| pat[0]}
$pattens_total =
Regexp.compile($pattens.map{|pat| /(#{pat[0]})/}.join('|'))
$pattens_total2 =
Regexp.compile($pattens.map{|pat| pat[0]}.join('|'))
$token_types = $pattens.map{|pat| pat[1]}
def tokenize1 str
tokens = []
while str.size > 0
case $pattens_only.each{|patten|
if patten =~ str
type = :token # patten[1]
token = [type, $~[0]]
tokens << token
str = $~.post_match
break :next
end
}
when :next
when :break
break
else
raise "unknown: #{str}"
end
end
tokens
end
def tokenize2 str
patterns = $pattens_total
tokens = []
while str.size > 0
if patterns =~ str
type = :token
tokens << [type, $~[0]]
str = $~.post_match
else
end
end
tokens
end
def tokenize3 str
patterns = $pattens_total2
tokens = []
while str.size > 0
if patterns =~ str
type = :token
tokens << [type, $~[0]]
str = $~.post_match
else
end
end
tokens
end
if false # ||true # test
t1 = tokenize1(test_data)
t2 = tokenize2(test_data)
unless t1 == t2
p t1, t2
end
else
require 'benchmark'
include Benchmark
bm{|x|
x.report{
tokenize1(test_data)
}
x.report{
tokenize2(test_data)
}
x.report{
tokenize3(test_data)
}
}
end