class DeadEnd::LexAll

Ripper.lex is not guaranteed to lex the entire source document

lex = LexAll.new(source: source) lex.each do |value|

puts value.line

end

Public Class Methods

new(source: ) click to toggle source
# File lib/dead_end/lex_all.rb, line 11
def initialize(source: )
  @lex = Ripper.lex(source)
  lineno = @lex.last&.first&.first + 1
  source_lines = source.lines
  last_lineno = source_lines.count

  until lineno >= last_lineno
    lines = source_lines[lineno..-1]

    @lex.concat(Ripper.lex(lines.join, '-', lineno + 1))
    lineno = @lex.last&.first&.first + 1
  end

  @lex.map! {|(line, _), type, token, state| LexValue.new(line, _, type, token, state) }
end

Public Instance Methods

each() { |x| ... } click to toggle source
# File lib/dead_end/lex_all.rb, line 27
def each
  return @lex.each unless block_given?
  @lex.each do |x|
    yield x
  end
end
last() click to toggle source
# File lib/dead_end/lex_all.rb, line 34
def last
  @lex.last
end