Location
class Location
Represents a location within a file, including the file name, start position, and end position.
Line and column numbers are 1-based, and 0 indicates that it is not specified.
class Position
A position within a file.
Line and column numbers are 1-based, and 0 indicates that it is not specified.
constructor Position()
Create an empty position.
constructor Position(size_t line_number, size_t column)
Create a position.
| Parameter | Description |
|---|---|
line_number |
The line number, or TYPE: |
column |
The column number, or TYPE: |
method size_t column_index()
Get the 0-based column index of the position. If the column number is not specified, 0 is returned.
| Returns | Description |
|---|---|
size_t |
The 0-based column index of the position, or |
method bool empty()
Check if the position is empty (i.e. has no line number).
| Returns | Description |
|---|---|
bool |
method size_t line_index()
Get the 0-based line index of the position. If the line number is not specified, 0 is returned.
| Returns | Description |
|---|---|
size_t |
The 0-based line index of the position, or |
method operator bool()
method bool operator!=(const Position &other)
Check if two positions are not equal.
| Parameter | Description |
|---|---|
other |
The position to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method bool operator<(const Position &other)
Check if this position is before another position.
| Parameter | Description |
|---|---|
other |
The position to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method bool operator<=(const Position &other)
Check if this position is before or equal to another position.
| Parameter | Description |
|---|---|
other |
The position to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method bool operator==(const Position &other)
Check if two positions are equal.
| Parameter | Description |
|---|---|
other |
The position to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method bool operator>(const Position &other)
Check if this position is after another position.
| Parameter | Description |
|---|---|
other |
The position to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method bool operator>=(const Position &other)
Check if this position is after or equal to another position.
| Parameter | Description |
|---|---|
other |
The position to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method std::string to_string()
Convert the position to a string representation.
| Returns | Description |
|---|---|
std::string |
The string representation of the position. |
member size_t column
The column number, or 0 if the column number is not specified.
member size_t line_number
The line number, or 0 if the line number is not specified.
constructor Location()
Empty location.
constructor Location(const Location &a, const Location &b)
Create a location that covers the range from the start of one location to the end of another location. If the two locations are in different files, the second location will be ignored.
| Parameter | Description |
|---|---|
a |
The first location. TYPE: |
b |
The second location. TYPE: |
constructor Location(Symbol file, size_t line_number, size_t start_column, size_t end_column)
Create a location.
| Parameter | Description |
|---|---|
file |
TYPE: |
line_number |
The line number, or TYPE: |
start_column |
The starting column number, or TYPE: |
end_column |
The ending column number, or TYPE: |
constructor Location(Symbol file, size_t start_line_number, size_t start_column, size_t end_line_number, size_t end_column)
Create a location with a file name, line number, and column range.
| Parameter | Description |
|---|---|
file |
The file symbol. TYPE: |
start_line_number |
The starting line number, or TYPE: |
start_column |
The starting column number, or TYPE: |
end_line_number |
The ending line number, or TYPE: |
end_column |
The ending column number, or TYPE: |
constructor Location(const std::string &file_name)
Create a location with only a file name.
| Parameter | Description |
|---|---|
file_name |
The name of the file. TYPE: |
method bool empty()
Check if the location is empty (i.e. has no file).
| Returns | Description |
|---|---|
bool |
|
method void extend(size_t amount)
Extend the location by a number of columns.
| Parameter | Description |
|---|---|
amount |
The number of columns to extend the location by. TYPE: |
method void extend(const Location &other)
Extend the location to include another location. If the other location is not in the same file, it will be ignored.
| Parameter | Description |
|---|---|
other |
TYPE: |
method bool is_one_line()
Check if the location is within a single line.
| Returns | Description |
|---|---|
bool |
|
method bool operator!=(const Location &other)
Check if two locations are not equal.
| Parameter | Description |
|---|---|
other |
TYPE: |
| Returns | Description |
|---|---|
bool |
method bool operator<(const Location &other)
Check if this location is before another location.
Locations are ordered first by line number, then by column number. Locations in different files are not comparable.
| Parameter | Description |
|---|---|
other |
The location to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method bool operator==(const Location &other)
Check if two locations are equal.
| Parameter | Description |
|---|---|
other |
The location to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method bool operator>(const Location &other)
Check if this location is after another location.
Locations are ordered first by line number, then by column number. Locations in different files are not comparable.
| Parameter | Description |
|---|---|
other |
The location to compare with. TYPE: |
| Returns | Description |
|---|---|
bool |
|
method std::string to_string()
Convert the location to a string representation of the start of the location.
| Returns | Description |
|---|---|
std::string |
A string representation of the start of the location. |
method size_t width()
Get the width of the location in columns.
If the location is not on a single line, or no start or end column is known, 0 is returned.
| Returns | Description |
|---|---|
size_t |
The width of the location in columns, or |
member end
The position where the location ends.
member file
The file.
member start
The position where the location starts.