Class: SyntaxTree::Parser::TokenList
- Inherits:
-
Object
- Object
- SyntaxTree::Parser::TokenList
- 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
-
#last_deleted ⇒ Object
readonly
Returns the value of attribute last_deleted.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
- #<<(token) ⇒ Object
- #[](index) ⇒ Object
- #any?(&block) ⇒ Boolean
- #delete(value) ⇒ Object
- #delete_at(index) ⇒ Object
-
#initialize ⇒ TokenList
constructor
A new instance of TokenList.
- #reverse_each(&block) ⇒ Object
- #rindex(&block) ⇒ Object
Constructor Details
#initialize ⇒ TokenList
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_deleted ⇒ Object (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 |
#tokens ⇒ Object (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
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 |