diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-27 05:43:40 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-27 05:43:40 +0000 |
commit | e1e25923240975bedc8b087736d39105fc6f91a1 (patch) | |
tree | 961141b42e33c7b7e22a48afaf3d0bec029372ce | |
parent | 48943ec3ae3ad53e7dd2fc88a5faef5352658c4f (diff) | |
download | ruby-e1e25923240975bedc8b087736d39105fc6f91a1.tar.gz |
*** empty log message ***
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@95 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | hash.c | 23 | ||||
-rw-r--r-- | lib/finalize.rb | 2 | ||||
-rw-r--r-- | lib/thread.rb | 13 | ||||
-rw-r--r-- | sample/rbc.rb | 125 | ||||
-rw-r--r-- | sample/ruby-mode.el | 2 |
6 files changed, 107 insertions, 67 deletions
@@ -1,3 +1,12 @@ +Thu Feb 26 17:22:13 1998 Yukihiro Matsumoto <matz@netlab.co.jp> + + * parse.y (fname): convert reswords into symbols. + + * parse.y (reswords): reserved words are now embedded in the + syntax (sigh). + + * parse.y: now reserved words can be method names safely. + Wed Feb 25 15:50:07 1998 Yukihiro Matsumoto <matz@netlab.co.jp> * eval.c (mod_module_eval): clear the_scope's PRIVATE flag before @@ -21,10 +21,8 @@ char *strchr(); #endif -#define HASH_DELETED 0x1 -#define HASH_REHASHED 0x2 - #define HASH_FREEZE FL_USER1 +#define HASH_DELETED FL_USER2 static void hash_modify(hash) @@ -131,10 +129,14 @@ hash_foreach_iter(key, value, arg) struct hash_foreach_arg *arg; { int status; + st_table *tbl = RHASH(arg->hash)->tbl; + st_table_entry **bins = tbl->bins; if (key == Qnil) return ST_CONTINUE; status = (*arg->func)(key, value, arg->arg); - if (RHASH(arg->hash)->status & HASH_REHASHED) return ST_STOP; + if (RHASH(arg->hash)->tbl != tbl || RHASH(arg->hash)->tbl->bins != bins){ + IndexError("rehash occurred during iteration"); + } return status; } @@ -150,7 +152,7 @@ static int hash_delete_nil(key, value) VALUE key, value; { - if (key == Qnil) return ST_DELETE; + if (value == Qnil) return ST_DELETE; return ST_CONTINUE; } @@ -161,10 +163,10 @@ hash_foreach_ensure(hash) RHASH(hash)->iter_lev--; if (RHASH(hash)->iter_lev == 0) { - if (RHASH(hash)->status & HASH_DELETED) { + if (FL_TEST(hash, HASH_DELETED)) { st_foreach(RHASH(hash)->tbl, hash_delete_nil, 0); + FL_UNSET(hash, HASH_DELETED); } - RHASH(hash)->status = 0; } } @@ -306,7 +308,6 @@ hash_rehash(hash) st_foreach(RHASH(hash)->tbl, hash_rehash_i, tbl); st_free_table(RHASH(hash)->tbl); RHASH(hash)->tbl = tbl; - if (RHASH(hash)->iter_lev > 0) RHASH(hash)->status |= HASH_REHASHED; return hash; } @@ -347,9 +348,11 @@ hash_delete(hash, key) VALUE val; hash_modify(hash); - if (RHASH(hash)->iter_lev > 0 - && st_delete_safe(RHASH(hash)->tbl, &key, &val, Qnil)) + if (RHASH(hash)->iter_lev > 0 && + st_delete_safe(RHASH(hash)->tbl, &key, &val, Qnil)) { + FL_SET(hash, HASH_DELETED); return val; + } else if (st_delete(RHASH(hash)->tbl, &key, &val)) return val; if (iterator_p()) rb_yield(key); diff --git a/lib/finalize.rb b/lib/finalize.rb index 1482e7ae20..e479cac563 100644 --- a/lib/finalize.rb +++ b/lib/finalize.rb @@ -170,7 +170,7 @@ module Finalizer # ObjectSpace#add_finalizerへの登録関数 def final_of(id) if assocs = Dependency.delete(id) - for dependant, method, *opt in assocs + for dependant, method, opt in assocs dependant.send(method, id, *opt) end end diff --git a/lib/thread.rb b/lib/thread.rb index c33333f5f3..91c588f603 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -50,14 +50,11 @@ class Mutex def unlock return unless @locked - Thread.critical = true - wait = @waiting - @waiting = [] - @locked = false - Thread.critical = false - for w in wait - w.run - end + Thread.critical = TRUE + t = @waiting.shift + @locked = FALSE + Thread.critical = FALSE + t.run if t self end diff --git a/sample/rbc.rb b/sample/rbc.rb index 69f75269d8..e09dae6069 100644 --- a/sample/rbc.rb +++ b/sample/rbc.rb @@ -1,9 +1,9 @@ #!/usr/local/bin/ruby # # rbc.rb - -# $Release Version: 0.7 $ -# $Revision: 1.4 $ -# $Date: 1998/02/23 03:56:16 $ +# $Release Version: 0.8 $ +# $Revision: 1.7 $ +# $Date: 1998/02/27 03:45:51 $ # by Keiju ISHITSUKA(Nippon Rational Inc.) # # -- @@ -33,7 +33,7 @@ require "e2mmap.rb" $stdout.sync = TRUE module BC_APPLICATION__ - RCS_ID='-$Id: rbc.rb,v 1.4 1998/02/23 03:56:16 keiju Exp keiju $-' + RCS_ID='-$Id: rbc.rb,v 1.7 1998/02/27 03:45:51 keiju Exp keiju $-' extend Exception2MessageMapper def_exception :UnrecognizedSwitch, "Unrecognized switch: %s" @@ -202,7 +202,7 @@ module BC_APPLICATION__ "<" => ">", "(" => ")" } - + def lex_init() @OP = Trie.new @OP.def_rules("\0", "\004", "\032"){} @@ -225,9 +225,9 @@ module BC_APPLICATION__ end @OP.def_rules("*", "*=", "**=", "**") {@lex_state = EXPR_BEG} @OP.def_rules("!", "!=", "!~") {@lex_state = EXPR_BEG} - @OP.def_rules("=", "==", "===", "=~", "=>") {@lex_state = EXPR_BEG} - @OP.def_rules("<", "<=", "<=>", "<<", "<=") {@lex_state = EXPR_BEG} - @OP.def_rules(">", ">=", ">>", ">=") {@lex_state = EXPR_BEG} + @OP.def_rules("=", "==", "===", "=~", "<=>") {@lex_state = EXPR_BEG} + @OP.def_rules("<", "<=", "<<") {@lex_state = EXPR_BEG} + @OP.def_rules(">", ">=", ">>") {@lex_state = EXPR_BEG} @OP.def_rules("'", '"') do |op, rests| @ltype = op @@ -273,10 +273,14 @@ module BC_APPLICATION__ if rests[0] =~ /[0-9]/ rests.unshift op identify_number(rests) + else + # obj.if などの対応 + identify_identifier(rests, TRUE) + @lex_state = EXPR_ARG end end @OP.def_rules("..", "...") {@lex_state = EXPR_BEG} - + lex_int2 end @@ -285,8 +289,12 @@ module BC_APPLICATION__ @lex_state = EXPR_END @indent -= 1 end - @OP.def_rule(":") {} - @OP.def_rule("::") {@lex_state = EXPR_BEG} + @OP.def_rule(":") {|op,rests| + identify_identifier(rests, TRUE) + } + @OP.def_rule("::") {|op,rests| + identify_identifier(rests, TRUE); + } @OP.def_rule("/") do |op, rests| if @lex_state == EXPR_BEG || @lex_state == EXPR_MID @@ -348,16 +356,26 @@ module BC_APPLICATION__ identify_identifier(rests) end end + @OP.def_rule("def", proc{|op, chrs| /\s/ =~ chrs[0]}) do + |op, rests| + @indent += 1 + @lex_state = EXPR_END + until rests[0] == "\n" or rests[0] == ";" + rests.shift + end + end @OP.def_rule("") do |op, rests| - printf "match: start %s: %s", op, rests.inspect if CONFIG[:DEBUG] + printf "MATCH: start %s: %s\n", op, rests.inspect if CONFIG[:DEBUG] if rests[0] =~ /[0-9]/ identify_number(rests) elsif rests[0] =~ /[\w_]/ identify_identifier(rests) end - printf "match: end %s: %s", op, rests.inspect if CONFIG[:DEBUG] + printf "MATCH: end %s: %s\n", op, rests.inspect if CONFIG[:DEBUG] end + + p @OP if CONFIG[:DEBUG] end def lex(l) @@ -426,9 +444,9 @@ module BC_APPLICATION__ end end - def identify_identifier(chrs) + def identify_identifier(chrs, escaped = FALSE) token = "" - token.concat chrs.shift if chrs[0] =~ /[$@]/ + token.concat chrs.shift if chrs[0] =~ /[$@]/ or escaped while (ch = chrs.shift) =~ /\w|_/ print ":", ch, ":" if CONFIG[:DEBUG] token.concat ch @@ -441,7 +459,7 @@ module BC_APPLICATION__ end # fix token - if token =~ /^[$@]/ + if token =~ /^[$@]/ or escaped @lex_state = EXPR_END return end @@ -629,14 +647,9 @@ module BC_APPLICATION__ @preproc = preproc @postproc = postproc end - - def preproc(p) - @preproc = p - end - - def postproc(p) - @postproc = p - end + + attr :preproc, TRUE + attr :postproc, TRUE def search(chrs, opt = nil) return self if chrs.empty? @@ -654,10 +667,29 @@ module BC_APPLICATION__ end def create_subnode(chrs, preproc = nil, postproc = nil) + if chrs.empty? + if @postproc + p node + Trie.fail ErrNodeAlreadyExists + else + print "Warn: change abstruct node to real node\n" if CONFIG[:DEBUG] + @preproc = preproc + @postproc = postproc + end + return self + end + ch = chrs.shift if node = @Tree[ch] if chrs.empty? - Trie.fail ErrNodeAlreadyExists + if node.postproc + p node + Trie.fail ErrNodeAlreadyExists + else + print "Warn: change abstruct node to real node\n" if CONFIG[:DEBUG] + node.preproc = preproc + node.postproc = postproc + end else node.create_subnode(chrs, preproc, postproc) end @@ -674,7 +706,7 @@ module BC_APPLICATION__ end def match(chrs, op = "") - print "match: ", chrs, ":", op, "\n" if CONFIG[:DEBUG] + print "match>: ", chrs, "op:", op, "\n" if CONFIG[:DEBUG] if chrs.empty? if @preproc.nil? || @preproc.call(op, chrs) printf "op1: %s\n", op if CONFIG[:DEBUG] @@ -688,23 +720,23 @@ module BC_APPLICATION__ if node = @Tree[ch] if ret = node.match(chrs, op+ch) return ch+ret - elsif @postproc and @preproc.nil? || @preproc.call(op, chrs) - chrs.unshift ch - printf "op2: %s\n", op if CONFIG[:DEBUG] - @postproc.call(op, chrs) - return "" else chrs.unshift ch - return nil + if @postproc and @preproc.nil? || @preproc.call(op, chrs) + printf "op2: %s\n", op.inspect if CONFIG[:DEBUG] + @postproc.call(op, chrs) + return "" + else + return nil + end end else + chrs.unshift ch if @postproc and @preproc.nil? || @preproc.call(op, chrs) printf "op3: %s\n", op if CONFIG[:DEBUG] - chrs.unshift ch @postproc.call(op, chrs) return "" else - chrs.unshift ch return nil end end @@ -717,14 +749,9 @@ module BC_APPLICATION__ end def def_rule(token, preproc = nil, postproc = nil) - node = search(token, :CREATE) # print node.inspect, "\n" if CONFIG[:DEBUG] - node.preproc(preproc) - if iterator? - node.postproc(proc) - elsif postproc - node.postproc(postproc) - end + postproc = proc if iterator? + node = create(token, preproc, postproc) end def def_rules(*tokens) @@ -736,18 +763,22 @@ module BC_APPLICATION__ end end - def preporc(token) + def preporc(token, proc) node = search(token) - node.preproc proc + node.preproc=proc end def postproc(token) - node = search(token) - node.postproc proc + node = search(token, proc) + node.postproc=proc end - def search(token, opt = nil) - @head.search(token.split(//), opt) + def search(token) + @head.search(token.split(//)) + end + + def create(token, preproc = nil, postproc = nil) + @head.create_subnode(token.split(//), preproc, postproc) end def match(token) diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el index 69d163329e..0d94df0fc8 100644 --- a/sample/ruby-mode.el +++ b/sample/ruby-mode.el @@ -600,7 +600,7 @@ An end of a defun is found by moving forward from the beginning of one." (defvar ruby-font-lock-keywords (list (cons (concat - "\\(^\\|[^_]\\)\\b\\(" + "\\(^\\|[^_:.]\\|\\.\\.\\)\\b\\(" (mapconcat 'identity '("alias" |