Class: YARD::Parser::Ruby::Legacy::TokenList
- Inherits:
-
Array
- Object
- Array
- YARD::Parser::Ruby::Legacy::TokenList
- Includes:
- RubyToken
- Defined in:
- lib/yard/parser/ruby/legacy/token_list.rb
Constant Summary
Constants included from RubyToken
EXPR_ARG, EXPR_BEG, EXPR_CLASS, EXPR_DOT, EXPR_END, EXPR_FNAME, EXPR_MID, NEWLINE_TOKEN, TkReading2Token, TkSymbol2Token
Instance Method Summary (collapse)
-
- (TokenList) initialize(content = nil)
constructor
A new instance of TokenList.
- - (Object) push(*tokens) (also: #<<)
- - (Object) squeeze(type = TkSPACE)
- - (Object) to_s(full_statement = false, show_block = true)
Methods inherited from Array
Constructor Details
- (TokenList) initialize(content = nil)
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
- (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 |