33 size_t start_row,
size_t start_column,
34 size_t end_row,
size_t end_column);
56 return lhs._start < rhs._start;
104 return lhs._source == rhs._source
105 && lhs._start == rhs._start
106 && lhs._end == rhs._end;
118 return !(lhs == rhs);
147 [[nodiscard]] std::string
substr()
const;
161 [[nodiscard]]
size_t line()
const;
168 [[nodiscard]]
const std::shared_ptr<Source>&
source()
const {
return _source; }
185 std::shared_ptr<Source> _source;
A position inside a Source, expressed as (row, column, index)
Definition: source.hpp:13
Represents a contiguous region within a Source
Definition: span.hpp:12
friend bool operator!=(const Span &lhs, const Span &rhs)
Inequality based on ==
Definition: span.hpp:117
Span join(const Span &other) const
Combines this span with another span into a single continuous span.
friend bool operator==(const Span &lhs, const Span &rhs)
Equality compares source, start and end.
Definition: span.hpp:103
std::string substr() const
Extracts the substring of the source covered by this span.
friend bool operator<=(const Span &lhs, const Span &rhs)
Less-than-or-equal comparison derived from >=
Definition: span.hpp:67
Location end() const
Returns the end location of the span.
Definition: span.hpp:182
size_t line() const
Returns the 1-based line number of the span's start.
size_t width() const
Returns the number of characters covered by this span.
friend bool operator>(const Span &lhs, const Span &rhs)
Greater-than comparison derived from <
Definition: span.hpp:79
bool intersects(const Span &other) const
Returns true if this span intersects the other span.
Span(const std::shared_ptr< Source > &source, size_t start_index, size_t end_index)
Constructs a span from 0-based character indices into the source content.
Span(const std::shared_ptr< Source > &source, size_t start_row, size_t start_column, size_t end_row, size_t end_column)
Constructs a span from row/column coordinates.
friend bool operator<(const Span &lhs, const Span &rhs)
Orders spans by their start location.
Definition: span.hpp:55
const std::shared_ptr< Source > & source() const
Returns the backing source of this span.
Definition: span.hpp:168
Span(const std::shared_ptr< Source > &source, const Location &start, const Location &end)
Constructs a span from explicit start and end locations within the same source.
friend bool operator>=(const Span &lhs, const Span &rhs)
Greater-than-or-equal comparison derived from <
Definition: span.hpp:91
Location start() const
Returns the starting location of the span.
Definition: span.hpp:175
std::ostream & operator<<(std::ostream &os, const pretty_diagnostics::Span &span)
Streams a human-readable representation of a span for debugging.