Class
Ripper.lex
is not guaranteed to lex the entire source document
lex = LexAll.new
(source: source) lex.each do |value|
puts value.line
end
Class Methods
lib/syntax_suggest/lex_all.rb
View on GitHub
# File tmp/rubies/ruby-3.2.0/lib/syntax_suggest/lex_all.rb, line 13
def initialize(source:, source_lines: nil)
@lex = Ripper::Lexer.new(source, "-", 1).parse.sort_by(&:pos)
lineno = @lex.last.pos.first + 1
source_lines ||= source.lines
last_lineno = source_lines.length
until lineno >= last_lineno
lines = source_lines[lineno..-1]
@lex.concat(
Ripper::Lexer.new(lines.join, "-", lineno + 1).parse.sort_by(&:pos)
)
lineno = @lex.last.pos.first + 1
end
last_lex = nil
@lex.map! { |elem|
last_lex = LexValue.new(elem.pos.first, elem.event, elem.tok, elem.state, last_lex)
}
end
No documentation available
Instance Methods
lib/syntax_suggest/lex_all.rb
View on GitHub
# File tmp/rubies/ruby-3.2.0/lib/syntax_suggest/lex_all.rb, line 45
def [](index)
@lex[index]
end
No documentation available
lib/syntax_suggest/lex_all.rb
View on GitHub
# File tmp/rubies/ruby-3.2.0/lib/syntax_suggest/lex_all.rb, line 38
def each
return @lex.each unless block_given?
@lex.each do |x|
yield x
end
end
No documentation available
#
lib/syntax_suggest/lex_all.rb
View on GitHub
# File tmp/rubies/ruby-3.2.0/lib/syntax_suggest/lex_all.rb, line 49
def last
@lex.last
end
No documentation available
#
lib/syntax_suggest/lex_all.rb
View on GitHub
# File tmp/rubies/ruby-3.2.0/lib/syntax_suggest/lex_all.rb, line 34
def to_a
@lex
end
No documentation available