2020-08-30 00:25:41 +02:00
|
|
|
// The Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) The Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_SPIRIT_PARSE_H
|
|
|
|
|
2022-05-14 22:23:09 +02:00
|
|
|
// This file is not part of the IRCd standard include list (stdinc.h) because
|
|
|
|
// it involves extremely expensive boost headers for creating formal spirit
|
|
|
|
// grammars. This file is automatically included in the spirit.h group.
|
|
|
|
|
2022-07-04 23:22:18 +02:00
|
|
|
namespace ircd::spirit
|
2020-08-30 00:25:41 +02:00
|
|
|
{
|
2022-05-08 00:16:44 +02:00
|
|
|
template<class rule,
|
2020-08-30 00:25:41 +02:00
|
|
|
class... attr>
|
2022-05-08 00:16:44 +02:00
|
|
|
bool parse(const char *&start, const char *const &stop, rule&&, attr&&...);
|
2020-08-30 00:25:41 +02:00
|
|
|
|
|
|
|
template<class parent_error,
|
2020-10-31 09:15:57 +01:00
|
|
|
size_t error_show_max = 128,
|
2022-05-08 00:16:44 +02:00
|
|
|
class rule,
|
2020-08-30 00:25:41 +02:00
|
|
|
class... attr>
|
2022-05-08 00:16:44 +02:00
|
|
|
bool parse(const char *&start, const char *const &stop, rule&&, attr&&...);
|
2022-05-14 23:22:18 +02:00
|
|
|
|
2022-05-08 00:16:44 +02:00
|
|
|
template<class rule,
|
2022-05-14 23:22:18 +02:00
|
|
|
class... attr>
|
2022-05-08 00:16:44 +02:00
|
|
|
bool parse(std::nothrow_t, const char *&start, const char *const &stop, rule&&, attr&&...) noexcept;
|
2022-07-04 23:22:18 +02:00
|
|
|
}
|
2020-08-30 00:25:41 +02:00
|
|
|
|
2022-05-14 23:22:18 +02:00
|
|
|
/// Execute the parse. The start pointer is advanced upon successful execution.
|
|
|
|
/// Failures must not throw: If the grammar contains any epsilon expressions or
|
|
|
|
/// callbacks which throw it is UB. This overload exists to force suppression
|
|
|
|
/// of EH from the base of a complex/opaque rule tree.
|
2022-05-08 00:16:44 +02:00
|
|
|
template<class rule,
|
2022-05-14 23:22:18 +02:00
|
|
|
class... attr>
|
|
|
|
[[using gnu: always_inline, gnu_inline, artificial]]
|
|
|
|
extern inline bool
|
|
|
|
ircd::spirit::parse(std::nothrow_t,
|
|
|
|
const char *&start,
|
|
|
|
const char *const &stop,
|
2022-05-08 00:16:44 +02:00
|
|
|
rule&& r,
|
2022-05-14 23:22:18 +02:00
|
|
|
attr&&... a)
|
|
|
|
noexcept try
|
|
|
|
{
|
2022-05-08 00:16:44 +02:00
|
|
|
return ircd::spirit::parse(start, stop, std::forward<rule>(r), std::forward<attr>(a)...);
|
2022-05-14 23:22:18 +02:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Execute the parse. The start pointer is advanced upon successful execution.
|
|
|
|
/// Failures may throw depending on the grammar. Boost's expectation_failure is
|
|
|
|
/// translated into our expectation_failure describing the failure.
|
2020-08-30 00:25:41 +02:00
|
|
|
template<class parent_error,
|
|
|
|
size_t error_show_max,
|
2022-05-08 00:16:44 +02:00
|
|
|
class rule,
|
2020-08-30 00:25:41 +02:00
|
|
|
class... attr>
|
|
|
|
[[using gnu: always_inline, gnu_inline, artificial]]
|
|
|
|
extern inline bool
|
|
|
|
ircd::spirit::parse(const char *&start,
|
|
|
|
const char *const &stop,
|
2022-05-08 00:16:44 +02:00
|
|
|
rule&& r,
|
2020-08-30 00:25:41 +02:00
|
|
|
attr&&... a)
|
|
|
|
try
|
|
|
|
{
|
2022-05-08 00:16:44 +02:00
|
|
|
return ircd::spirit::parse(start, stop, std::forward<rule>(r), std::forward<attr>(a)...);
|
2020-08-30 00:25:41 +02:00
|
|
|
}
|
|
|
|
catch(const qi::expectation_failure<const char *> &e)
|
|
|
|
{
|
|
|
|
throw expectation_failure<parent_error>
|
|
|
|
{
|
2020-10-31 09:15:57 +01:00
|
|
|
e, error_show_max
|
2020-08-30 00:25:41 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-14 23:22:18 +02:00
|
|
|
/// Low-level qi::parse entry point. Throws boost's qi::expectation_failure;
|
|
|
|
/// Try not to allow this exception to escape the calling unit.
|
2022-05-08 00:16:44 +02:00
|
|
|
template<class rule,
|
2020-08-30 00:25:41 +02:00
|
|
|
class... attr>
|
|
|
|
[[using gnu: always_inline, gnu_inline, artificial]]
|
|
|
|
extern inline bool
|
|
|
|
ircd::spirit::parse(const char *&start,
|
|
|
|
const char *const &stop,
|
2022-05-08 00:16:44 +02:00
|
|
|
rule&& r,
|
2020-08-30 00:25:41 +02:00
|
|
|
attr&&... a)
|
|
|
|
{
|
2022-05-08 00:16:44 +02:00
|
|
|
return qi::parse(start, stop, std::forward<rule>(r), std::forward<attr>(a)...);
|
2020-08-30 00:25:41 +02:00
|
|
|
}
|