// 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/. #include "elna/source/driver.h" namespace elna { namespace source { position make_position(const yy::location& location) { return position{ static_cast(location.begin.line), static_cast(location.begin.column) }; } syntax_error::syntax_error(const std::string& message, const char *input_file, const yy::location& location) : error(input_file, make_position(location)), message(message) { } std::string syntax_error::what() const { return message; } driver::driver(const char *input_file) : input_file(input_file) { } void driver::error(const yy::location& loc, const std::string& message) { m_errors.emplace_back(std::make_unique(message, input_file, loc)); } const std::list>& driver::errors() const noexcept { return m_errors; } std::optional escape_char(char escape) { switch (escape) { case 'n': return std::make_optional('\n'); case 'a': return std::make_optional('\a'); case 'b': return std::make_optional('\b'); case 't': return std::make_optional('\t'); case 'f': return std::make_optional('\f'); case 'r': return std::make_optional('\r'); case 'v': return std::make_optional('\v'); case '\\': return std::make_optional('\\'); case '\'': return std::make_optional('\''); case '"': return std::make_optional('"'); case '?': return std::make_optional('\?'); case '0': return std::make_optional('\0'); default: return std::nullopt; } } } }