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.



64
65
66
# File 'lib/ripper/lexer.rb', line 64

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



63
64
65
# File 'lib/ripper/lexer.rb', line 63

def event
  @event
end

#messageObject

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



63
64
65
# File 'lib/ripper/lexer.rb', line 63

def message
  @message
end

#posObject

Returns the value of attribute pos

Returns:

  • (Object)

    the current value of pos



63
64
65
# File 'lib/ripper/lexer.rb', line 63

def pos
  @pos
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



63
64
65
# File 'lib/ripper/lexer.rb', line 63

def state
  @state
end

#tokObject

Returns the value of attribute tok

Returns:

  • (Object)

    the current value of tok



63
64
65
# File 'lib/ripper/lexer.rb', line 63

def tok
  @tok
end

Instance Method Details

#inspectObject



68
69
70
# File 'lib/ripper/lexer.rb', line 68

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

#pretty_print(q) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ripper/lexer.rb', line 72

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



89
90
91
92
93
# File 'lib/ripper/lexer.rb', line 89

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