Class: Yoda::Parsing::Range

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/parsing/range.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(begin_location, end_location) ⇒ Range

Returns a new instance of Range.

Parameters:

  • begin_location (Integer)
  • end_location (Integer)


7
8
9
10
# File 'lib/yoda/parsing/range.rb', line 7

def initialize(begin_location, end_location)
  @begin_location = begin_location
  @end_location = end_location
end

Instance Attribute Details

#begin_locationObject (readonly)

Returns the value of attribute begin_location.



4
5
6
# File 'lib/yoda/parsing/range.rb', line 4

def begin_location
  @begin_location
end

#end_locationObject (readonly)

Returns the value of attribute end_location.



4
5
6
# File 'lib/yoda/parsing/range.rb', line 4

def end_location
  @end_location
end

Class Method Details

.of_ast_location(ast_location) ⇒ Location?

Parameters:

  • ast_location (Parser::Source::Map, Parser::Source::Range)

Returns:



14
15
16
17
18
19
20
# 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

Instance Method Details

#include?(location) ⇒ true, false

Parameters:

Returns:

  • (true, false)


36
37
38
# File 'lib/yoda/parsing/range.rb', line 36

def include?(location)
  begin_location <= location && location <= end_location
end

#move(row:, column:) ⇒ Range

Parameters:

  • row (Integer)
  • column (Integer)

Returns:



30
31
32
# 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{Symbol => { Symbol => Integer } }

Returns:

  • ({Symbol => { Symbol => Integer } })


23
24
25
# 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