Class: YARD::Parser::Ruby::Legacy::TokenList

Inherits:
Array
  • Object
show all
Includes:
RubyToken
Defined in:
lib/yard/parser/ruby/legacy/token_list.rb

Constant Summary

Constants included from RubyToken

RubyToken::EXPR_ARG, RubyToken::EXPR_BEG, RubyToken::EXPR_CLASS, RubyToken::EXPR_DOT, RubyToken::EXPR_END, RubyToken::EXPR_FNAME, RubyToken::EXPR_MID, RubyToken::NEWLINE_TOKEN, RubyToken::TkReading2Token, RubyToken::TkSymbol2Token, RubyToken::TokenDefinitions

Instance Method Summary collapse

Methods included from RubyToken

#Token, def_token, #set_token_position

Methods inherited from Array

#place

Constructor Details

#initialize(content = nil) ⇒ TokenList

Returns a new instance of TokenList.



7
8
9
# File 'lib/yard/parser/ruby/legacy/token_list.rb', line 7

def initialize(content = nil)
  self << content if content
end

Instance Method Details

#push(*tokens) ⇒ Object Also known as: <<

Parameters:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yard/parser/ruby/legacy/token_list.rb', line 21

def push(*tokens)
  tokens.each do |tok|
    if tok.is_a?(TokenList) || tok.is_a?(Array)
      concat tok
    elsif tok.is_a?(Token)
      super tok
    elsif tok.is_a?(String)
      parse_content(tok)
    else
      raise ArgumentError, "Expecting token, list of tokens or string of code to be tokenized. Got #{tok.class}"
    end
  end
  self
end

#squeeze(type = TkSPACE) ⇒ Object



37
38
39
40
# File 'lib/yard/parser/ruby/legacy/token_list.rb', line 37

def squeeze(type = TkSPACE)
  last = nil
  TokenList.new(map {|t| x = t.is_a?(type) && last.is_a?(type) ? nil : t; last = t; x })
end

#to_s(full_statement = false, show_block = true) ⇒ Object



11
12
13
14
15
16
# File 'lib/yard/parser/ruby/legacy/token_list.rb', line 11

def to_s(full_statement = false, show_block = true)
  inject([]) do |acc, token|
    break acc if !full_statement && TkStatementEnd === token
    acc << (!show_block && TkBlockContents === token ? "" : token.text)
  end.join
end