class Yoda::Parsing::Range

Attributes

begin_location[R]
end_location[R]

Public Class Methods

new(begin_location, end_location) click to toggle source

@param begin_location [Integer] @param end_location [Integer]

# File lib/yoda/parsing/range.rb, line 7
def initialize(begin_location, end_location)
  @begin_location = begin_location
  @end_location = end_location
end
of_ast_location(ast_location) click to toggle source

@param ast_location [Parser::Source::Map, Parser::Source::Range] @return [Location, nil]

# File lib/yoda/parsing/range.rb, line 14
def self.of_ast_location(ast_location)
  return nil unless Location.valid_location?(ast_location)
  new(
    Location.new(row: ast_location.line, column: ast_location.column),
    Location.new(row: ast_location.last_line, column: ast_location.last_column),
  )
end

Public Instance Methods

include?(location) click to toggle source

@param location [Location] @return [true, false]

# File lib/yoda/parsing/range.rb, line 36
def include?(location)
  begin_location <= location && location <= end_location
end
move(row:, column:) click to toggle source

@param row [Integer] @param column [Integer] @return [Range]

# File lib/yoda/parsing/range.rb, line 30
def move(row:, column:)
  self.class.new(begin_location.move(row: row, column: column), end_location.move(row: row, column: column))
end
to_language_server_protocol_range() click to toggle source

@return [{Symbol => { Symbol => Integer } }]

# File lib/yoda/parsing/range.rb, line 23
def to_language_server_protocol_range
  { start: begin_location.to_language_server_protocol_range, end: end_location.to_language_server_protocol_range }
end