Class: Parselly::Lexer::Token
- Inherits:
-
Struct
- Object
- Struct
- Parselly::Lexer::Token
- Defined in:
- lib/parselly/lexer.rb
Instance Attribute Summary collapse
-
#position ⇒ Object
Returns the value of attribute position.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](index) ⇒ Object
- #[]=(index, new_value) ⇒ Object
- #first ⇒ Object
- #last ⇒ Object
- #to_ary ⇒ Object (also: #to_a)
Instance Attribute Details
#position ⇒ Object
Returns the value of attribute position
29 30 31 |
# File 'lib/parselly/lexer.rb', line 29 def position @position end |
#type ⇒ Object
Returns the value of attribute type
29 30 31 |
# File 'lib/parselly/lexer.rb', line 29 def type @type end |
#value ⇒ Object
Returns the value of attribute value
29 30 31 |
# File 'lib/parselly/lexer.rb', line 29 def value @value end |
Instance Method Details
#==(other) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/parselly/lexer.rb', line 61 def ==(other) return super unless other.respond_to?(:to_ary) other_type, other_value, other_position = other.to_ary return false unless type == other_type return false unless value == other_value return position == other_position unless position.is_a?(Hash) && other_position.is_a?(Hash) other_position.all? { |key, expected| position[key] == expected } end |
#[](index) ⇒ Object
30 31 32 |
# File 'lib/parselly/lexer.rb', line 30 def [](index) to_ary[index] end |
#[]=(index, new_value) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/parselly/lexer.rb', line 34 def []=(index, new_value) case index when 0 self.type = new_value when 1 self.value = new_value when 2 self.position = new_value else raise IndexError, "index #{index} outside of token" end end |
#first ⇒ Object
47 48 49 |
# File 'lib/parselly/lexer.rb', line 47 def first type end |
#last ⇒ Object
51 52 53 |
# File 'lib/parselly/lexer.rb', line 51 def last position end |
#to_ary ⇒ Object Also known as: to_a
55 56 57 |
# File 'lib/parselly/lexer.rb', line 55 def to_ary [type, value, position] end |