sapphire/src/Location.h

39 lines
967 B
C++

#pragma once
#include "sapphirepch.h"
/* Struct to represent a location in a file. */
struct Location
{
int line;
int column;
std::string filename;
/* The location at which this location was imported, for error traces in imported files. */
std::shared_ptr<Location> parent = nullptr;
/* Creates a Location with the given parameters. */
Location(int line, int column, std::string filename);
Location(Location&& other);
Location(const Location& other);
Location operator=(const Location& other)
{
return Location(other);
}
~Location();
/* Returns a string of the format FILE:LINE:COL. */
std::string str() const;
/* Advance to the next column in the file. */
void advance();
/* Advance to the next line if provided a newline. */
void pos_from_char(const char& character);
/* Returns a copy of the original Location. */
static Location copy(const Location& other);
};