Class: SyntaxTree::Parser::TokenList

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/parser.rb

Overview

This represents all of the tokens coming back from the lexer. It is replacing a simple array because it keeps track of the last deleted token from the list for better error messages.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTokenList

Returns a new instance of TokenList.



66
67
68
69
# File 'lib/syntax_tree/parser.rb', line 66

def initialize
  @tokens = []
  @last_deleted = nil
end

Instance Attribute Details

#last_deletedObject (readonly)

Returns the value of attribute last_deleted.



64
65
66
# File 'lib/syntax_tree/parser.rb', line 64

def last_deleted
  @last_deleted
end

#tokensObject (readonly)

Returns the value of attribute tokens.



64
65
66
# File 'lib/syntax_tree/parser.rb', line 64

def tokens
  @tokens
end

Instance Method Details

#<<(token) ⇒ Object



71
72
73
# File 'lib/syntax_tree/parser.rb', line 71

def <<(token)
  tokens << token
end

#[](index) ⇒ Object



75
76
77
# File 'lib/syntax_tree/parser.rb', line 75

def [](index)
  tokens[index]
end

#any?(&block) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/syntax_tree/parser.rb', line 79

def any?(&block)
  tokens.any?(&block)
end

#delete(value) ⇒ Object



91
92
93
# File 'lib/syntax_tree/parser.rb', line 91

def delete(value)
  @last_deleted = tokens.delete(value) || @last_deleted
end

#delete_at(index) ⇒ Object



95
96
97
# File 'lib/syntax_tree/parser.rb', line 95

def delete_at(index)
  @last_deleted = tokens.delete_at(index)
end

#reverse_each(&block) ⇒ Object



83
84
85
# File 'lib/syntax_tree/parser.rb', line 83

def reverse_each(&block)
  tokens.reverse_each(&block)
end

#rindex(&block) ⇒ Object



87
88
89
# File 'lib/syntax_tree/parser.rb', line 87

def rindex(&block)
  tokens.rindex(&block)
end