Class: Herb::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/herb/location.rb,
sig/herb/location.rbs,
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

Parameters:



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

#endPosition (readonly)

: Position

Returns:



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

def end
  @end
end

#startPosition (readonly)

: Position

Returns:



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) ⇒ Location

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

Parameters:

  • (Integer)
  • (Integer)
  • (Integer)
  • (Integer)

Returns:



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) ⇒ Location

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

Parameters:

  • (Integer)
  • (Integer)
  • (Integer)
  • (Integer)

Returns:



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

#inspectString

: () -> String

Returns:

  • (String)


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

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

#to_hashserialized_location

: () -> serialized_location

Returns:

  • (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) ⇒ String

: (?untyped) -> String

Parameters:

  • (Object)

Returns:

  • (String)


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

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

#tree_inspectString

: () -> String

Returns:

  • (String)


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

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