123456789_123456789_123456789_123456789_123456789_

Module: YARD::Parser::Ruby::Legacy::RubyToken

Overview

::YARD::Parser::Ruby::Legacy lexical tokenizer module.

Constant Summary

Class Method Summary

Instance Method Summary

Class Method Details

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

This method is for internal use only.
[ GitHub ]

  
# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 275

def self.def_token(token_n, super_token = Token, reading = nil, *opts)
  token_n = token_n.id2name unless token_n.is_a?(String)
  if RubyToken.const_defined?(token_n)
    # IRB.fail AlreadyDefinedToken, token_n
  end

  token_c = Class.new super_token
  RubyToken.const_set token_n, token_c
  # token_c.inspect

  if reading
    if TkReading2Token[reading]
      raise "duplicate #{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

  if token_c <= TkOp
    token_c.class_eval %{
      def self.op_name; "#{reading}"; end
    }
  end
end

Instance Method Details

#set_token_position(line, char)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 119

def set_token_position(line, char)
  @prev_line_no = line
  @prev_char_no = char
end

Token(token, value = nil)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 125

def Token(token, value = nil) # rubocop:disable Style/MethodName
  tk = nil
  case token
  when String, Symbol
    source = token.is_a?(String) ? TkReading2Token : TkSymbol2Token
    if (tk = source[token]).nil?
      raise "no key #{token}"
    end
    tk = Token(tk[0], value)
  else
    if token
      tk = if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
             token.new(@prev_line_no, @prev_char_no)
           else
             token.new(@prev_line_no, @prev_char_no, value)
           end
    end
  end
  tk
end