Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
kouki-o-iij edited this page Mar 22, 2013 · 37 revisions

Regexp

TODO

  • Regexp#match の pos のサポート
  • named capture
  • String メソッドの実装
  • $~ の類のローカル変数化

やること

  1. Regexp Engines: 正規表現エンジンを比較する。バイナリサイズ、実行時サイズ、オブジェクトの生成に伴うメモリ消費の増加、速度。
  2. Regexp Specification: mruby Regexp 実装と CRuby / ISO Ruby との仕様の違いを調べる。メソッド数レベルの違いと、挙動の違い。
  3. テストファーストで実装する。

実装

Regexp クラス

Regexp:

 #new(string, option, code) -> Regexp : 保存しておく。
 .last_match : $~
 .last_match(n) : $&
 .try_convert : (いらない)
 .union : (いらない)
 #== : かんたんで後回し
 #hash : ...? てきとうにでっちあげれば良い?
 #inspect : なんとでもなるだろう
 #named_captures : REエンジンによっては書けるか? Posixでは無理。
 #names : Posix では無理
 #to_s : うーん...? 変化しないことの保証は厳しそう
 
 $& : Regexp.last_match[0] 実は「ローカルスコープ」。それ以外は難しくない。
 $'' : Regexp.last_match.post_match
 $+ : Regexp.last_match の最後のもの。
 $` : Regexp.last_match.pre_match
 $~ : Regexp.last_match

MatchData

リテラル

parse.y は "Regexp.compile(restr, optstr)" 相当のバイトコードにコンパイルする。optstr は常に付く。

実現すべき機能

  • 正規表現リテラル入り .rb の .mrb へのコンパイル

要検討事項

  • 1ドル... はいくつまでサポートするか?
  • pcre_malloc / pcre_free の置き換え

mrbgem 化

  • mruby 本家へ escape 処理の pull-req(Done)
  • regexp のテスト
  • mrbgem 化

テスト

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /