class SyntaxTree::Location

Represents the location of a node in the tree from the source code.

Attributes

end_char[R]
end_column[R]
end_line[R]
start_char[R]
start_column[R]
start_line[R]

Public Class Methods

default() click to toggle source

A convenience method that is typically used when you don’t care about the location of a node, but need to create a Location instance to pass to a constructor.

# File lib/syntax_tree/node.rb, line 90
def self.default
  new(
    start_line: 1,
    start_char: 0,
    start_column: 0,
    end_line: 1,
    end_char: 0,
    end_column: 0
  )
end
fixed(line:, char:, column:) click to toggle source
# File lib/syntax_tree/node.rb, line 76
def self.fixed(line:, char:, column:)
  new(
    start_line: line,
    start_char: char,
    start_column: column,
    end_line: line,
    end_char: char,
    end_column: column
  )
end
new( start_line:, start_char:, start_column:, end_line:, end_char:, end_column: ) click to toggle source
# File lib/syntax_tree/node.rb, line 13
def initialize(
  start_line:,
  start_char:,
  start_column:,
  end_line:,
  end_char:,
  end_column:
)
  @start_line = start_line
  @start_char = start_char
  @start_column = start_column
  @end_line = end_line
  @end_char = end_char
  @end_column = end_column
end
token(line:, char:, column:, size:) click to toggle source
# File lib/syntax_tree/node.rb, line 65
def self.token(line:, char:, column:, size:)
  new(
    start_line: line,
    start_char: char,
    start_column: column,
    end_line: line,
    end_char: char + size,
    end_column: column + size
  )
end

Public Instance Methods

==(other) click to toggle source
# File lib/syntax_tree/node.rb, line 33
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
deconstruct() click to toggle source
# File lib/syntax_tree/node.rb, line 50
def deconstruct
  [start_line, start_char, start_column, end_line, end_char, end_column]
end
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 54
def deconstruct_keys(_keys)
  {
    start_line: start_line,
    start_char: start_char,
    start_column: start_column,
    end_line: end_line,
    end_char: end_char,
    end_column: end_column
  }
end
lines() click to toggle source
# File lib/syntax_tree/node.rb, line 29
def lines
  start_line..end_line
end
to(other) click to toggle source
# File lib/syntax_tree/node.rb, line 39
def to(other)
  Location.new(
    start_line: start_line,
    start_char: start_char,
    start_column: start_column,
    end_line: [end_line, other.end_line].max,
    end_char: other.end_char,
    end_column: other.end_column
  )
end