diff options
author | Yukihiro Matsumoto <[email protected]> | 1994-10-13 12:13:48 +0900 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2019-08-17 22:09:30 +0900 |
commit | eed5c920dd5429bac6075e9bc98d82360392b424 (patch) | |
tree | 825427093bc27339080dbbcaebc1563703bae357 /sample | |
parent | 6e3090413652b6592346556149fed1e9aec5495d (diff) |
version 0.51v0_51
https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.51.tar.gz
Thu Oct 13 12:13:48 1994 Yukihiro Matsumoto (matz@ix-02)
* eval.c(SETUP_ARGS): 付加演算子が配列でない時には配列に変換する.
* parse.y: 括弧なしのメソッド呼び出しでも`*'による付加引数が使える
ようにした. ただし, 通常引数が一つもない場合は乗算演算子と区別が
つかないので, 必ず括弧が必要.
Wed Oct 12 10:09:07 1994 Yukihiro Matsumoto (matz@ix-02)
* eval.c(rb_call): キャッシュの計算をinline化. キャッシュミスがあ
れば関数呼び出しでメソッドを検索する. methods.cはなくなった.
* eval.c(rb_eval): ローカル変数用の領域をalloca()するように変更.
サイズの変更が必要になれば改めてmalloc()するように.
* parse.y: error recoveryの際にlex_stateを更新しておくように.
Tue Oct 11 17:10:46 1994 Yukihiro Matsumoto (matz@ix-02)
* socket.c(for_fd): ファイル記述子(Fixnum)からソケットインスタンス
を得るメソッド. たとえばinetdから起動されたサーバで標準入出力に
ソケット操作を行なうために使う. つまりSocket.for_fd($stdin)で標
準入力に対応するソケットオブジェクトが得られる.
* io.c(to_i): IOクラスのインスタンスを整数に変換するとそのファイル
記述子を返すように.
* numeric.c(num2int): to_iメソッドを使って, できる限り整数に変換す
る. 以前はnum2fixだけが全てのオブジェクトに対してto_iメソッドを
適用していた.
* sprintf.c(Fsprintf): 整数表示の際, オブジェクトをできる限り整数
に変換するように(to_iメソッドを使う).
Fri Oct 7 14:06:32 1994 Yukihiro Matsumoto (matz@ix-02)
* eval.c(Fcaller): 必要性がよく分からないのでドキュメントから削除.
将来デバッガを作る時に復活させよう.
* eval.c(rb_call): Cで記述されたメソッド呼び出しでは環境をスタック
にセーブしないことによって高速化.
Wed Oct 5 15:00:58 1994 Yukihiro Matsumoto (matz@ix-02)
* ruby.h: 一時env.hに移動してたQselfの定義を復活. ただし今回は関数
として実現(env.hでは変数として再定義してある).
* ruby.h: TRUEでsyntax errorにならないよう#undefを追加.
* eval.c(rb_eval): thread化に挑戦したが, 失敗(速くならなかった).
が, Scopingなどの無駄なコードの削除とメソッド呼び出しの引数セッ
トのinline化で若干の高速化を実現した. 副作用として, argc, argv形
式の関数呼び出しの仕様が変化した(argvにselfを含まなくなった).
* eval.c(rb_call): メソッド呼び出しの高速化.
Tue Oct 4 11:40:53 1994 Yukihiro Matsumoto (matz@ix-02)
* ruby-mode.el: 修飾子に対応した.
* parse.y: 多重代入にrestをつけた. この機能を使えばoptional引数の
解析が簡単にできる(はず).
* pack.c(unpack): uuencode形式のdecodeの際に文字列の長さが間違って
いた.
Mon Oct 3 15:58:41 1994 Yukihiro Matsumoto (matz@ix-02)
* file.c(type): ファイルタイプを文字列で返すメソッド.
Fri Sep 30 11:36:07 1994 Yukihiro Matsumoto (matz@ix-02)
* object.c: デフォルトの真の値である%TRUEの値を1(Fixnum)からtに変
更した. to_sで文字列に変換した時にも`t'と表示される. 更に踏み込
んで`t'を予約語にしてlispのようにしようかとも思ったが, そこまで
は決心できなかった. 一文字のローカル変数はかなり使いそうな気がす
るので….
* array.c,dict.c: equalを再定義しているクラスで, hashを正しく定義
した.
Wed Sep 28 23:30:28 1994 Yukihiro Matsumoto (matz@dyna)
* eval.c(Ffail): 今までfailはカーネルクラスのメソッドであったが,
構文に組み込んだ. この変更によって, 1)`fail'は予約語となり, ロー
カル変数に用いることができなくなった. 2)`fail'単体で例外を発生す
るようになった. 3)failはメソッドではなくなったので再定義される可
能性がなくなった.
* dic.c, dbm.c(indexes): Arrayのindexesと同様の機能を持つメソッド
を追加.
* array.c(indexes): 引数をインデックスとする要素の配列を返す. 整数
の配列を引数とする時には引数の要素をインデックスとする要素の配列
を返す.
Mon Sep 19 13:42:31 1994 Yukihiro Matsumoto (matz@ix-02)
* array.c(aset): 部分配列に対する代入で配列以外のオブジェクトが指
定された場合に多重代入と同じルールで配列化するようにした.
* io.c(print): 引数として与えられた各オブジェクトにprint_onメッセー
ジを与えるように. 実行速度は落ちるが柔軟性は増す.
Fri Sep 16 14:59:18 1994 Yukihiro Matsumoto (matz@ix-02)
* glob.c: ワイルドカードの導入. bashに使われているGNUのglobルーチ
ンを流用した.
Mon Sep 12 18:36:58 1994 Yukihiro Matsumoto (matz@ix-02)
* parse.y(value_expr): 式がnilの時に対応.
* class.c: ICLASSのclassが必ずClass/Moduleを指すように.
Tue Sep 6 16:23:28 1994 Yukihiro Matsumoto (matz@ix-02)
* re.c: 正規表現内で「\数字」形式が指定できるように.
* parse.y:「do expr using var ... end」形式はなくなった. 寂しい気
もする. *BACKWARD INCOMPATIBILITY*
Mon Sep 5 10:59:01 1994 Yukihiro Matsumoto (matz@ix-02)
* numeric.c(next): Numericクラスにもnextを提供.
* string.c(upto): uptoを提供.
* range.c(each): nextを使ったインタフェースからuptoを使うように変
更した. この方が一つのメソッドで処理をまとめで行なうことができる.
Fri Sep 2 15:25:39 1994 Yukihiro Matsumoto (matz@ix-02)
* dict.c(each): 戻り値を[key, value]のペアに変更. 今までのeachは
each_valueとして残る. *BACKWARD INCOMPATIBILITY*
Thu Sep 1 10:49:04 1994 Yukihiro Matsumoto (matz@ix-02)
* 成功した(特別な戻り値を持たない)システムコールは`0'を返すように.
Wed Aug 31 00:26:51 1994 Yukihiro Matsumoto (matz@dyna)
* string.c: チェックサムを得るメソッド`sum'を作った.
* class.c(include_class_new): ICLASSのclassをもとのクラスにした.
gcの際に元クラスをマークする必要があるのが, フィールドを増やす余
地が無いので, classフィールドを流用した. 私の見積りが間違ってい
て, ICLASSのインスタンスにメッセージを送る事があれば, おかしな動
作をするだろう.
* eval.c(masign): 式(a,b = nil)の値を[nil]からnilに変更した.
Mon Aug 29 11:56:09 1994 Yukihiro Matsumoto (matz@ix-02)
* class.c: rb_define_mfuncを無くして, メタクラスにモジュールをイン
クルードするようにした.
* error.c(yyerror): 同じ行で複数のsyntax errorをリポートしないよう
にした.
* file.c: FileTestモジュールにファイルテストメソッドを分離した.
* parse.y: 演算子を指定する時のlex_stateを正しく設定した.
Sat Aug 27 01:23:34 1994 Yukihiro Matsumoto (matz@dyna)
* parse.y: if/whileなどの複合式をprimaryに移動した. これによって例
えば「if cond then a else b end.message()」のような式が書けるよ
うになった.
Fri Aug 26 10:46:30 1994 Yukihiro Matsumoto (matz@ix-02)
* spec: 整理された文法にしたがって書き直した.
* parse.y: ここ数日で混乱していた文法を整理した. 括弧を省略したメ
ソッド呼び出しができるようになったこと, modifierが付けられるよう
になったこと, returnにリストが渡せるようになったことが主な変更点
である.
* process周りが怪しいがとにかくSolaris 2.3で動くように.
* parse.y: 曖昧性がない場合にはメソッド呼び出しの引数の括弧を省略
できるように. 省略できるメソッド呼び出しの条件は, 1)かならず1個
以上の引数を必要とすること, 2)第1引数が`+', `-', `(', `[', `{',
`/'など, 式の始まりに置かれた時と途中に現れた時とで解釈が違う記
号で始まらないこと, である.
Thu Aug 25 13:54:58 1994 Yukihiro Matsumoto (matz@ix-02)
* parse.y(cond): 条件式の展開部にbugがあった.
Wed Aug 24 00:01:15 1994 Yukihiro Matsumoto (matz@dyna)
* parse.y: returnはコンマで区切ったリストも受け取るように. つまり,
return a, b, cはreturn [a, b, c]と同じ意味になる.
* parse.y: yield以外の大域脱出制御式をexprからexpr0に移した. よっ
てメソッドの引数に制御式を使えなくなる(これで困る人はいないはず).
* parse.y: `+'の定数展開の際に演算子の優先順位を忘れていた.
* eval.c: untilの戻り値はnilになった.
* parse.y: modifierとしてのif/unless/while/untilを追加.
* parse.y: 文法からendの後ろにつけるキーワードを削除. ほとんど使わ
なかった上に, emacsではruby-modeがあれば対応のチェックが機械的に
出来るため.
Tue Aug 23 18:08:33 1994 Yukihiro Matsumoto (matz@ix-02)
* eval.c: スクリプト実行開始前に例外が発生した時にcore dumpした.
組み込み用にコードを変更した時にenbugしてしまった.
Tue Aug 23 00:07:17 1994 Yukihiro Matsumoto (matz@dyna)
* eval.c: doの戻り値がいつもnilになっていた.
* parse.y: loop制御変数の多重代入化にbugがあった.
* parse.y(expand_op): 文字列も畳み込みの対象に.
Mon Aug 22 10:50:01 1994 Yukihiro Matsumoto (matz@ix-02)
* parse.y(expand_op): `+'に関しては結合則を使って, より多く定数畳
み込みを行なうように.
* ruby.c(proc_options): argcが0の時にも対応.
* parse.y: forなどの制御変数に多重代入も使えるように.
Sat Aug 20 00:59:40 1994 Yukihiro Matsumoto (matz@dyna)
* parse.y(call_op): 演算子`~'の取り扱いをルール部へ移動.
Fri Aug 19 11:44:13 1994 Yukihiro Matsumoto (matz@ix-02)
* main.c: rubyをほかのプログラムに組み込めるようにmain()を分割した.
それにともない, プログラムの呼び出し構造を修正した.
* parse.y: 条件式の定義を変更. ifなどの条件式の中でだけ`&&'や`||'
および`!'の引数が条件式になるように. この変更により条件式以外の
場所での `&&', `||', `!'演算子の動作が直観に一致する.
* parse.y: 実引数の`*'の後に続く引数はexprに制限した. 今までは全て
の文が有効であったが, ここで定義文があってもしょうがない.
Thu Aug 18 10:21:45 1994 Yukihiro Matsumoto (matz@ix-02)
* re.c: 正規表現ルーチンの初期化部分を削除してしまっていた. これで
はemacsの正規表現になってしまう.
* version.c: copyright表示を追加.
* version.c: バージョン表示をstderrに.
* configure.in: gccがない場合testに失敗していた.
Fri Aug 12 14:12:23 1994 Yukihiro Matsumoto (matz@ix-02)
* array.c(astore): 配列の拡大する時にある程度の大きさをまとめて拡
大するように.
* io.c(Fprint): 配列に対しては一度文字列に変換することなく, 直接内
容を出力するように.
* string.c(str_new): memmoveからmemcpyへ置き換えた. これでもかなり
速度が違う.
* ruby.h: データメンバの取り出しで名前を文字列からIDで指定するよう
にした. かなりの高速化になる.
* io.c: $ARGFという変数で引数列からなる仮想ファイルをオブジェクト
として扱えるようにした. 今まではトップレベルのgets()などを使って
アクセスしていたが, どうもオブジェクト指向的ではなかった.
Thu Aug 11 11:43:15 1994 Yukihiro Matsumoto (matz@ix-02)
* gc.c: mark_location()の間違った呼び出し方の行が残っていた.
* method.c: プロトタイプ宣言が足りなかった.
Diffstat (limited to 'sample')
-rw-r--r-- | sample/biorhythm.rb | 4 | ||||
-rw-r--r-- | sample/cat2.rb | 4 | ||||
-rw-r--r-- | sample/getopts.rb | 2 | ||||
-rw-r--r-- | sample/io.rb | 2 | ||||
-rw-r--r-- | sample/newver.rb | 13 | ||||
-rw-r--r-- | sample/rcs.rb | 10 | ||||
-rw-r--r-- | sample/ruby-mode.el | 139 | ||||
-rw-r--r-- | sample/sieve.rb | 16 | ||||
-rw-r--r-- | sample/t2.rb | 7 | ||||
-rw-r--r-- | sample/trojan.rb | 12 | ||||
-rw-r--r-- | sample/tt.rb | 19 |
11 files changed, 151 insertions, 77 deletions
diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb index 3261c4377f..eb14ca7365 100644 --- a/sample/biorhythm.rb +++ b/sample/biorhythm.rb @@ -41,7 +41,7 @@ def leapyear(y) return ta end -def bcalc(t, m, j) +def bcalc(tt, m, j) ta = 0 if (m <= 2) ta = (m - 1) * 31 @@ -51,7 +51,7 @@ def bcalc(t, m, j) end ta = ta + (j - 1) * 365 + ((j - 1) / 4.0).to_i ta = ta - ((j - 1) / 100) + ((j - 1) / 400.0).to_i - ta = ta + t + ta = ta + tt return ta end diff --git a/sample/cat2.rb b/sample/cat2.rb new file mode 100644 index 0000000000..f979dc53cb --- /dev/null +++ b/sample/cat2.rb @@ -0,0 +1,4 @@ +while gets() + if 1 ... /^\*/; print("--") end + printf("%5d: %s", $., $_) +end diff --git a/sample/getopts.rb b/sample/getopts.rb index 57a7db424f..01eddcea98 100644 --- a/sample/getopts.rb +++ b/sample/getopts.rb @@ -55,7 +55,7 @@ def getopts(single_opts, *opts) while ($ARGV.length != 0) compare = nil case $ARGV[0] - when /^-*$/ + when /^--?$/ $ARGV.shift break when /^--.*/ diff --git a/sample/io.rb b/sample/io.rb index 45d50d653a..b5591af7e4 100644 --- a/sample/io.rb +++ b/sample/io.rb @@ -13,7 +13,7 @@ end printf("%s:(%d)%s\n", $0, $ARGV.length, $ARGV[0]) passwd = open($ARGV[0], "r") -#printf("%s", do passwd.find using i; i =~ /\*/ end) +#printf("%s", passwd.find{i|i =~ /\*/}) n = 1 for i in passwd #.grep(/^\*/) diff --git a/sample/newver.rb b/sample/newver.rb new file mode 100644 index 0000000000..bbf03aebc2 --- /dev/null +++ b/sample/newver.rb @@ -0,0 +1,13 @@ +#! /usr/local/bin/ruby + +f = open("version.h", "r") +f.gets() +f.close + +if $_ =~ /"(\d)\.(\d+)"/; + f = open("version.h", "w") + i = $2.to_i + 1 + printf("ruby version %d.%0d\n", $1, i) + printf(f, "#define RUBY_VERSION \"%d.%0d\"\n", $1, i) + f.close +end diff --git a/sample/rcs.rb b/sample/rcs.rb index 6d7f10c6bc..0ed4a36c1e 100644 --- a/sample/rcs.rb +++ b/sample/rcs.rb @@ -14,12 +14,16 @@ while gets() while xr < hdw x = xr * (1 + y) - y * w / 2 i = (x / (1 + h) + sw /2) - c = if (1 < i && i < $_.length); $_[i, 1].to_i else 0 end + if (1 < i && i < $_.length); + c = $_[i, 1].to_i + else + c = 0 + end y = h - d * c xl = xr - w * y / (1 + y); if xl < -hdw || xl >= hdw || xl <= maxxl - t = rand(ss.length) - c = ss[t, 1] + tt = rand(ss.length) + c = ss[tt, 1] else c = s[xl + hdw, 1] maxxl = xl diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el index 96915bdc5a..8f864d3846 100644 --- a/sample/ruby-mode.el +++ b/sample/ruby-mode.el @@ -8,22 +8,23 @@ ;;; (defconst ruby-block-beg-re - "class\\|module\\|def\\|if\\|case\\|while\\|do\\|for\\|protect" + "class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|protect" ) (defconst ruby-block-mid-re - "else\\|elsif\\|when\\|using\\|resque\\|ensure" + "else\\|elsif\\|when\\|resque\\|ensure" ) -(defconst ruby-block-end-re - (concat "\\(end\\([ \t]+\\(" ruby-block-beg-re "\\)\\)?\\)") - ) +(defconst ruby-block-end-re "end") (defconst ruby-delimiter - (concat "(\\|)\\|\\{\\|\\}\\|\"\\|\'\\|\\b\\(" ruby-block-beg-re "\\|" ruby-block-end-re "\\)\\b\\|#") + (concat "[/<(){}#\"'`]\\|\\[\\|\\]\\|\\b\\(" + ruby-block-beg-re "\\|" ruby-block-end-re "\\)\\b") ) + (defconst ruby-negative - (concat "^[ \t]*\\b\\(\\(" ruby-block-mid-re "\\)\\|\\(" ruby-block-end-re "\\)\\)\\b") + (concat "^[ \t]*\\(\\b\\(" ruby-block-mid-re "\\)\\|\\(" + ruby-block-end-re "\\)\\b\\|\\}\\|\\]\\)") ) (defvar ruby-mode-abbrev-table nil @@ -51,9 +52,10 @@ (setq ruby-mode-syntax-table (make-syntax-table)) (modify-syntax-entry ?\' "\"" ruby-mode-syntax-table) (modify-syntax-entry ?\" "\"" ruby-mode-syntax-table) - (modify-syntax-entry ?\n "> " ruby-mode-syntax-table) - (modify-syntax-entry ?\f "> " ruby-mode-syntax-table) - (modify-syntax-entry ?# "< " ruby-mode-syntax-table) +;;(modify-syntax-entry ?\n ">" ruby-mode-syntax-table) +;;(modify-syntax-entry ?\f ">" ruby-mode-syntax-table) + (modify-syntax-entry ?# "<" ruby-mode-syntax-table) + (modify-syntax-entry ?\\ "'" ruby-mode-syntax-table) (modify-syntax-entry ?_ "w" ruby-mode-syntax-table) (modify-syntax-entry ?< "." ruby-mode-syntax-table) (modify-syntax-entry ?> "." ruby-mode-syntax-table) @@ -68,9 +70,9 @@ (modify-syntax-entry ?- "." ruby-mode-syntax-table) (modify-syntax-entry ?\; "." ruby-mode-syntax-table) (modify-syntax-entry ?\( "()" ruby-mode-syntax-table) - (modify-syntax-entry ?) ")(" ruby-mode-syntax-table) - (modify-syntax-entry ?{ "(}" ruby-mode-syntax-table) - (modify-syntax-entry ?} "){" ruby-mode-syntax-table) + (modify-syntax-entry ?\) ")(" ruby-mode-syntax-table) + (modify-syntax-entry ?\{ "(}" ruby-mode-syntax-table) + (modify-syntax-entry ?\} "){" ruby-mode-syntax-table) (modify-syntax-entry ?\[ "(]" ruby-mode-syntax-table) (modify-syntax-entry ?\] ")[" ruby-mode-syntax-table) ) @@ -78,23 +80,6 @@ (defvar ruby-indent-level 2 "*Indentation of ruby statements.") -(defun ruby-mode-variables () - (setq local-abbrev-table ruby-mode-abbrev-table) - (make-local-variable 'indent-line-function) - (setq indent-line-function 'ruby-indent-line) - (make-local-variable 'require-final-newline) - (setq require-final-newline t) - (make-variable-buffer-local 'comment-start) - (setq comment-start "# ") - (make-variable-buffer-local 'comment-end) - (setq comment-end "") - (make-variable-buffer-local 'comment-column) - (setq comment-column 32) - (make-variable-buffer-local 'comment-start-skip) - (setq comment-start-skip "#+ *") - (make-local-variable 'parse-sexp-ignore-comments) - (setq parse-sexp-ignore-comments t)) - (defun ruby-mode () "Major mode for editing ruby scripts. \\[ruby-indent-command] properly indents subexpressions of multi-line @@ -109,7 +94,21 @@ The variable ruby-indent-level controls the amount of indentation. (setq mode-name "ruby") (setq major-mode 'ruby-mode) (set-syntax-table ruby-mode-syntax-table) - (ruby-mode-variables) + (setq local-abbrev-table ruby-mode-abbrev-table) + (make-local-variable 'indent-line-function) + (setq indent-line-function 'ruby-indent-line) + (make-local-variable 'require-final-newline) + (setq require-final-newline t) + (make-variable-buffer-local 'comment-start) + (setq comment-start "# ") + (make-variable-buffer-local 'comment-end) + (setq comment-end "") + (make-variable-buffer-local 'comment-column) + (setq comment-column 32) + (make-variable-buffer-local 'comment-start-skip) + (setq comment-start-skip "#+ *") + (make-local-variable 'parse-sexp-ignore-comments) + (setq parse-sexp-ignore-comments t) (run-hooks 'ruby-mode-hook)) (defun ruby-current-indentation () @@ -131,10 +130,8 @@ The variable ruby-indent-level controls the amount of indentation. (defun ruby-indent-line (&optional flag) "Correct indentation of the current ruby line." - (let - ((x (ruby-calculate-indent))) - (ruby-indent-to x))) - + (ruby-indent-to (ruby-calculate-indent))) + (defun ruby-indent-command () (interactive) (ruby-indent-line t)) @@ -166,14 +163,36 @@ The variable ruby-indent-level controls the amount of indentation. (ruby-beginning-of-defun)) (while (and (> indent-point (point)) (re-search-forward ruby-delimiter indent-point t)) - (let ((w (buffer-substring (match-beginning 0) (match-end 0)))) + (let ((w (buffer-substring (match-beginning 0) (match-end 0))) + (pnt (match-beginning 0))) (cond ((or (string= "\"" w) ;skip string - (string= "\'" w)) + (string= "'" w) + (string= "`" w)) (if (search-forward w indent-point t) nil (goto-char indent-point) (setq in-string t))) + ((or (string= "/" w) + (string= "<" w)) + (if (string= "<" w) (setq w ">")) + (let (c) + (save-excursion + (goto-char pnt) + (skip-chars-backward " \t") + (setq c (char-after (1- (point)))) + (if c + (setq c (char-syntax c)))) + (cond + ((or (eq c ?.) + (and (eq c ?w) + (save-excursion + (forward-word -1) + (looking-at ruby-block-beg-re)))) + (if (search-forward w indent-point t) + nil + (goto-char indent-point) + (setq in-string t)))))) ((string= "#" w) ;skip comment (forward-line 1)) ((string= "(" w) ;skip to matching paren @@ -189,7 +208,21 @@ The variable ruby-indent-level controls the amount of indentation. (t (setq nest (cdr nest)) (setq depth (1- depth))))) - (if (> depth orig) (setq in-paren t)))) + (if (> depth orig) (setq in-paren ?\()))) + ((string= "[" w) ;skip to matching paren + (let ((orig depth)) + (setq nest (cons (point) nest)) + (setq depth (1+ depth)) + (while (and (/= depth orig) + (re-search-forward "\\[\\|\\]" indent-point t)) + (cond + ((= (char-after (match-beginning 0)) ?\[ ) + (setq nest (cons (point) nest)) + (setq depth (1+ depth))) + (t + (setq nest (cdr nest)) + (setq depth (1- depth))))) + (if (> depth orig) (setq in-paren ?\[)))) ((string= "{" w) ;skip to matching paren (let ((orig depth)) (setq nest (cons (point) nest)) @@ -197,22 +230,28 @@ The variable ruby-indent-level controls the amount of indentation. (while (and (/= depth orig) (re-search-forward "[{}]" indent-point t)) (cond - ((= (char-after (match-beginning 0)) ?\{ ) + ((= (char-after (match-beginning 0)) ?{ ) (setq nest (cons (point) nest)) (setq depth (1+ depth))) (t (setq nest (cdr nest)) (setq depth (1- depth))))) - (if (> depth orig) (setq in-paren t)))) - ((string-match "^end" w) + (if (> depth orig) (setq in-paren ?{)))) + ((string-match ruby-block-end-re w) (setq nest (cdr nest)) (setq depth (1- depth))) ((string-match ruby-block-beg-re w) - (setq nest (cons (point) nest)) - (setq depth (1+ depth))) + (let (c) + (save-excursion + (goto-char pnt) + (skip-chars-backward " \t") + (setq c (char-after (1- (point))))) + (if (or (null c) (= c ?\n) (= c ?\;)) + (progn + (setq nest (cons (point) nest)) + (setq depth (1+ depth)))))) (t (error (format "bad string %s" w))))))) - (if in-paren (message "in-paren")) (list in-string in-paren (car nest) depth))) (defun ruby-calculate-indent (&optional parse-start) @@ -224,7 +263,7 @@ The variable ruby-indent-level controls the amount of indentation. (indent 0)) (if parse-start (goto-char parse-start) - (beginning-of-defun) + (ruby-beginning-of-defun) (setq parse-start (point))) (setq state (ruby-parse-region parse-start indent-point)) (cond @@ -234,9 +273,9 @@ The variable ruby-indent-level controls the amount of indentation. ((nth 1 state) ; in paren (goto-char (nth 2 state)) (setq indent - (if (looking-at "$") - (+ (current-indentation) ruby-indent-level) - (current-column)))) + (if (and (eq (nth 1 state) ?\( ) (not (looking-at "$"))) + (current-column) + (+ (current-indentation) ruby-indent-level)))) ((> (nth 3 state) 0) ; in nest (goto-char (nth 2 state)) @@ -258,7 +297,7 @@ The variable ruby-indent-level controls the amount of indentation. With argument, do this that many times. Returns t unless search stops due to end of buffer." (interactive "p") - (and (re-search-backward (concat "^\\(" ruby-block-beg-re "\\)") + (and (re-search-backward (concat "^\\(" ruby-block-beg-re "\\)\\b") nil 'move (or arg 1)) (progn (beginning-of-line) t))) @@ -266,7 +305,7 @@ Returns t unless search stops due to end of buffer." "Move forward to next end of defun. An end of a defun is found by moving forward from the beginning of one." (interactive "p") - (and (re-search-forward (concat "^\\(" ruby-block-end-re "\\)") + (and (re-search-forward (concat "^\\(" ruby-block-end-re "\\)\\b") nil 'move (or arg 1)) (progn (beginning-of-line) t)) (forward-line 1)) diff --git a/sample/sieve.rb b/sample/sieve.rb new file mode 100644 index 0000000000..0228243fda --- /dev/null +++ b/sample/sieve.rb @@ -0,0 +1,16 @@ +sieve = [] +unless max = $ARGV.shift; max = 100; end +max = max.to_i + +print "1" +for i in 2 .. max + protect + for d in sieve + fail if i % d == 0 + end + print ", " + print i + sieve.push(i) + resque + end +end diff --git a/sample/t2.rb b/sample/t2.rb index 7f5b9df480..a34c171837 100644 --- a/sample/t2.rb +++ b/sample/t2.rb @@ -7,7 +7,7 @@ def println(*args) print(a) end print("\n") -end def +end def tt for i in 1..10 @@ -16,9 +16,8 @@ def tt end end -test = -do tt() using i +test = tt{i| if i == 3; break end println("ttt: ", i); -end +} #exit() diff --git a/sample/trojan.rb b/sample/trojan.rb index bd49d44357..b42fd166a8 100644 --- a/sample/trojan.rb +++ b/sample/trojan.rb @@ -2,11 +2,13 @@ path = $ENV['PATH'].split(/:/) for dir in path - for f in d = Dir.open(dir) - fpath = dir+"/"+f - if File.f(fpath) && (File.stat(fpath).mode & 022) != 0 - printf("file %s is writable from other users\n", fpath) + if File.d(dir) + for f in d = Dir.open(dir) + fpath = dir+"/"+f + if File.f(fpath) && (File.stat(fpath).mode & 022) != 0 + printf("file %s is writable from other users\n", fpath) + end end + d.close end - d.close end diff --git a/sample/tt.rb b/sample/tt.rb index cb863e3527..c53ec39d68 100644 --- a/sample/tt.rb +++ b/sample/tt.rb @@ -5,13 +5,13 @@ module Print print(a) end print("\n") - end def + end def println2(*args) print(*args) print("\n") - end def -end module + end +end module Print2 def println(*args) @@ -52,20 +52,20 @@ class Fib:Object if args; println(*args) end args = args.grep(/^c/) super(*args) - end def + end def init println("in Fib.init"); - end def + end def fib(n) a =0; b = 1 while b <= n c = a; a = b; b = c+b - end while + end return b - end def + end end def Object.test(*args) @@ -96,8 +96,5 @@ def tt end end -test = do tt() using i - if i == 2; break end -end - +test = tt() {i|break if i == 2} println([1,2,3,4].join(":")) |