Class: SyntaxTree::CSS::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/css/nodes.rb

Overview

This represents a location in the source file. It maps constructs like tokens and parse nodes to their original location.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_char:, end_char:) ⇒ Location

Returns a new instance of Location.



10
11
12
13
# File 'lib/syntax_tree/css/nodes.rb', line 10

def initialize(start_char:, end_char:)
  @start_char = start_char
  @end_char = end_char
end

Instance Attribute Details

#end_charObject (readonly)

Returns the value of attribute end_char.



8
9
10
# File 'lib/syntax_tree/css/nodes.rb', line 8

def end_char
  @end_char
end

#start_charObject (readonly)

Returns the value of attribute start_char.



8
9
10
# File 'lib/syntax_tree/css/nodes.rb', line 8

def start_char
  @start_char
end

Class Method Details

.from(range) ⇒ Object



23
24
25
# File 'lib/syntax_tree/css/nodes.rb', line 23

def self.from(range)
  Location.new(start_char: range.begin, end_char: range.end)
end

Instance Method Details

#to(other) ⇒ Object



15
16
17
# File 'lib/syntax_tree/css/nodes.rb', line 15

def to(other)
  Location.new(start_char: start_char, end_char: other.end_char)
end

#to_rangeObject



19
20
21
# File 'lib/syntax_tree/css/nodes.rb', line 19

def to_range
  start_char...end_char
end