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 /sample | |
parent | 48943ec3ae3ad53e7dd2fc88a5faef5352658c4f (diff) |
*** empty log message ***
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@95 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
-rw-r--r-- | sample/rbc.rb | 125 | ||||
-rw-r--r-- | sample/ruby-mode.el | 2 |
2 files changed, 79 insertions, 48 deletions
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" |