Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • irb/ruby-token.rb

RubyToken

irb/ruby-token.rb - ruby tokens
    $Release Version: 0.9.6$
    $Revision: 25189 $
    by Keiju ISHITSUKA(keiju@ruby-lang.org)

Constants

EXPR_ARG
EXPR_BEG
EXPR_CLASS
EXPR_DOT
EXPR_END
EXPR_FNAME
EXPR_MID
Symbol
TkReading2Token

{reading => token_class} {reading => [token_class, *opt]}

TkSymbol2Token
TokenDefinitions

Public Class Methods

def_token(token_n, super_token = Token, reading = nil, *opts) click to toggle source
 
               # File irb/ruby-token.rb, line 247
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
            

Public Instance Methods

Token(token, value = nil) click to toggle source
 
               # File irb/ruby-token.rb, line 81
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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus