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

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

Instance Method Summary (collapse)

Methods inherited from Array

#place

Constructor Details

- (TokenList) initialize(content = nil)



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

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

Instance Method Details

- (Object) push(*tokens) Also known as: <<



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/yard/parser/ruby/legacy/token_list.rb', line 25

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

- (Object) squeeze(type = TkSPACE)



41
42
43
44
# File 'lib/yard/parser/ruby/legacy/token_list.rb', line 41

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

- (Object) to_s(full_statement = false, show_block = true)



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

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