mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-22 07:08:16 +00:00
Added thirdparty: boost library
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2015 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#if !defined(BOOST_SPIRIT_X3__ANNOTATE_ON_SUCCESS_HPP)
|
||||
#define BOOST_SPIRIT_X3__ANNOTATE_ON_SUCCESS_HPP
|
||||
|
||||
#include <boost/spirit/home/x3/support/ast/variant.hpp>
|
||||
#include <boost/spirit/home/x3/support/context.hpp>
|
||||
#include <boost/spirit/home/x3/support/utility/error_reporting.hpp>
|
||||
#include <boost/spirit/home/x3/support/utility/lambda_visitor.hpp>
|
||||
#include <boost/spirit/home/x3/support/traits/is_variant.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace x3
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// The on_success handler tags the AST with the iterator position
|
||||
// for error handling.
|
||||
//
|
||||
// The on_success handler also ties the AST to a vector of iterator
|
||||
// positions for the purpose of subsequent semantic error handling
|
||||
// when the program is being compiled. See x3::position_cache in
|
||||
// x3/support/ast.
|
||||
//
|
||||
// We'll ask the X3's error_handler utility to do these.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct annotate_on_success
|
||||
{
|
||||
template <typename Iterator, typename Context, typename... Types>
|
||||
inline void on_success(Iterator const& first, Iterator const& last
|
||||
, variant<Types...>& ast, Context const& context)
|
||||
{
|
||||
ast.apply_visitor(x3::make_lambda_visitor<void>([&](auto& node)
|
||||
{
|
||||
this->on_success(first, last, node, context);
|
||||
}));
|
||||
}
|
||||
|
||||
template <typename T, typename Iterator, typename Context>
|
||||
inline void on_success(Iterator const& first, Iterator const& last
|
||||
, forward_ast<T>& ast, Context const& context)
|
||||
{
|
||||
this->on_success(first, last, ast.get(), context);
|
||||
}
|
||||
|
||||
template <typename T, typename Iterator, typename Context>
|
||||
inline typename disable_if<traits::is_variant<T>>::type on_success(Iterator const& first, Iterator const& last
|
||||
, T& ast, Context const& context)
|
||||
{
|
||||
auto& error_handler = x3::get<error_handler_tag>(context).get();
|
||||
error_handler.tag(ast, first, last);
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_SPIRIT_X3_ERROR_REPORTING_MAY_19_2014_00405PM)
|
||||
#define BOOST_SPIRIT_X3_ERROR_REPORTING_MAY_19_2014_00405PM
|
||||
|
||||
#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
|
||||
#include <boost/spirit/home/x3/support/utility/utf8.hpp>
|
||||
#include <ostream>
|
||||
|
||||
// Clang-style error handling utilities
|
||||
|
||||
namespace boost { namespace spirit { namespace x3
|
||||
{
|
||||
// tag used to get our error handler from the context
|
||||
struct error_handler_tag;
|
||||
|
||||
template <typename Iterator>
|
||||
class error_handler
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Iterator iterator_type;
|
||||
|
||||
error_handler(
|
||||
Iterator first, Iterator last, std::ostream& err_out
|
||||
, std::string file = "", int tabs = 4)
|
||||
: err_out(err_out)
|
||||
, file(file)
|
||||
, tabs(tabs)
|
||||
, pos_cache(first, last) {}
|
||||
|
||||
typedef void result_type;
|
||||
|
||||
void operator()(Iterator err_pos, std::string const& error_message) const;
|
||||
void operator()(Iterator err_first, Iterator err_last, std::string const& error_message) const;
|
||||
void operator()(position_tagged pos, std::string const& message) const
|
||||
{
|
||||
auto where = pos_cache.position_of(pos);
|
||||
(*this)(where.begin(), where.end(), message);
|
||||
}
|
||||
|
||||
template <typename AST>
|
||||
void tag(AST& ast, Iterator first, Iterator last)
|
||||
{
|
||||
return pos_cache.annotate(ast, first, last);
|
||||
}
|
||||
|
||||
boost::iterator_range<Iterator> position_of(position_tagged pos) const
|
||||
{
|
||||
return pos_cache.position_of(pos);
|
||||
}
|
||||
|
||||
position_cache<std::vector<Iterator>> const& get_position_cache() const
|
||||
{
|
||||
return pos_cache;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void print_file_line(std::size_t line) const;
|
||||
void print_line(Iterator line_start, Iterator last) const;
|
||||
void print_indicator(Iterator& line_start, Iterator last, char ind) const;
|
||||
Iterator get_line_start(Iterator first, Iterator pos) const;
|
||||
std::size_t position(Iterator i) const;
|
||||
|
||||
std::ostream& err_out;
|
||||
std::string file;
|
||||
int tabs;
|
||||
position_cache<std::vector<Iterator>> pos_cache;
|
||||
};
|
||||
|
||||
template <typename Iterator>
|
||||
void error_handler<Iterator>::print_file_line(std::size_t line) const
|
||||
{
|
||||
if (file != "")
|
||||
{
|
||||
err_out << "In file " << file << ", ";
|
||||
}
|
||||
else
|
||||
{
|
||||
err_out << "In ";
|
||||
}
|
||||
|
||||
err_out << "line " << line << ':' << std::endl;
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
void error_handler<Iterator>::print_line(Iterator start, Iterator last) const
|
||||
{
|
||||
auto end = start;
|
||||
while (end != last)
|
||||
{
|
||||
auto c = *end;
|
||||
if (c == '\r' || c == '\n')
|
||||
break;
|
||||
else
|
||||
++end;
|
||||
}
|
||||
typedef typename std::iterator_traits<Iterator>::value_type char_type;
|
||||
std::basic_string<char_type> line{start, end};
|
||||
err_out << x3::to_utf8(line) << std::endl;
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
void error_handler<Iterator>::print_indicator(Iterator& start, Iterator last, char ind) const
|
||||
{
|
||||
for (; start != last; ++start)
|
||||
{
|
||||
auto c = *start;
|
||||
if (c == '\r' || c == '\n')
|
||||
break;
|
||||
else if (c == '\t')
|
||||
for (int i = 0; i < tabs; ++i)
|
||||
err_out << ind;
|
||||
else
|
||||
err_out << ind;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Iterator>
|
||||
inline Iterator error_handler<Iterator>::get_line_start(Iterator first, Iterator pos) const
|
||||
{
|
||||
Iterator latest = first;
|
||||
for (Iterator i = first; i != pos;)
|
||||
if (*i == '\r' || *i == '\n')
|
||||
latest = ++i;
|
||||
else
|
||||
++i;
|
||||
return latest;
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
std::size_t error_handler<Iterator>::position(Iterator i) const
|
||||
{
|
||||
std::size_t line { 1 };
|
||||
typename std::iterator_traits<Iterator>::value_type prev { 0 };
|
||||
|
||||
for (Iterator pos = pos_cache.first(); pos != i; ++pos) {
|
||||
auto c = *pos;
|
||||
switch (c) {
|
||||
case '\n':
|
||||
if (prev != '\r') ++line;
|
||||
break;
|
||||
case '\r':
|
||||
++line;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
prev = c;
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
void error_handler<Iterator>::operator()(
|
||||
Iterator err_pos, std::string const& error_message) const
|
||||
{
|
||||
Iterator first = pos_cache.first();
|
||||
Iterator last = pos_cache.last();
|
||||
|
||||
print_file_line(position(err_pos));
|
||||
err_out << error_message << std::endl;
|
||||
|
||||
Iterator start = get_line_start(first, err_pos);
|
||||
print_line(start, last);
|
||||
print_indicator(start, err_pos, '_');
|
||||
err_out << "^_" << std::endl;
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
void error_handler<Iterator>::operator()(
|
||||
Iterator err_first, Iterator err_last, std::string const& error_message) const
|
||||
{
|
||||
Iterator first = pos_cache.first();
|
||||
Iterator last = pos_cache.last();
|
||||
|
||||
print_file_line(position(err_first));
|
||||
err_out << error_message << std::endl;
|
||||
|
||||
Iterator start = get_line_start(first, err_first);
|
||||
print_line(start, last);
|
||||
print_indicator(start, err_first, ' ');
|
||||
print_indicator(start, err_last, '~');
|
||||
err_out << " <<-- Here" << std::endl;
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
Copyright (c) 2014 Jamboree
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
#ifndef BOOST_SPIRIT_X3_IS_CALLABLE_HPP_INCLUDED
|
||||
#define BOOST_SPIRIT_X3_IS_CALLABLE_HPP_INCLUDED
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace x3 { namespace detail
|
||||
{
|
||||
template <typename Sig, typename Enable = void>
|
||||
struct is_callable_impl : mpl::false_ {};
|
||||
|
||||
template <typename F, typename... A>
|
||||
struct is_callable_impl<F(A...),
|
||||
decltype(void(std::declval<F>()(std::declval<A>()...)))>
|
||||
: mpl::true_
|
||||
{};
|
||||
}}}}
|
||||
|
||||
namespace boost { namespace spirit { namespace x3
|
||||
{
|
||||
template <typename Sig>
|
||||
struct is_callable;
|
||||
|
||||
template <typename F, typename... A>
|
||||
struct is_callable<F(A...)> : detail::is_callable_impl<F(A...)> {};
|
||||
}}}
|
||||
|
||||
|
||||
#endif
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_SPIRIT_X3_LAMBDA_VISITOR_MAY_19_2014_1116AM)
|
||||
#define BOOST_SPIRIT_X3_LAMBDA_VISITOR_MAY_19_2014_1116AM
|
||||
|
||||
namespace boost { namespace spirit { namespace x3
|
||||
{
|
||||
template <typename RT, typename... Lambdas>
|
||||
struct lambda_visitor;
|
||||
|
||||
template <typename RT, typename F, typename... Lambdas>
|
||||
struct lambda_visitor<RT, F, Lambdas...> : F, lambda_visitor<RT, Lambdas...>
|
||||
{
|
||||
typedef lambda_visitor<RT , Lambdas...> base_type;
|
||||
using F::operator();
|
||||
using base_type::operator();
|
||||
lambda_visitor(F f, Lambdas... lambdas)
|
||||
: F(f), base_type(lambdas...)
|
||||
{}
|
||||
};
|
||||
|
||||
template <typename RT, typename F>
|
||||
struct lambda_visitor<RT, F> : F
|
||||
{
|
||||
typedef RT result_type;
|
||||
using F::operator();
|
||||
lambda_visitor(F f)
|
||||
: F(f)
|
||||
{}
|
||||
};
|
||||
|
||||
template <typename RT>
|
||||
struct lambda_visitor<RT>
|
||||
{
|
||||
typedef RT result_type;
|
||||
};
|
||||
|
||||
template <typename RT, typename... Lambdas>
|
||||
lambda_visitor<RT, Lambdas...> make_lambda_visitor(Lambdas... lambdas)
|
||||
{
|
||||
return { lambdas... };
|
||||
}
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2014 Joel de Guzman
|
||||
Copyright (c) 2013 Agustin Berge
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_SPIRIT_X3_SFINAE_MAY_20_2013_0840AM)
|
||||
#define BOOST_SPIRIT_X3_SFINAE_MAY_20_2013_0840AM
|
||||
|
||||
namespace boost { namespace spirit { namespace x3
|
||||
{
|
||||
template <typename Expr, typename T = void>
|
||||
struct disable_if_substitution_failure
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <typename Expr, typename T>
|
||||
struct lazy_disable_if_substitution_failure
|
||||
{
|
||||
typedef typename T::type type;
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2014 Joel de Guzman
|
||||
Copyright (c) 2023 Nikita Kniazev
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_SPIRIT_X3_UC_TYPES_NOVEMBER_23_2008_0840PM)
|
||||
#define BOOST_SPIRIT_X3_UC_TYPES_NOVEMBER_23_2008_0840PM
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
|
||||
namespace boost { namespace spirit { namespace x3
|
||||
{
|
||||
typedef char32_t ucs4_char;
|
||||
typedef char utf8_char;
|
||||
typedef std::basic_string<ucs4_char> ucs4_string;
|
||||
typedef std::basic_string<utf8_char> utf8_string;
|
||||
|
||||
namespace detail {
|
||||
inline void utf8_put_encode(utf8_string& out, ucs4_char x)
|
||||
{
|
||||
// https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf D90
|
||||
if (BOOST_UNLIKELY(x > 0x10FFFFul || (0xD7FFul < x && x < 0xE000ul)))
|
||||
x = 0xFFFDul;
|
||||
|
||||
// Table 3-6. UTF-8 Bit Distribution
|
||||
if (x < 0x80ul) {
|
||||
out.push_back(static_cast<unsigned char>(x));
|
||||
}
|
||||
else if (x < 0x800ul) {
|
||||
out.push_back(static_cast<unsigned char>(0xC0ul + (x >> 6)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + (x & 0x3Ful)));
|
||||
}
|
||||
else if (x < 0x10000ul) {
|
||||
out.push_back(static_cast<unsigned char>(0xE0ul + (x >> 12)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + ((x >> 6) & 0x3Ful)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + (x & 0x3Ful)));
|
||||
}
|
||||
else {
|
||||
out.push_back(static_cast<unsigned char>(0xF0ul + (x >> 18)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + ((x >> 12) & 0x3Ful)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + ((x >> 6) & 0x3Ful)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + (x & 0x3Ful)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
inline utf8_string to_utf8(Char value)
|
||||
{
|
||||
utf8_string result;
|
||||
typedef typename std::make_unsigned<Char>::type UChar;
|
||||
detail::utf8_put_encode(result, static_cast<UChar>(value));
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
inline utf8_string to_utf8(Char const* str)
|
||||
{
|
||||
utf8_string result;
|
||||
typedef typename std::make_unsigned<Char>::type UChar;
|
||||
while (*str)
|
||||
detail::utf8_put_encode(result, static_cast<UChar>(*str++));
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Char, typename Traits, typename Allocator>
|
||||
inline utf8_string
|
||||
to_utf8(std::basic_string<Char, Traits, Allocator> const& str)
|
||||
{
|
||||
utf8_string result;
|
||||
typedef typename std::make_unsigned<Char>::type UChar;
|
||||
for (Char ch : str)
|
||||
detail::utf8_put_encode(result, static_cast<UChar>(ch));
|
||||
return result;
|
||||
}
|
||||
|
||||
// Assume wchar_t content is UTF-16 on MSVC, or mingw/wineg++ with -fshort-wchar
|
||||
#if defined(_MSC_VER) || defined(__SIZEOF_WCHAR_T__) && __SIZEOF_WCHAR_T__ == 2
|
||||
inline utf8_string to_utf8(wchar_t value)
|
||||
{
|
||||
utf8_string result;
|
||||
detail::utf8_put_encode(result, static_cast<std::make_unsigned<wchar_t>::type>(value));
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
inline ucs4_char decode_utf16(wchar_t const*& s)
|
||||
{
|
||||
typedef std::make_unsigned<wchar_t>::type uwchar_t;
|
||||
|
||||
uwchar_t x(*s);
|
||||
if (x < 0xD800ul || x > 0xDFFFul)
|
||||
return x;
|
||||
|
||||
// expected high-surrogate
|
||||
if (BOOST_UNLIKELY((x >> 10) != 0b110110ul))
|
||||
return 0xFFFDul;
|
||||
|
||||
uwchar_t y(*++s);
|
||||
// expected low-surrogate
|
||||
if (BOOST_UNLIKELY((y >> 10) != 0b110111ul))
|
||||
return 0xFFFDul;
|
||||
|
||||
return ((x & 0x3FFul) << 10) + (y & 0x3FFul) + 0x10000ul;
|
||||
}
|
||||
}
|
||||
|
||||
inline utf8_string to_utf8(wchar_t const* str)
|
||||
{
|
||||
utf8_string result;
|
||||
for (ucs4_char c; (c = detail::decode_utf16(str)) != ucs4_char(); ++str)
|
||||
detail::utf8_put_encode(result, c);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Traits, typename Allocator>
|
||||
inline utf8_string
|
||||
to_utf8(std::basic_string<wchar_t, Traits, Allocator> const& str)
|
||||
{
|
||||
return to_utf8(str.c_str());
|
||||
}
|
||||
#endif
|
||||
}}}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user