@@ -27,19 +27,20 @@ class CodeLine
2727 # Returns an array of CodeLine objects
2828 # from the source string
2929 def self . from_source ( source )
30- lex_array_for_line = LexAll . new ( source : source ) . each_with_object ( Hash . new { |h , k | h [ k ] = [ ] } ) { |lex , hash | hash [ lex . line ] << lex }
30+ tokens = LexAll . new ( source : source )
31+ tokens_for_line = tokens . each_with_object ( Hash . new { |h , k | h [ k ] = [ ] } ) { |token , hash | hash [ token . line ] << token }
3132 source . lines . map . with_index do |line , index |
3233 CodeLine . new (
3334 line : line ,
3435 index : index ,
35- lex : lex_array_for_line [ index + 1 ]
36+ tokens : tokens_for_line [ index + 1 ]
3637 )
3738 end
3839 end
3940
40- attr_reader :line , :index , :lex , :line_number , :indent
41- def initialize ( line :, index :, lex :)
42- @lex = lex
41+ attr_reader :line , :index , :tokens , :line_number , :indent
42+ def initialize ( line :, index :, tokens :)
43+ @tokens = tokens
4344 @line = line
4445 @index = index
4546 @original = line
@@ -180,12 +181,12 @@ def ignore_newline_not_beg?
180181 # expect(lines.first.trailing_slash?).to eq(true)
181182 #
182183 def trailing_slash?
183- last = @lex . last
184+ last = @tokens . last
184185
185186 # Older versions of prism diverged slightly from Ripper in compatibility mode
186187 case last &.type
187188 when :on_sp
188- last . token == TRAILING_SLASH
189+ last . value == TRAILING_SLASH
189190 when :on_tstring_end
190191 true
191192 else
@@ -209,21 +210,21 @@ def trailing_slash?
209210 end_count = 0
210211
211212 @ignore_newline_not_beg = false
212- @lex . each do |lex |
213- kw_count += 1 if lex . is_kw?
214- end_count += 1 if lex . is_end?
213+ @tokens . each do |token |
214+ kw_count += 1 if token . is_kw?
215+ end_count += 1 if token . is_end?
215216
216- if lex . type == :on_ignored_nl
217- @ignore_newline_not_beg = !lex . expr_beg?
217+ if token . type == :on_ignored_nl
218+ @ignore_newline_not_beg = !token . expr_beg?
218219 end
219220
220221 if in_oneliner_def . nil?
221- in_oneliner_def = :ENDFN if lex . state . allbits? ( Ripper ::EXPR_ENDFN )
222- elsif lex . state . allbits? ( Ripper ::EXPR_ENDFN )
222+ in_oneliner_def = :ENDFN if token . state . allbits? ( Ripper ::EXPR_ENDFN )
223+ elsif token . state . allbits? ( Ripper ::EXPR_ENDFN )
223224 # Continue
224- elsif lex . state . allbits? ( Ripper ::EXPR_BEG )
225- in_oneliner_def = :BODY if lex . token == "="
226- elsif lex . state . allbits? ( Ripper ::EXPR_END )
225+ elsif token . state . allbits? ( Ripper ::EXPR_BEG )
226+ in_oneliner_def = :BODY if token . value == "="
227+ elsif token . state . allbits? ( Ripper ::EXPR_END )
227228 # We found an endless method, count it
228229 oneliner_count += 1 if in_oneliner_def == :BODY
229230
0 commit comments