123456789_123456789_123456789_123456789_123456789_

Module: RubyToken

Relationships & Source Files
Namespace Children
Classes:
Extension / Inclusion / Inheritance Descendants
Included In:
RubyLex
Defined in: lib/irb/ruby-token.rb

Overview

irb/ruby-token.rb - ruby tokens

$Release Version: 0.9.6$
$Revision$
by Keiju ISHITSUKA(keiju@ruby-lang.org)

Constant Summary

Class Method Summary

Instance Method Summary

Class Method Details

.def_token(token_n, super_token = Token, reading = nil, *opts)

[ GitHub ]

  
# File 'lib/irb/ruby-token.rb', line 242

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

Instance Method Details

Token(token, value = nil)

[ GitHub ]

  
# File 'lib/irb/ruby-token.rb', line 77

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