Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/prism/lex_compat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def result

event = RIPPER.fetch(token.type)
value = token.value
lex_state = Translation::Ripper::Lexer::State.cached(lex_state)
lex_state = Translation::Ripper::Lexer::State[lex_state]

token =
case event
Expand Down Expand Up @@ -691,7 +691,7 @@ def result
counter += { on_embexpr_beg: -1, on_embexpr_end: 1 }[current_event] || 0
end

Translation::Ripper::Lexer::State.cached(result_value[current_index][1])
Translation::Ripper::Lexer::State[result_value[current_index][1]]
else
previous_state
end
Expand Down Expand Up @@ -828,7 +828,7 @@ def result
def add_on_sp_tokens(tokens, source, data_loc, bom, eof_token)
new_tokens = []

prev_token_state = Translation::Ripper::Lexer::State.cached(Translation::Ripper::EXPR_BEG)
prev_token_state = Translation::Ripper::Lexer::State[Translation::Ripper::EXPR_BEG]
prev_token_end = bom ? 3 : 0

tokens.each do |token|
Expand Down
11 changes: 6 additions & 5 deletions lib/prism/translation/ripper/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Ripper
class Lexer < Ripper # :nodoc:
# :stopdoc:
class State

attr_reader :to_int, :to_s

def initialize(i)
Expand Down Expand Up @@ -39,10 +38,12 @@ def allbits?(i) to_int.allbits?(i) end
def anybits?(i) to_int.anybits?(i) end
def nobits?(i) to_int.nobits?(i) end

# Instances are frozen and there are only a handful of them so we cache them here.
STATES = Hash.new { |h,k| h[k] = State.new(k) }
# Instances are frozen and there are only a handful of them so we
# cache them here.
STATES = Hash.new { |hash, key| hash[key] = State.new(key) }
private_constant :STATES

def self.cached(i)
def self.[](i)
STATES[i]
end
end
Expand All @@ -54,7 +55,7 @@ def initialize(pos, event, tok, state, message = nil)
@pos = pos
@event = event
@tok = tok
@state = State.cached(state)
@state = State[state]
@message = message
end

Expand Down