Class: Herb::Location
- Inherits:
-
Object
- Object
- Herb::Location
- Defined in:
- lib/herb/location.rb,
ext/herb/extension.c
Overview
: type serialized_location = { | start: serialized_position, | end: serialized_position | }
Instance Attribute Summary collapse
-
#end ⇒ Object
readonly
: Position.
-
#start ⇒ Object
readonly
: Position.
Class Method Summary collapse
-
.[](start_line, start_column, end_line, end_column) ⇒ Object
: (Integer, Integer, Integer, Integer) -> Location.
-
.from(start_line, start_column, end_line, end_column) ⇒ Object
: (Integer, Integer, Integer, Integer) -> Location.
Instance Method Summary collapse
-
#initialize(start_position, end_position) ⇒ Location
constructor
: (Position, Position) -> void.
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_location.
-
#to_json(state = nil) ⇒ Object
: (?untyped) -> String.
-
#tree_inspect ⇒ Object
: () -> String.
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
#end ⇒ Object (readonly)
: Position
11 12 13 |
# File 'lib/herb/location.rb', line 11 def end @end end |
#start ⇒ Object (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
#inspect ⇒ Object
: () -> String
51 52 53 |
# File 'lib/herb/location.rb', line 51 def inspect %(#<Herb::Location (location: #{tree_inspect})>) end |
#to_hash ⇒ Object
: () -> 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_inspect ⇒ Object
: () -> String
46 47 48 |
# File 'lib/herb/location.rb', line 46 def tree_inspect "#{start.tree_inspect}-#{self.end.tree_inspect}" end |