@@ -198,58 +198,6 @@ def deconstruct_keys(keys)
198198 "__END__" : :on___end__
199199 } . freeze
200200
201- # Pretty much a 1:1 copy of Ripper::Lexer::State. We list all the available states
202- # to reimplement to_s without using Ripper.
203- class State
204- # Ripper-internal bitflags.
205- ALL = %i[
206- BEG END ENDARG ENDFN ARG CMDARG MID FNAME DOT CLASS LABEL LABELED FITEM
207- ] . map . with_index . to_h { |name , i | [ 2 ** i , name ] }
208- ALL [ 0 ] = :NONE
209- ALL . freeze
210- ALL . each { |value , name | const_set ( name , value ) }
211-
212- # :stopdoc:
213-
214- attr_reader :to_int , :to_s
215-
216- def initialize ( i )
217- @to_int = i
218- @to_s = state_name ( i )
219- freeze
220- end
221-
222- def []( index )
223- case index
224- when 0 , :to_int
225- @to_int
226- when 1 , :to_s
227- @to_s
228- else
229- nil
230- end
231- end
232-
233- alias to_i to_int
234- alias inspect to_s
235- def pretty_print ( q ) q . text ( to_s ) end
236- def ==( i ) super or to_int == i end
237- def &( i ) self . class . new ( to_int & i ) end
238- def |( i ) self . class . new ( to_int | i ) end
239- def allbits? ( i ) to_int . allbits? ( i ) end
240- def anybits? ( i ) to_int . anybits? ( i ) end
241- def nobits? ( i ) to_int . nobits? ( i ) end
242-
243- # :startdoc:
244-
245- private
246-
247- # Convert the state flags into the format exposed by ripper.
248- def state_name ( bits )
249- ALL . filter_map { |flag , name | name if bits & flag != 0 } . join ( "|" )
250- end
251- end
252-
253201 # When we produce tokens, we produce the same arrays that Ripper does.
254202 # However, we add a couple of convenience methods onto them to make them a
255203 # little easier to work with. We delegate all other methods to the array.
@@ -300,8 +248,8 @@ def ==(other) # :nodoc:
300248 class IdentToken < Token
301249 def ==( other ) # :nodoc:
302250 ( self [ 0 ...-1 ] == other [ 0 ...-1 ] ) && (
303- ( other [ 3 ] == State :: LABEL | State :: END ) ||
304- ( other [ 3 ] & ( State :: ARG | State :: CMDARG ) != 0 )
251+ ( other [ 3 ] == Translation :: Ripper :: EXPR_LABEL | Translation :: Ripper :: EXPR_END ) ||
252+ ( other [ 3 ] & ( Translation :: Ripper :: EXPR_ARG | Translation :: Ripper :: EXPR_CMDARG ) != 0 )
305253 )
306254 end
307255 end
@@ -312,8 +260,8 @@ class IgnoredNewlineToken < Token
312260 def ==( other ) # :nodoc:
313261 return false unless self [ 0 ...-1 ] == other [ 0 ...-1 ]
314262
315- if self [ 3 ] == State :: ARG | State :: LABELED
316- other [ 3 ] & State :: ARG | State :: LABELED != 0
263+ if self [ 3 ] == Translation :: Ripper :: EXPR_ARG | Translation :: Ripper :: EXPR_LABELED
264+ other [ 3 ] & Translation :: Ripper :: EXPR_ARG | Translation :: Ripper :: EXPR_LABELED != 0
317265 else
318266 self [ 3 ] == other [ 3 ]
319267 end
@@ -331,8 +279,8 @@ def ==(other) # :nodoc:
331279 class ParamToken < Token
332280 def ==( other ) # :nodoc:
333281 ( self [ 0 ...-1 ] == other [ 0 ...-1 ] ) && (
334- ( other [ 3 ] == State :: END ) ||
335- ( other [ 3 ] == State :: END | State :: LABEL )
282+ ( other [ 3 ] == Translation :: Ripper :: EXPR_END ) ||
283+ ( other [ 3 ] == Translation :: Ripper :: EXPR_END | Translation :: Ripper :: EXPR_LABEL )
336284 )
337285 end
338286 end
@@ -727,7 +675,7 @@ def result
727675
728676 event = RIPPER . fetch ( token . type )
729677 value = token . value
730- lex_state = State . new ( lex_state )
678+ lex_state = Translation :: Ripper :: Lexer :: State . new ( lex_state )
731679
732680 token =
733681 case event
@@ -741,7 +689,7 @@ def result
741689 last_heredoc_end = token . location . end_offset
742690 IgnoreStateToken . new ( [ [ lineno , column ] , event , value , lex_state ] )
743691 when :on_ident
744- if lex_state == State :: END
692+ if lex_state == Translation :: Ripper :: EXPR_END
745693 # If we have an identifier that follows a method name like:
746694 #
747695 # def foo bar
@@ -751,7 +699,7 @@ def result
751699 # yet. We do this more accurately, so we need to allow comparing
752700 # against both END and END|LABEL.
753701 ParamToken . new ( [ [ lineno , column ] , event , value , lex_state ] )
754- elsif lex_state == State :: END | State :: LABEL
702+ elsif lex_state == Translation :: Ripper :: EXPR_END | Translation :: Ripper :: EXPR_LABEL
755703 # In the event that we're comparing identifiers, we're going to
756704 # allow a little divergence. Ripper doesn't account for local
757705 # variables introduced through named captures in regexes, and we
@@ -791,7 +739,7 @@ def result
791739 counter += { on_embexpr_beg : -1 , on_embexpr_end : 1 } [ current_event ] || 0
792740 end
793741
794- State . new ( result_value [ current_index ] [ 1 ] )
742+ Translation :: Ripper :: Lexer :: State . new ( result_value [ current_index ] [ 1 ] )
795743 else
796744 previous_state
797745 end
0 commit comments