Class: YARD::Parser::Ruby::Legacy::TokenList
- Inherits:
-
Array
- Object
- Array
- YARD::Parser::Ruby::Legacy::TokenList
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
Instance Method Summary
collapse
Constructor Details
#initialize(content = nil) ⇒ TokenList
Returns a new instance of TokenList.
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
#push(*tokens) ⇒ Object
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
|
#squeeze(type = TkSPACE) ⇒ Object
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
|
#to_s(full_statement = false, show_block = true) ⇒ Object
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
|