@@ -53,10 +53,16 @@ def Ripper.lex(src, filename = '-', lineno = 1, **kw)
53
53
end
54
54
55
55
class Lexer < ::Ripper #:nodoc: internal use only
56
- State = Struct . new ( :to_int , :to_s ) do
56
+ class State
57
+ attr_reader :to_int , :to_s
58
+
59
+ def initialize ( i )
60
+ @to_int = i
61
+ @to_s = Ripper . lex_state_name ( i )
62
+ freeze
63
+ end
64
+
57
65
alias to_i to_int
58
- def initialize ( i ) super ( i , Ripper . lex_state_name ( i ) ) . freeze end
59
- # def inspect; "#<#{self.class}: #{self}>" end
60
66
alias inspect to_s
61
67
def pretty_print ( q ) q . text ( to_s ) end
62
68
def ==( i ) super or to_int == i end
@@ -67,9 +73,15 @@ def anybits?(i) to_int.anybits?(i) end
67
73
def nobits? ( i ) to_int . nobits? ( i ) end
68
74
end
69
75
70
- Elem = Struct . new ( :pos , :event , :tok , :state , :message ) do
76
+ class Elem
77
+ attr_accessor :pos , :event , :tok , :state , :message
78
+
71
79
def initialize ( pos , event , tok , state , message = nil )
72
- super ( pos , event , tok , State . new ( state ) , message )
80
+ @pos = pos
81
+ @event = event
82
+ @tok = tok
83
+ @state = State . new ( state )
84
+ @message = message
73
85
end
74
86
75
87
def inspect
@@ -94,9 +106,11 @@ def pretty_print(q)
94
106
end
95
107
96
108
def to_a
97
- a = super
98
- a . pop unless a . last
99
- a
109
+ if @message
110
+ [ @pos , @event , @tok , @state , @message ]
111
+ else
112
+ [ @pos , @event , @tok , @state ]
113
+ end
100
114
end
101
115
end
102
116
0 commit comments