123456789_123456789_123456789_123456789_123456789_

Class: Prism::LexRipper

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/prism/lex_compat.rb

Overview

This is a class that wraps the Ripper lexer to produce almost exactly the same tokens.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(source) ⇒ LexRipper

[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 875

def initialize(source)
  @source = source
end

Instance Attribute Details

#source (readonly)

[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 873

attr_reader :source

Instance Method Details

#lex(source) (private)

See additional method definition at line 913.

[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 917

def lex(source)
  Ripper.lex(source, raise_errors: true)
end

#result

[ GitHub ]

  
# File 'lib/prism/lex_compat.rb', line 879

def result
  previous = [] #: [[Integer, Integer], Symbol, String, untyped] | []
  results = [] #: Array[[[Integer, Integer], Symbol, String, untyped]]

  lex(source).each do |token|
    case token[1]
    when :on_sp
      # skip
    when :on_tstring_content
      if previous[1] == :on_tstring_content && (token[2].start_with?("\#$") || token[2].start_with?("\#@"))
        previous[2] << token[2]
      else
        results << token
        previous = token
      end
    when :on_words_sep
      if previous[1] == :on_words_sep
        previous[2] << token[2]
      else
        results << token
        previous = token
      end
    else
      results << token
      previous = token
    end
  end

  results
end