Class: Ripper::Lexer::Elem
- Inherits:
-
Object
- Object
- Ripper::Lexer::Elem
- Defined in:
- lib/ripper/lexer.rb
Instance Attribute Summary collapse
-
#event ⇒ Object
Returns the value of attribute event.
-
#message ⇒ Object
Returns the value of attribute message.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#state ⇒ Object
Returns the value of attribute state.
-
#tok ⇒ Object
Returns the value of attribute tok.
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#initialize(pos, event, tok, state, message = nil) ⇒ Elem
constructor
A new instance of Elem.
- #inspect ⇒ Object (also: #to_s)
- #pretty_print(q) ⇒ Object
- #to_a ⇒ Object
Constructor Details
Instance Attribute Details
#event ⇒ Object
Returns the value of attribute event.
89 90 91 |
# File 'lib/ripper/lexer.rb', line 89 def event @event end |
#message ⇒ Object
Returns the value of attribute message.
89 90 91 |
# File 'lib/ripper/lexer.rb', line 89 def @message end |
#pos ⇒ Object
Returns the value of attribute pos.
89 90 91 |
# File 'lib/ripper/lexer.rb', line 89 def pos @pos end |
#state ⇒ Object
Returns the value of attribute state.
89 90 91 |
# File 'lib/ripper/lexer.rb', line 89 def state @state end |
#tok ⇒ Object
Returns the value of attribute tok.
89 90 91 |
# File 'lib/ripper/lexer.rb', line 89 def tok @tok end |
Instance Method Details
#[](index) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ripper/lexer.rb', line 99 def [](index) case index when 0, :pos @pos when 1, :event @event when 2, :tok @tok when 3, :state @state when 4, :message @message else nil end end |
#inspect ⇒ Object Also known as: to_s
116 117 118 |
# File 'lib/ripper/lexer.rb', line 116 def inspect "#<#{self.class}: #{event}@#{pos[0]}:#{pos[1]}:#{state}: #{tok.inspect}#{": " if }#{}>" end |
#pretty_print(q) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ripper/lexer.rb', line 122 def pretty_print(q) q.group(2, "#<#{self.class}:", ">") { q.breakable q.text("#{event}@#{pos[0]}:#{pos[1]}") q.breakable state.pretty_print(q) q.breakable q.text("token: ") tok.pretty_print(q) if q.breakable q.text("message: ") q.text() end } end |
#to_a ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/ripper/lexer.rb', line 139 def to_a if @message [@pos, @event, @tok, @state, @message] else [@pos, @event, @tok, @state] end end |