Location and Position
Interface
-
class Location
Represents the location in a parsed document.
- Tested:
LocationTest
Public Functions
-
Location() = default
Creates an undefined location.
Can be tested with
isUndefined()
.
-
inline explicit Location(SourceIdentifierPtr sourceIdentifier, const Position position = {}) noexcept
Create a new location object.
- Parameters:
sourceIdentifier – The source identifier.
position – The position in the document.
-
inline bool operator==(const Location &other) const noexcept
Compare this location to another for equality.
- Parameters:
other – The location to compare.
- Returns:
true
if both the source identifier and position are equal.
-
inline bool operator!=(const Location &other) const noexcept
Compare this location to another for inequality.
- Parameters:
other – The location to compare.
- Returns:
true
if the locations are not equal,false
otherwise.
-
inline bool isUndefined() const noexcept
Test if this location is undefined.
- Returns:
true
if undefined,false
otherwise.
-
inline const SourceIdentifierPtr &sourceIdentifier() const noexcept
The source identifier for this location.
-
class Position
A position inside a document.
Starting with line 1 and column 1. If the line or column are undefined, they are set to -1.
- Tested:
PositionTest
Public Functions
-
inline constexpr Position(int line, int column)
Create a new position with the given line and column.
- Parameters:
line – The line.
column – The column.
-
Position() = default
Default constructor.
-
~Position() = default
Default destructor.
-
inline bool operator==(const Position &other) const noexcept
Compare this position to another for equality.
- Parameters:
other – The other position to compare.
- Returns:
true
if both line and column are identical.
-
inline bool operator!=(const Position &other) const noexcept
Compare this position to another for inequality.
- Parameters:
other – The other position to compare.
- Returns:
true
if positions differ,false
otherwise.
-
inline int line() const noexcept
The line, starting from 1
-
inline int column() const noexcept
The column, starting from 1
-
inline bool isUndefined() const noexcept
Test if this position is undefined.
-
inline void nextLine() noexcept
Increase the line and reset the column.
-
inline void nextColumn() noexcept
Increase the column.