Class: Ripper::Lexer::Elem

Inherits:
Struct
  • Object
show all
Defined in:
lib/ripper/lexer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pos, event, tok, state, message = nil) ⇒ Elem

Returns a new instance of Elem.



71
72
73
# File 'lib/ripper/lexer.rb', line 71

def initialize(pos, event, tok, state, message = nil)
  super(pos, event, tok, State.new(state), message)
end

Instance Attribute Details

#eventObject

Returns the value of attribute event

Returns:

  • (Object)

    the current value of event



70
71
72
# File 'lib/ripper/lexer.rb', line 70

def event
  @event
end

#messageObject

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



70
71
72
# File 'lib/ripper/lexer.rb', line 70

def message
  @message
end

#posObject

Returns the value of attribute pos

Returns:

  • (Object)

    the current value of pos



70
71
72
# File 'lib/ripper/lexer.rb', line 70

def pos
  @pos
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



70
71
72
# File 'lib/ripper/lexer.rb', line 70

def state
  @state
end

#tokObject

Returns the value of attribute tok

Returns:

  • (Object)

    the current value of tok



70
71
72
# File 'lib/ripper/lexer.rb', line 70

def tok
  @tok
end

Instance Method Details

#inspectObject



75
76
77
# File 'lib/ripper/lexer.rb', line 75

def inspect
  "#<#{self.class}: #{event}@#{pos[0]}:#{pos[1]}:#{state}: #{tok.inspect}#{": " if message}#{message}>"
end

#pretty_print(q) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ripper/lexer.rb', line 79

def pretty_print(q)
  q.group(2, "#<#{self.class}:", ">") {
    q.breakable
    q.text("#{event}@#{pos[0]}:#{pos[1]}")
    q.breakable
    q.text(state)
    q.breakable
    q.text("token: ")
    tok.pretty_print(q)
    if message
      q.breakable
      q.text("message: ")
      q.text(message)
    end
  }
end

#to_aObject



96
97
98
99
100
# File 'lib/ripper/lexer.rb', line 96

def to_a
  a = super
  a.pop unless a.last
  a
end