elna/boot/driver.cc

93 lines
2.3 KiB
C++
Raw Normal View History

/* Parsing driver.
Copyright (C) 2025 Free Software Foundation, Inc.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
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
}