sapphire/src/Location.h

35 lines
920 B
C
Raw Normal View History

#pragma once
2022-06-16 13:56:10 +00:00
#include "sapphirepch.h"
/* Struct to represent a location in a file. */
struct Location
{
2022-06-16 13:56:10 +00:00
int line;
int column;
std::string fname;
2022-06-16 13:56:10 +00:00
/* The location at which this location was imported, for error traces in imported files. */
std::shared_ptr<Location> parent = nullptr;
2022-06-16 13:56:10 +00:00
/* Creates a Location with the given parameters. */
Location(int ln, int col, std::string file);
2022-06-16 13:56:10 +00:00
~Location();
2022-06-16 13:56:10 +00:00
/* Returns a string of the format FILE:LINE:COL. */
std::string str() const;
/* Returns a string of the format (FILE:LINE:COL). */
std::string paren_str() const;
2022-06-16 13:56:10 +00:00
/* Advance to the next column in the file. */
void advance();
2022-06-16 13:56:10 +00:00
/* Advance to the next line if provided a newline. */
void pos_from_char(const char& character);
2022-06-16 13:56:10 +00:00
void operator=(const Location& other);
2022-06-16 13:56:10 +00:00
/* Copies the other location into this one. */
void copy(const Location& other);
};