New paste Repaste Download
/*
* error.hpp -- respresent an IRC error.
*
* Written on Sunday, 06 May 2024 by oldfashionedcow
*
* Copyright 2024 Cow
*
* This file is part of ircplusplus.
*
* ircplusplus is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ircplusplus 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ircplusplus.  If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <expected>
#include <format>
#include <iostream>
namespace [[gnu::visibility("default")]] ircplusplus {
namespace parser {
enum class FormatterError {
    InvalidFormat,
};
std::ostream &operator<<(std::ostream &os, FormatterError err);
enum class ParserError {
    EmptyCommand,
    NoSeparator,
    MissingKey,
    MissingParameter,
    TrailingSemicolon,
    NonLastParamSpaces,
    NonLastParamColon
};
std::ostream &operator<<(std::ostream &os, ParserError err);
} // namespace parser
} // namespace ircplusplus
template <> struct std::formatter<ircplusplus::parser::FormatterError> {
    template <typename FmtContext>
    FmtContext::iterator format(ircplusplus::parser::FormatterError err, FmtContext &ctx) const {
        switch (err) {
        case ircplusplus::parser::FormatterError::InvalidFormat:
            return std::format_to(ctx.out(), "Invalid format code!");
        default:
            // GCC cannot see that all enum values are covered
            __builtin_unreachable();
        }
    }
};
template <> struct std::formatter<ircplusplus::parser::ParserError> {
    template <typename FmtContext>
    FmtContext::iterator format(ircplusplus::parser::ParserError err, FmtContext &ctx) const {
        switch (err) {
        case ircplusplus::parser::ParserError::EmptyCommand:
            return std::format_to(ctx.out(), "Cannot parse command-less line!");
        case ircplusplus::parser::ParserError::NoSeparator:
            return std::format_to(ctx.out(), "Cannot split line without separator!");
        case ircplusplus::parser::ParserError::MissingKey:
            return std::format_to(ctx.out(), "Cannot parse tags with missing key!");
        case ircplusplus::parser::ParserError::MissingParameter:
            return std::format_to(ctx.out(), "Cannot parse line with missing parameter!");
        case ircplusplus::parser::ParserError::TrailingSemicolon:
            return std::format_to(ctx.out(), "Cannot parse tags with trailing semicolon!");
        case ircplusplus::parser::ParserError::NonLastParamSpaces:
            return std::format_to(ctx.out(), "Non last params cannot have spaces!");
        case ircplusplus::parser::ParserError::NonLastParamColon:
            return std::format_to(ctx.out(), "Non last params cannot start with colon!");
        default:
            // GCC cannot see that all enum values are covered
            __builtin_unreachable();
        }
    }
};
Filename: include/ircplusplus/parser/error.hpp. Size: 3kb. View raw, , hex, or download this file.

This paste expires on 2024-05-14 13:47:19.066139. Pasted through v1-api.