irb/ruby-token.rb - ruby tokens $Release Version: 0.9.5$ $Revision: 11708 $ $Date: 2007-02-12 17:01:19 -0600 (Mon, 12 Feb 2007) $ by Keiju ISHITSUKA(keiju@ruby-lang.org)
–
{reading => token_class} {reading => [token_class, *opt]}
# File irb/ruby-token.rb, line 250 def RubyToken.def_token(token_n, super_token = Token, reading = nil, *opts) token_n = token_n.id2name if token_n.kind_of?(Symbol) if RubyToken.const_defined?(token_n) IRB.fail AlreadyDefinedToken, token_n end token_c = eval("class #{token_n} < #{super_token}; end; #{token_n}") if reading if TkReading2Token[reading] IRB.fail TkReading2TokenDuplicateError, token_n, reading end if opts.empty? TkReading2Token[reading] = [token_c] else TkReading2Token[reading] = [token_c].concat(opts) end end TkSymbol2Token[token_n.intern] = token_c end
# File irb/ruby-token.rb, line 84 def Token(token, value = nil) case token when String if (tk = TkReading2Token[token]).nil? IRB.fail TkReading2TokenNoKey, token end tk = Token(tk[0], value) if tk.kind_of?(TkOp) tk.name = token end return tk when Symbol if (tk = TkSymbol2Token[token]).nil? IRB.fail TkSymbol2TokenNoKey, token end return Token(tk[0], value) else if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty? token.new(@prev_seek, @prev_line_no, @prev_char_no) else token.new(@prev_seek, @prev_line_no, @prev_char_no, value) end end end