Class: Herb::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/herb/location.rb,
ext/herb/extension.c

Overview

: type serialized_location = { | start: serialized_position, | end: serialized_position | }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_position, end_position) ⇒ Location

: (Position, Position) -> void



14
15
16
17
# File 'lib/herb/location.rb', line 14

def initialize(start_position, end_position)
  @start = start_position
  @end = end_position
end

Instance Attribute Details

#endObject (readonly)

: Position



11
12
13
# File 'lib/herb/location.rb', line 11

def end
  @end
end

#startObject (readonly)

: Position



10
11
12
# File 'lib/herb/location.rb', line 10

def start
  @start
end

Class Method Details

.[](start_line, start_column, end_line, end_column) ⇒ Object

: (Integer, Integer, Integer, Integer) -> Location



28
29
30
# File 'lib/herb/location.rb', line 28

def self.[](start_line, start_column, end_line, end_column)
  from(start_line, start_column, end_line, end_column)
end

.from(start_line, start_column, end_line, end_column) ⇒ Object

: (Integer, Integer, Integer, Integer) -> Location



20
21
22
23
24
25
# File 'lib/herb/location.rb', line 20

def self.from(start_line, start_column, end_line, end_column)
  new(
    Position.new(start_line, start_column),
    Position.new(end_line, end_column)
  )
end

Instance Method Details

#inspectObject

: () -> String



51
52
53
# File 'lib/herb/location.rb', line 51

def inspect
  %(#<Herb::Location (location: #{tree_inspect})>)
end

#to_hashObject

: () -> serialized_location



33
34
35
36
37
38
# File 'lib/herb/location.rb', line 33

def to_hash
  {
    start: start.to_hash,
    end: self.end.to_hash,
  }
end

#to_json(state = nil) ⇒ Object

: (?untyped) -> String



41
42
43
# File 'lib/herb/location.rb', line 41

def to_json(state = nil)
  to_hash.to_json(state)
end

#tree_inspectObject

: () -> String



46
47
48
# File 'lib/herb/location.rb', line 46

def tree_inspect
  "#{start.tree_inspect}-#{self.end.tree_inspect}"
end