Class: SyntaxTree::Location
- Inherits:
-
Object
- Object
- SyntaxTree::Location
- Defined in:
- lib/syntax_tree.rb
Overview
Represents the location of a node in the tree from the source code.
Instance Attribute Summary collapse
-
#end_char ⇒ Object
readonly
Returns the value of attribute end_char.
-
#end_line ⇒ Object
readonly
Returns the value of attribute end_line.
-
#start_char ⇒ Object
readonly
Returns the value of attribute start_char.
-
#start_line ⇒ Object
readonly
Returns the value of attribute start_line.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(start_line:, start_char:, end_line:, end_char:) ⇒ Location
constructor
A new instance of Location.
- #to(other) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(start_line:, start_char:, end_line:, end_char:) ⇒ Location
60 61 62 63 64 65 |
# File 'lib/syntax_tree.rb', line 60 def initialize(start_line:, start_char:, end_line:, end_char:) @start_line = start_line @start_char = start_char @end_line = end_line @end_char = end_char end |
Instance Attribute Details
#end_char ⇒ Object (readonly)
Returns the value of attribute end_char.
58 59 60 |
# File 'lib/syntax_tree.rb', line 58 def end_char @end_char end |
#end_line ⇒ Object (readonly)
Returns the value of attribute end_line.
58 59 60 |
# File 'lib/syntax_tree.rb', line 58 def end_line @end_line end |
#start_char ⇒ Object (readonly)
Returns the value of attribute start_char.
58 59 60 |
# File 'lib/syntax_tree.rb', line 58 def start_char @start_char end |
#start_line ⇒ Object (readonly)
Returns the value of attribute start_line.
58 59 60 |
# File 'lib/syntax_tree.rb', line 58 def start_line @start_line end |
Class Method Details
.fixed(line:, char:) ⇒ Object
96 97 98 |
# File 'lib/syntax_tree.rb', line 96 def self.fixed(line:, char:) new(start_line: line, start_char: char, end_line: line, end_char: char) end |
.token(line:, char:, size:) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/syntax_tree.rb', line 87 def self.token(line:, char:, size:) new( start_line: line, start_char: char, end_line: line, end_char: char + size ) end |
Instance Method Details
#==(other) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/syntax_tree.rb', line 67 def ==(other) other.is_a?(Location) && start_line == other.start_line && start_char == other.start_char && end_line == other.end_line && end_char == other.end_char end |
#to(other) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/syntax_tree.rb', line 74 def to(other) Location.new( start_line: start_line, start_char: start_char, end_line: other.end_line, end_char: other.end_char ) end |
#to_json(*opts) ⇒ Object
83 84 85 |
# File 'lib/syntax_tree.rb', line 83 def to_json(*opts) [start_line, start_char, end_line, end_char].to_json(*opts) end |