Include the filename in the error messages
This commit is contained in:
@ -267,8 +267,9 @@ namespace elna::source
|
||||
assert(false);
|
||||
}
|
||||
|
||||
unexpected_character::unexpected_character(const std::string& character, const source::position position)
|
||||
: error(position), character(character)
|
||||
unexpected_character::unexpected_character(const std::string& character, const std::filesystem::path& path,
|
||||
const source::position position)
|
||||
: error(path, position), character(character)
|
||||
{
|
||||
}
|
||||
|
||||
@ -281,8 +282,8 @@ namespace elna::source
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
unexpected_token::unexpected_token(const token& token)
|
||||
: error(token.position()), m_token(token)
|
||||
unexpected_token::unexpected_token(const token& token, const std::filesystem::path& path)
|
||||
: error(path, token.position()), m_token(token)
|
||||
{
|
||||
}
|
||||
|
||||
@ -291,8 +292,9 @@ namespace elna::source
|
||||
return "Unexpected token " + m_token.to_string();
|
||||
}
|
||||
|
||||
lexer::lexer(std::vector<token>&& tokens, const position last_position)
|
||||
: tokens(std::move(tokens)), iterator(this->tokens.cbegin()), eof(token(token::type::eof, last_position))
|
||||
lexer::lexer(std::vector<token>&& tokens, const position last_position, const std::filesystem::path& path)
|
||||
: tokens(std::move(tokens)), iterator(this->tokens.cbegin()), eof(token(token::type::eof, last_position)),
|
||||
source_file(path)
|
||||
{
|
||||
}
|
||||
|
||||
@ -328,7 +330,7 @@ namespace elna::source
|
||||
|
||||
void lexer::add_error(const token& expected)
|
||||
{
|
||||
m_errors.push_back(std::make_unique<unexpected_token>(expected));
|
||||
m_errors.push_back(std::make_unique<unexpected_token>(expected, this->source_file));
|
||||
}
|
||||
|
||||
std::optional<std::reference_wrapper<const token>> lexer::advance(const token::type token_type)
|
||||
@ -367,7 +369,7 @@ namespace elna::source
|
||||
return m_errors;
|
||||
}
|
||||
|
||||
result<lexer> lex(const std::string& buffer)
|
||||
result<lexer> lex(const std::string& buffer, const std::filesystem::path& path)
|
||||
{
|
||||
std::vector<token> tokens;
|
||||
auto [iterator, text_end] = text_iterators(buffer);
|
||||
@ -492,10 +494,10 @@ namespace elna::source
|
||||
}
|
||||
else
|
||||
{
|
||||
return result<lexer>(unexpected_character{ std::string{ *iterator }, iterator.position() });
|
||||
return result<lexer>(unexpected_character{ std::string{ *iterator }, path, iterator.position() });
|
||||
}
|
||||
++iterator;
|
||||
}
|
||||
return result<lexer>(std::in_place, std::move(tokens), iterator.position());
|
||||
return result<lexer>(std::in_place, std::move(tokens), iterator.position(), path);
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace elna::source
|
||||
{
|
||||
error::error(const position position)
|
||||
: m_position(position)
|
||||
error::error(const std::filesystem::path& path, const position position)
|
||||
: m_position(position), m_path(path)
|
||||
{
|
||||
}
|
||||
|
||||
@ -17,8 +17,14 @@ namespace elna::source
|
||||
return this->m_position.column;
|
||||
}
|
||||
|
||||
name_collision::name_collision(const std::string& name, const position current, const position previous)
|
||||
: error(current), name(name), previous(previous)
|
||||
const std::filesystem::path& error::path() const noexcept
|
||||
{
|
||||
return this->m_path;
|
||||
}
|
||||
|
||||
name_collision::name_collision(const std::string& name, const std::filesystem::path& path,
|
||||
const position current, const position previous)
|
||||
: error(path, current), name(name), previous(previous)
|
||||
{
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user