elna/boot/driver.cc

79 lines
1.8 KiB
C++
Raw Normal View History

2024-12-27 10:51:46 +01:00
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
2025-01-31 09:46:17 +01:00
#include "elna/boot/driver.h"
2024-12-21 14:05:27 +01:00
2024-12-23 13:54:11 +01:00
namespace elna
{
2025-01-31 09:46:17 +01:00
namespace boot
2024-12-21 14:05:27 +01:00
{
position make_position(const yy::location& location)
{
2025-02-07 22:12:59 +01:00
position result;
result.line = static_cast<std::size_t>(location.begin.line);
result.column = static_cast<std::size_t>(location.begin.column);
return result;
2024-12-21 14:05:27 +01:00
}
syntax_error::syntax_error(const std::string& message,
2024-12-27 10:51:46 +01:00
const char *input_file, const yy::location& location)
2024-12-21 14:05:27 +01:00
: error(input_file, make_position(location)), message(message)
{
}
std::string syntax_error::what() const
{
return message;
}
2024-12-27 10:51:46 +01:00
driver::driver(const char *input_file)
2024-12-21 14:05:27 +01:00
: input_file(input_file)
{
}
void driver::error(const yy::location& loc, const std::string& message)
{
2025-02-07 22:12:59 +01:00
m_errors.emplace_back(new boot::syntax_error(message, input_file, loc));
2024-12-21 14:05:27 +01:00
}
const std::list<std::unique_ptr<struct error>>& driver::errors() const noexcept
{
return m_errors;
}
2025-01-24 11:41:14 +01:00
2025-02-07 22:12:59 +01:00
char escape_char(char escape)
2025-01-24 11:41:14 +01:00
{
switch (escape)
{
case 'n':
2025-02-07 22:12:59 +01:00
return '\n';
2025-01-24 11:41:14 +01:00
case 'a':
2025-02-07 22:12:59 +01:00
return '\a';
2025-01-24 11:41:14 +01:00
case 'b':
2025-02-07 22:12:59 +01:00
return '\b';
2025-01-24 11:41:14 +01:00
case 't':
2025-02-07 22:12:59 +01:00
return '\t';
2025-01-24 11:41:14 +01:00
case 'f':
2025-02-07 22:12:59 +01:00
return '\f';
2025-01-24 11:41:14 +01:00
case 'r':
2025-02-07 22:12:59 +01:00
return '\r';
2025-01-24 11:41:14 +01:00
case 'v':
2025-02-07 22:12:59 +01:00
return '\v';
2025-01-24 11:41:14 +01:00
case '\\':
2025-02-07 22:12:59 +01:00
return '\\';
2025-01-24 11:41:14 +01:00
case '\'':
2025-02-07 22:12:59 +01:00
return '\'';
2025-01-24 11:41:14 +01:00
case '"':
2025-02-07 22:12:59 +01:00
return '"';
2025-01-24 11:41:14 +01:00
case '?':
2025-02-07 22:12:59 +01:00
return '\?';
2025-01-24 11:41:14 +01:00
case '0':
2025-02-07 22:12:59 +01:00
return '\0';
2025-01-24 11:41:14 +01:00
default:
2025-02-07 22:12:59 +01:00
return escape_invalid_char;
2025-01-24 11:41:14 +01:00
}
}
2024-12-21 14:05:27 +01:00
}
2024-12-23 13:54:11 +01:00
}