7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 11:21:41 +00:00

PEGTL 2.x->3.x

This commit is contained in:
Ola Rinta-Koski 2022-01-10 23:22:23 +00:00 committed by Seth Hillbrand
parent d5faac7614
commit dcab2833b8
193 changed files with 13856 additions and 12477 deletions
common
include
thirdparty/pegtl
LICENSELICENSE_1_0.txtpegtl.hpp
pegtl
apply_mode.hppargv_input.hppascii.hppbuffer_input.hppchange_action.hppchange_action_and_state.hppchange_action_and_states.hppchange_control.hppchange_state.hppchange_states.hppconfig.hpp
contrib
cstream_input.hppdemangle.hppdisable_action.hppdiscard_input.hppdiscard_input_on_failure.hppdiscard_input_on_success.hppenable_action.hppeol.hppfile_input.hpp
internal
istream_input.hppmatch.hppmemory_input.hppmmap_input.hppmust_if.hppnormal.hppnothing.hppparse.hppparse_error.hppposition.hppread_input.hpprequire_apply.hpprequire_apply0.hpprewind_mode.hpprules.hppstring_input.hpptracking_mode.hpptype_list.hpputf8.hppversion.hppvisit.hpp

View File

@ -37,13 +37,13 @@ std::string NODE::typeString() const
{
std::stringstream os;
if( is<MARKUP::subscript>() ) os << "SUBSCRIPT";
else if( is<MARKUP::superscript>() ) os << "SUPERSCRIPT";
else if( is<MARKUP::anyString>() ) os << "ANYSTRING";
else if( is<MARKUP::anyStringWithinBraces>() ) os << "ANYSTRINGWITHINBRACES";
else if( is<MARKUP::varNamespaceName>() ) os << "VARNAMESPACENAME";
else if( is<MARKUP::varName>() ) os << "VARNAME";
else os << "other";
if( is_type<MARKUP::subscript>() ) os << "SUBSCRIPT";
else if( is_type<MARKUP::superscript>() ) os << "SUPERSCRIPT";
else if( is_type<MARKUP::anyString>() ) os << "ANYSTRING";
else if( is_type<MARKUP::anyStringWithinBraces>() ) os << "ANYSTRINGWITHINBRACES";
else if( is_type<MARKUP::varNamespaceName>() ) os << "VARNAMESPACENAME";
else if( is_type<MARKUP::varName>() ) os << "VARNAME";
else os << "other";
return os.str();
}
@ -53,7 +53,7 @@ std::string NODE::asString() const
{
std::stringstream os;
os << name(); // << "{" << typeString() << "}";
os << type;
if( has_content() )
os << " \"" << string() << "\"";

View File

@ -22,6 +22,7 @@
#define MARKUP_PARSER_H
#include <pegtl.hpp>
#include <pegtl/contrib/parse_tree.hpp>
#include <iostream>
#include <string>
#include <utf8.h>
@ -41,9 +42,9 @@ struct NODE : parse_tree::basic_node<NODE>
std::string typeString() const;
bool isOverbar() const { return is<MARKUP::overbar>(); }
bool isSubscript() const { return is<MARKUP::subscript>(); }
bool isSuperscript() const { return is<MARKUP::superscript>(); }
bool isOverbar() const { return is_type<MARKUP::overbar>(); }
bool isSubscript() const { return is_type<MARKUP::subscript>(); }
bool isSuperscript() const { return is_type<MARKUP::superscript>(); }
};
struct varPrefix : string<'$', '{'> {};

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2007-2020 Dr. Colin Hirsch and Daniel Frey
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

23
thirdparty/pegtl/LICENSE_1_0.txt vendored Normal file
View File

@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

File diff suppressed because it is too large Load Diff

20
thirdparty/pegtl/pegtl/apply_mode.hpp vendored Normal file
View File

@ -0,0 +1,20 @@
// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_APPLY_MODE_HPP
#define TAO_PEGTL_APPLY_MODE_HPP
#include "config.hpp"
namespace TAO_PEGTL_NAMESPACE
{
enum class apply_mode : bool
{
action = true,
nothing = false
};
} // namespace TAO_PEGTL_NAMESPACE
#endif

50
thirdparty/pegtl/pegtl/argv_input.hpp vendored Normal file
View File

@ -0,0 +1,50 @@
// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_ARGV_INPUT_HPP
#define TAO_PEGTL_ARGV_INPUT_HPP
#include <cstddef>
#include <sstream>
#include <string>
#include <utility>
#include "config.hpp"
#include "eol.hpp"
#include "memory_input.hpp"
#include "tracking_mode.hpp"
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
[[nodiscard]] inline std::string make_argv_source( const std::size_t argn )
{
std::ostringstream oss;
oss << "argv[" << argn << ']';
return std::move( oss ).str();
}
} // namespace internal
template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf >
struct argv_input
: memory_input< P, Eol >
{
template< typename T >
argv_input( char** argv, const std::size_t argn, T&& in_source )
: memory_input< P, Eol >( static_cast< const char* >( argv[ argn ] ), std::forward< T >( in_source ) )
{}
argv_input( char** argv, const std::size_t argn )
: argv_input( argv, argn, internal::make_argv_source( argn ) )
{}
};
template< typename... Ts >
argv_input( Ts&&... ) -> argv_input<>;
} // namespace TAO_PEGTL_NAMESPACE
#endif

55
thirdparty/pegtl/pegtl/ascii.hpp vendored Normal file
View File

@ -0,0 +1,55 @@
// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_ASCII_HPP
#define TAO_PEGTL_ASCII_HPP
#include "config.hpp"
#include "internal/result_on_found.hpp"
#include "internal/rules.hpp"
namespace TAO_PEGTL_NAMESPACE
{
inline namespace ascii
{
// clang-format off
struct alnum : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z', '0', '9' > {};
struct alpha : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z' > {};
struct any : internal::any< internal::peek_char > {};
struct blank : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > {};
struct digit : internal::range< internal::result_on_found::success, internal::peek_char, '0', '9' > {};
struct ellipsis : internal::string< '.', '.', '.' > {};
template< char... Cs > struct forty_two : internal::rep< 42, internal::one< internal::result_on_found::success, internal::peek_char, Cs... > > {};
struct identifier_first : internal::identifier_first {};
struct identifier_other : internal::identifier_other {};
struct identifier : internal::identifier {};
template< char... Cs > struct istring : internal::istring< Cs... > {};
template< char... Cs > struct keyword : internal::seq< internal::string< Cs... >, internal::not_at< internal::identifier_other > > { static_assert( sizeof...( Cs ) > 0 ); };
struct lower : internal::range< internal::result_on_found::success, internal::peek_char, 'a', 'z' > {};
template< char... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_char, Cs... > {};
template< char Lo, char Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_char, Lo, Hi > {};
struct nul : internal::one< internal::result_on_found::success, internal::peek_char, char( 0 ) > {};
struct odigit : internal::range< internal::result_on_found::success, internal::peek_char, '0', '7' > {};
template< char... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_char, Cs... > {};
struct print : internal::range< internal::result_on_found::success, internal::peek_char, char( 32 ), char( 126 ) > {};
template< char Lo, char Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_char, Lo, Hi > {};
template< char... Cs > struct ranges : internal::ranges< internal::peek_char, Cs... > {};
struct seven : internal::range< internal::result_on_found::success, internal::peek_char, char( 0 ), char( 127 ) > {};
struct shebang : internal::seq< internal::string< '#', '!' >, internal::until< internal::eolf > > {};
struct space : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\n', '\r', '\t', '\v', '\f' > {};
template< char... Cs > struct string : internal::string< Cs... > {};
template< char C > struct three : internal::string< C, C, C > {};
template< char C > struct two : internal::string< C, C > {};
struct upper : internal::range< internal::result_on_found::success, internal::peek_char, 'A', 'Z' > {};
struct xdigit : internal::ranges< internal::peek_char, '0', '9', 'a', 'f', 'A', 'F' > {};
// clang-format on
} // namespace ascii
} // namespace TAO_PEGTL_NAMESPACE
#include "internal/pegtl_string.hpp"
#endif

227
thirdparty/pegtl/pegtl/buffer_input.hpp vendored Normal file
View File

@ -0,0 +1,227 @@
// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_BUFFER_INPUT_HPP
#define TAO_PEGTL_BUFFER_INPUT_HPP
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
#include <string>
#if defined( __cpp_exceptions )
#include <stdexcept>
#else
#include <cstdio>
#include <exception>
#endif
#include "config.hpp"
#include "eol.hpp"
#include "memory_input.hpp"
#include "position.hpp"
#include "tracking_mode.hpp"
#include "internal/action_input.hpp"
#include "internal/bump.hpp"
#include "internal/iterator.hpp"
#include "internal/marker.hpp"
namespace TAO_PEGTL_NAMESPACE
{
template< typename Reader, typename Eol = eol::lf_crlf, typename Source = std::string, std::size_t Chunk = 64 >
class buffer_input
{
public:
using reader_t = Reader;
using eol_t = Eol;
using source_t = Source;
using iterator_t = internal::iterator;
using action_t = internal::action_input< buffer_input >;
static constexpr std::size_t chunk_size = Chunk;
static constexpr tracking_mode tracking_mode_v = tracking_mode::eager;
template< typename T, typename... As >
buffer_input( T&& in_source, const std::size_t maximum, As&&... as )
: m_reader( std::forward< As >( as )... ),
m_maximum( maximum + Chunk ),
m_buffer( new char[ maximum + Chunk ] ),
m_current( m_buffer.get() ),
m_end( m_buffer.get() ),
m_source( std::forward< T >( in_source ) )
{
static_assert( Chunk, "zero chunk size not implemented" );
assert( m_maximum > maximum ); // Catches overflow; change to >= when zero chunk size is implemented.
}
buffer_input( const buffer_input& ) = delete;
buffer_input( buffer_input&& ) = delete;
~buffer_input() = default;
buffer_input& operator=( const buffer_input& ) = delete;
buffer_input& operator=( buffer_input&& ) = delete;
[[nodiscard]] bool empty()
{
require( 1 );
return m_current.data == m_end;
}
[[nodiscard]] std::size_t size( const std::size_t amount )
{
require( amount );
return buffer_occupied();
}
[[nodiscard]] const char* current() const noexcept
{
return m_current.data;
}
[[nodiscard]] const char* end( const std::size_t amount )
{
require( amount );
return m_end;
}
[[nodiscard]] std::size_t byte() const noexcept
{
return m_current.byte;
}
[[nodiscard]] std::size_t line() const noexcept
{
return m_current.line;
}
[[nodiscard]] std::size_t column() const noexcept
{
return m_current.column;
}
[[nodiscard]] const Source& source() const noexcept
{
return m_source;
}
[[nodiscard]] char peek_char( const std::size_t offset = 0 ) const noexcept
{
return m_current.data[ offset ];
}
[[nodiscard]] std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept
{
return static_cast< std::uint8_t >( peek_char( offset ) );
}
void bump( const std::size_t in_count = 1 ) noexcept
{
internal::bump( m_current, in_count, Eol::ch );
}
void bump_in_this_line( const std::size_t in_count = 1 ) noexcept
{
internal::bump_in_this_line( m_current, in_count );
}
void bump_to_next_line( const std::size_t in_count = 1 ) noexcept
{
internal::bump_to_next_line( m_current, in_count );
}
void discard() noexcept
{
if( m_current.data > m_buffer.get() + Chunk ) {
const auto s = m_end - m_current.data;
std::memmove( m_buffer.get(), m_current.data, s );
m_current.data = m_buffer.get();
m_end = m_buffer.get() + s;
}
}
void require( const std::size_t amount )
{
if( m_current.data + amount <= m_end ) {
return;
}
if( m_current.data + amount > m_buffer.get() + m_maximum ) {
#if defined( __cpp_exceptions )
throw std::overflow_error( "require() beyond end of buffer" );
#else
std::fputs( "overflow error: require() beyond end of buffer\n", stderr );
std::terminate();
#endif
}
if( const auto r = m_reader( m_end, ( std::min )( buffer_free_after_end(), ( std::max )( amount - buffer_occupied(), Chunk ) ) ) ) {
m_end += r;
}
}
template< rewind_mode M >
[[nodiscard]] internal::marker< iterator_t, M > mark() noexcept
{
return internal::marker< iterator_t, M >( m_current );
}
[[nodiscard]] TAO_PEGTL_NAMESPACE::position position( const iterator_t& it ) const
{
return TAO_PEGTL_NAMESPACE::position( it, m_source );
}
[[nodiscard]] TAO_PEGTL_NAMESPACE::position position() const
{
return position( m_current );
}
[[nodiscard]] const iterator_t& iterator() const noexcept
{
return m_current;
}
[[nodiscard]] std::size_t buffer_capacity() const noexcept
{
return m_maximum;
}
[[nodiscard]] std::size_t buffer_occupied() const noexcept
{
assert( m_end >= m_current.data );
return std::size_t( m_end - m_current.data );
}
[[nodiscard]] std::size_t buffer_free_before_current() const noexcept
{
assert( m_current.data >= m_buffer.get() );
return std::size_t( m_current.data - m_buffer.get() );
}
[[nodiscard]] std::size_t buffer_free_after_end() const noexcept
{
assert( m_buffer.get() + m_maximum >= m_end );
return std::size_t( m_buffer.get() + m_maximum - m_end );
}
private:
Reader m_reader;
std::size_t m_maximum;
std::unique_ptr< char[] > m_buffer;
iterator_t m_current;
char* m_end;
const Source m_source;
public:
std::size_t private_depth = 0;
};
} // namespace TAO_PEGTL_NAMESPACE
#endif

View File

@ -0,0 +1,39 @@
// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CHANGE_ACTION_HPP
#define TAO_PEGTL_CHANGE_ACTION_HPP
#include <type_traits>
#include "apply_mode.hpp"
#include "config.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace TAO_PEGTL_NAMESPACE
{
template< template< typename... > class NewAction >
struct change_action
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
static_assert( !std::is_same_v< Action< void >, NewAction< void > >, "old and new action class templates are identical" );
return Control< Rule >::template match< A, M, NewAction, Control >( in, st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
#endif

View File

@ -0,0 +1,72 @@
// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CHANGE_ACTION_AND_STATE_HPP
#define TAO_PEGTL_CHANGE_ACTION_AND_STATE_HPP
#include <type_traits>
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
#include "internal/dependent_false.hpp"
namespace TAO_PEGTL_NAMESPACE
{
template< template< typename... > class NewAction, typename NewState >
struct change_action_and_state
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
static_assert( !std::is_same_v< Action< void >, NewAction< void > >, "old and new action class templates are identical" );
if constexpr( std::is_constructible_v< NewState, const ParseInput&, States... > ) {
NewState s( static_cast< const ParseInput& >( in ), st... );
if( Control< Rule >::template match< A, M, NewAction, Control >( in, s ) ) {
if constexpr( A == apply_mode::action ) {
Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... );
}
return true;
}
return false;
}
else if constexpr( std::is_default_constructible_v< NewState > ) {
NewState s;
if( Control< Rule >::template match< A, M, NewAction, Control >( in, s ) ) {
if constexpr( A == apply_mode::action ) {
Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... );
}
return true;
}
return false;
}
else {
static_assert( internal::dependent_false< NewState >, "unable to instantiate new state" );
}
}
template< typename ParseInput,
typename... States >
static void success( const ParseInput& in, NewState& s, States&&... st ) noexcept( noexcept( s.success( in, st... ) ) )
{
s.success( in, st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
#endif

View File

@ -0,0 +1,63 @@
// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CHANGE_ACTION_AND_STATES_HPP
#define TAO_PEGTL_CHANGE_ACTION_AND_STATES_HPP
#include <tuple>
#include <utility>
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace TAO_PEGTL_NAMESPACE
{
template< template< typename... > class NewAction, typename... NewStates >
struct change_action_and_states
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
std::size_t... Ns,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( std::index_sequence< Ns... > /*unused*/, ParseInput& in, States&&... st )
{
auto t = std::tie( st... );
if( Control< Rule >::template match< A, M, NewAction, Control >( in, std::get< Ns >( t )... ) ) {
if constexpr( A == apply_mode::action ) {
Action< Rule >::success( static_cast< const ParseInput& >( in ), st... );
}
return true;
}
return false;
}
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
static_assert( !std::is_same_v< Action< void >, NewAction< void > >, "old and new action class templates are identical" );
return match< Rule, A, M, Action, Control >( std::index_sequence_for< NewStates... >(), in, NewStates()..., st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
#endif

View File

@ -0,0 +1,37 @@
// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CHANGE_CONTROL_HPP
#define TAO_PEGTL_CHANGE_CONTROL_HPP
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace TAO_PEGTL_NAMESPACE
{
template< template< typename... > class NewControl >
struct change_control
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, NewControl >( in, st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
#endif

70
thirdparty/pegtl/pegtl/change_state.hpp vendored Normal file
View File

@ -0,0 +1,70 @@
// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CHANGE_STATE_HPP
#define TAO_PEGTL_CHANGE_STATE_HPP
#include <type_traits>
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
#include "internal/dependent_false.hpp"
namespace TAO_PEGTL_NAMESPACE
{
template< typename NewState >
struct change_state
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
if constexpr( std::is_constructible_v< NewState, const ParseInput&, States... > ) {
NewState s( static_cast< const ParseInput& >( in ), st... );
if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s ) ) {
if constexpr( A == apply_mode::action ) {
Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... );
}
return true;
}
return false;
}
else if constexpr( std::is_default_constructible_v< NewState > ) {
NewState s;
if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s ) ) {
if constexpr( A == apply_mode::action ) {
Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... );
}
return true;
}
return false;
}
else {
static_assert( internal::dependent_false< NewState >, "unable to instantiate new state" );
}
}
template< typename ParseInput,
typename... States >
static void success( const ParseInput& in, NewState& s, States&&... st ) noexcept( noexcept( s.success( in, st... ) ) )
{
s.success( in, st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
#endif

View File

@ -0,0 +1,62 @@
// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CHANGE_STATES_HPP
#define TAO_PEGTL_CHANGE_STATES_HPP
#include <tuple>
#include <utility>
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace TAO_PEGTL_NAMESPACE
{
template< typename... NewStates >
struct change_states
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
std::size_t... Ns,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( std::index_sequence< Ns... > /*unused*/, ParseInput& in, States&&... st )
{
auto t = std::tie( st... );
if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, std::get< Ns >( t )... ) ) {
if constexpr( A == apply_mode::action ) {
Action< Rule >::success( static_cast< const ParseInput& >( in ), st... );
}
return true;
}
return false;
}
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
return match< Rule, A, M, Action, Control >( std::index_sequence_for< NewStates... >(), in, NewStates()..., st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
#endif

14
thirdparty/pegtl/pegtl/config.hpp vendored Normal file
View File

@ -0,0 +1,14 @@
// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CONFIG_HPP
#define TAO_PEGTL_CONFIG_HPP
#if defined( TAO_PEGTL_NAMESPACE )
#pragma message( "TAO_PEGTL_NAMESPACE is deprecated" )
#else
#define TAO_PEGTL_NAMESPACE tao::pegtl
#endif
#endif

36
thirdparty/pegtl/pegtl/contrib/abnf.hpp vendored Normal file
View File

@ -0,0 +1,36 @@
// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CONTRIB_ABNF_HPP
#define TAO_PEGTL_CONTRIB_ABNF_HPP
#include "../config.hpp"
#include "../internal/rules.hpp"
namespace TAO_PEGTL_NAMESPACE::abnf
{
// Core ABNF rules according to RFC 5234, Appendix B
// clang-format off
struct ALPHA : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z' > {};
struct BIT : internal::one< internal::result_on_found::success, internal::peek_char, '0', '1' > {};
struct CHAR : internal::range< internal::result_on_found::success, internal::peek_char, char( 1 ), char( 127 ) > {};
struct CR : internal::one< internal::result_on_found::success, internal::peek_char, '\r' > {};
struct CRLF : internal::string< '\r', '\n' > {};
struct CTL : internal::ranges< internal::peek_char, char( 0 ), char( 31 ), char( 127 ) > {};
struct DIGIT : internal::range< internal::result_on_found::success, internal::peek_char, '0', '9' > {};
struct DQUOTE : internal::one< internal::result_on_found::success, internal::peek_char, '"' > {};
struct HEXDIG : internal::ranges< internal::peek_char, '0', '9', 'a', 'f', 'A', 'F' > {};
struct HTAB : internal::one< internal::result_on_found::success, internal::peek_char, '\t' > {};
struct LF : internal::one< internal::result_on_found::success, internal::peek_char, '\n' > {};
struct LWSP : internal::star< internal::sor< internal::string< '\r', '\n' >, internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > >, internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > > {};
struct OCTET : internal::any< internal::peek_char > {};
struct SP : internal::one< internal::result_on_found::success, internal::peek_char, ' ' > {};
struct VCHAR : internal::range< internal::result_on_found::success, internal::peek_char, char( 33 ), char( 126 ) > {};
struct WSP : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > {};
// clang-format on
} // namespace TAO_PEGTL_NAMESPACE::abnf
#endif

View File

@ -0,0 +1,70 @@
// Copyright (c) 2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CONTRIB_ADD_STATE_HPP
#define TAO_PEGTL_CONTRIB_ADD_STATE_HPP
#include <type_traits>
#include "../apply_mode.hpp"
#include "../config.hpp"
#include "../match.hpp"
#include "../nothing.hpp"
#include "../rewind_mode.hpp"
#include "../internal/dependent_false.hpp"
namespace TAO_PEGTL_NAMESPACE
{
template< typename AddState >
struct add_state
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
if constexpr( std::is_constructible_v< AddState, const ParseInput&, States... > ) {
AddState s( static_cast< const ParseInput& >( in ), st... );
if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s, st... ) ) {
if constexpr( A == apply_mode::action ) {
Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... );
}
return true;
}
return false;
}
else if constexpr( std::is_default_constructible_v< AddState > ) {
AddState s;
if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s, st... ) ) {
if constexpr( A == apply_mode::action ) {
Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... );
}
return true;
}
return false;
}
else {
static_assert( internal::dependent_false< AddState >, "unable to instantiate new state" );
}
}
template< typename ParseInput,
typename... States >
static void success( const ParseInput& in, AddState& s, States&&... st ) noexcept( noexcept( s.success( in, st... ) ) )
{
s.success( in, st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
#endif

View File

@ -0,0 +1,68 @@
// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CONTRIB_ALPHABET_HPP
#define TAO_PEGTL_CONTRIB_ALPHABET_HPP
#include "../config.hpp"
namespace TAO_PEGTL_NAMESPACE::alphabet
{
static const char a = 'a';
static const char b = 'b';
static const char c = 'c';
static const char d = 'd';
static const char e = 'e';
static const char f = 'f';
static const char g = 'g';
static const char h = 'h';
static const char i = 'i';
static const char j = 'j';
static const char k = 'k';
static const char l = 'l';
static const char m = 'm';
static const char n = 'n';
static const char o = 'o';
static const char p = 'p';
static const char q = 'q';
static const char r = 'r';
static const char s = 's';
static const char t = 't';
static const char u = 'u';
static const char v = 'v';
static const char w = 'w';
static const char x = 'x';
static const char y = 'y';
static const char z = 'z';
static const char A = 'A'; // NOLINT(readability-identifier-naming)
static const char B = 'B'; // NOLINT(readability-identifier-naming)
static const char C = 'C'; // NOLINT(readability-identifier-naming)
static const char D = 'D'; // NOLINT(readability-identifier-naming)
static const char E = 'E'; // NOLINT(readability-identifier-naming)
static const char F = 'F'; // NOLINT(readability-identifier-naming)
static const char G = 'G'; // NOLINT(readability-identifier-naming)
static const char H = 'H'; // NOLINT(readability-identifier-naming)
static const char I = 'I'; // NOLINT(readability-identifier-naming)
static const char J = 'J'; // NOLINT(readability-identifier-naming)
static const char K = 'K'; // NOLINT(readability-identifier-naming)
static const char L = 'L'; // NOLINT(readability-identifier-naming)
static const char M = 'M'; // NOLINT(readability-identifier-naming)
static const char N = 'N'; // NOLINT(readability-identifier-naming)
static const char O = 'O'; // NOLINT(readability-identifier-naming)
static const char P = 'P'; // NOLINT(readability-identifier-naming)
static const char Q = 'Q'; // NOLINT(readability-identifier-naming)
static const char R = 'R'; // NOLINT(readability-identifier-naming)
static const char S = 'S'; // NOLINT(readability-identifier-naming)
static const char T = 'T'; // NOLINT(readability-identifier-naming)
static const char U = 'U'; // NOLINT(readability-identifier-naming)
static const char V = 'V'; // NOLINT(readability-identifier-naming)
static const char W = 'W'; // NOLINT(readability-identifier-naming)
static const char X = 'X'; // NOLINT(readability-identifier-naming)
static const char Y = 'Y'; // NOLINT(readability-identifier-naming)
static const char Z = 'Z'; // NOLINT(readability-identifier-naming)
} // namespace TAO_PEGTL_NAMESPACE::alphabet
#endif

View File

@ -0,0 +1,190 @@
// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CONTRIB_ANALYZE_HPP
#define TAO_PEGTL_CONTRIB_ANALYZE_HPP
#include <cassert>
#include <cstddef>
#include <iostream>
#include <map>
#include <set>
#include <stdexcept>
#include <string_view>
#include <utility>
#include <vector>
#include "../config.hpp"
#include "../demangle.hpp"
#include "analyze_traits.hpp"
#include "internal/set_stack_guard.hpp"
#include "internal/vector_stack_guard.hpp"
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct analyze_entry
{
explicit analyze_entry( const analyze_type in_type ) noexcept
: type( in_type )
{}
const analyze_type type;
std::vector< std::string_view > subs;
};
class analyze_cycles_impl
{
public:
analyze_cycles_impl( analyze_cycles_impl&& ) = delete;
analyze_cycles_impl( const analyze_cycles_impl& ) = delete;
~analyze_cycles_impl() = default;
analyze_cycles_impl& operator=( analyze_cycles_impl&& ) = delete;
analyze_cycles_impl& operator=( const analyze_cycles_impl& ) = delete;
[[nodiscard]] std::size_t problems()
{
for( auto& i : m_entries ) {
assert( m_trace.empty() );
assert( m_stack.empty() );
m_results[ i.first ] = work( i, false );
}
// The number of problems returned is not very informative as some problems will be found multiple times.
return m_problems;
}
template< typename Rule >
[[nodiscard]] bool consumes() const
{
// The name "consumes" is a shortcut for "the analyze cycles algorithm could prove that this rule always consumes when it succeeds".
return m_results.at( demangle< Rule >() );
}
protected:
explicit analyze_cycles_impl( const int verbose ) noexcept
: m_verbose( verbose ),
m_problems( 0 )
{}
[[nodiscard]] const std::pair< const std::string_view, analyze_entry >& find( const std::string_view name ) const noexcept
{
const auto iter = m_entries.find( name );
assert( iter != m_entries.end() );
return *iter;
}
[[nodiscard]] bool work( const std::pair< const std::string_view, analyze_entry >& entry, const bool accum )
{
if( const auto g = set_stack_guard( m_stack, entry.first ) ) {
const auto v = vector_stack_guard( m_trace, entry.first );
switch( entry.second.type ) {
case analyze_type::any: {
bool a = false;
for( const auto& r : entry.second.subs ) {
a = a || work( find( r ), accum || a );
}
return true;
}
case analyze_type::opt: {
bool a = false;
for( const auto& r : entry.second.subs ) {
a = a || work( find( r ), accum || a );
}
return false;
}
case analyze_type::seq: {
bool a = false;
for( const auto& r : entry.second.subs ) {
a = a || work( find( r ), accum || a );
}
return a;
}
case analyze_type::sor: {
bool a = true;
for( const auto& r : entry.second.subs ) {
a = a && work( find( r ), accum );
}
return a;
}
}
assert( false ); // LCOV_EXCL_LINE
}
assert( !m_trace.empty() );
if( !accum ) {
++m_problems;
// LCOV_EXCL_START
if( ( m_verbose >= 0 ) && ( m_trace.front() == entry.first ) ) {
for( const auto& r : m_trace ) {
if( r < entry.first ) {
return accum;
}
}
std::cerr << "WARNING: Possible cycle without progress at rule " << entry.first << std::endl;
if( m_verbose > 0 ) {
for( const auto& r : m_trace ) {
std::cerr << "- involved (transformed) rule: " << r << std::endl;
}
}
}
// LCOV_EXCL_STOP
}
return accum;
}
const int m_verbose;
std::size_t m_problems;
std::set< std::string_view > m_stack;
std::vector< std::string_view > m_trace;
std::map< std::string_view, bool > m_results;
std::map< std::string_view, analyze_entry > m_entries;
};
template< typename Name >
std::string_view analyze_insert( std::map< std::string_view, analyze_entry >& entry )
{
using Traits = analyze_traits< Name, typename Name::rule_t >;
const auto [ i, b ] = entry.try_emplace( demangle< Name >(), Traits::type_v );
if( b ) {
analyze_insert_impl( typename Traits::subs_t(), i->second.subs, entry );
}
return i->first;
}
template< typename... Subs >
void analyze_insert_impl( type_list< Subs... > /*unused*/, std::vector< std::string_view >& subs, std::map< std::string_view, analyze_entry >& entry )
{
( subs.emplace_back( analyze_insert< Subs >( entry ) ), ... );
}
template< typename Grammar >
struct analyze_cycles
: analyze_cycles_impl
{
explicit analyze_cycles( const int verbose )
: analyze_cycles_impl( verbose )
{
analyze_insert< Grammar >( m_entries );
}
};
} // namespace internal
template< typename Grammar >
[[nodiscard]] std::size_t analyze( const int verbose = 1 )
{
return internal::analyze_cycles< Grammar >( verbose ).problems();
}
} // namespace TAO_PEGTL_NAMESPACE
#endif

View File

@ -0,0 +1,278 @@
// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CONTRIB_ANALYZE_TRAITS_HPP
#define TAO_PEGTL_CONTRIB_ANALYZE_TRAITS_HPP
#include <type_traits>
#include "../ascii.hpp"
#include "../config.hpp"
#include "../rules.hpp"
#include "../type_list.hpp"
#include "forward.hpp"
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
enum class analyze_type
{
any, // Consumption-on-success is always true; assumes bounded repetition of conjunction of sub-rules.
opt, // Consumption-on-success not necessarily true; assumes bounded repetition of conjunction of sub-rules.
seq, // Consumption-on-success depends on consumption of (non-zero bounded repetition of) conjunction of sub-rules.
sor // Consumption-on-success depends on consumption of (non-zero bounded repetition of) disjunction of sub-rules.
};
} // namespace internal
template< typename... Rules >
struct analyze_any_traits
{
static constexpr internal::analyze_type type_v = internal::analyze_type::any;
using subs_t = type_list< Rules... >;
};
template< typename... Rules >
struct analyze_opt_traits
{
static constexpr internal::analyze_type type_v = internal::analyze_type::opt;
using subs_t = type_list< Rules... >;
};
template< typename... Rules >
struct analyze_seq_traits
{
static constexpr internal::analyze_type type_v = internal::analyze_type::seq;
using subs_t = type_list< Rules... >;
};
template< typename... Rules >
struct analyze_sor_traits
{
static constexpr internal::analyze_type type_v = internal::analyze_type::sor;
using subs_t = type_list< Rules... >;
};
template< typename Name, template< typename... > class Action, typename... Rules >
struct analyze_traits< Name, internal::action< Action, Rules... > >
: analyze_traits< Name, typename seq< Rules... >::rule_t >
{};
template< typename Name, typename Peek >
struct analyze_traits< Name, internal::any< Peek > >
: analyze_any_traits<>
{};
template< typename Name, typename... Actions >
struct analyze_traits< Name, internal::apply< Actions... > >
: analyze_opt_traits<>
{};
template< typename Name, typename... Actions >
struct analyze_traits< Name, internal::apply0< Actions... > >
: analyze_opt_traits<>
{};
template< typename Name, typename... Rules >
struct analyze_traits< Name, internal::at< Rules... > >
: analyze_traits< Name, typename opt< Rules... >::rule_t >
{};
template< typename Name >
struct analyze_traits< Name, internal::bof >
: analyze_opt_traits<>
{};
template< typename Name >
struct analyze_traits< Name, internal::bol >
: analyze_opt_traits<>
{};
template< typename Name, unsigned Cnt >
struct analyze_traits< Name, internal::bytes< Cnt > >
: std::conditional_t< ( Cnt != 0 ), analyze_any_traits<>, analyze_opt_traits<> >
{};
template< typename Name, template< typename... > class Control, typename... Rules >
struct analyze_traits< Name, internal::control< Control, Rules... > >
: analyze_traits< Name, typename seq< Rules... >::rule_t >
{};
template< typename Name, typename... Rules >
struct analyze_traits< Name, internal::disable< Rules... > >
: analyze_traits< Name, typename seq< Rules... >::rule_t >
{};
template< typename Name >
struct analyze_traits< Name, internal::discard >
: analyze_opt_traits<>
{};
template< typename Name, typename... Rules >
struct analyze_traits< Name, internal::enable< Rules... > >
: analyze_traits< Name, typename seq< Rules... >::rule_t >
{};
template< typename Name >
struct analyze_traits< Name, internal::eof >
: analyze_opt_traits<>
{};
template< typename Name >
struct analyze_traits< Name, internal::eol >
: analyze_any_traits<>
{};
template< typename Name >
struct analyze_traits< Name, internal::eolf >
: analyze_opt_traits<>
{};
template< typename Name >
struct analyze_traits< Name, internal::failure >
: analyze_any_traits<>
{};
template< typename Name, typename Rule, typename... Actions >
struct analyze_traits< Name, internal::if_apply< Rule, Actions... > >
: analyze_traits< Name, typename Rule::rule_t >
{};
template< typename Name, typename Cond, typename Then, typename Else >
struct analyze_traits< Name, internal::if_then_else< Cond, Then, Else > >
: analyze_traits< Name, typename sor< seq< Cond, Then >, Else >::rule_t >
{};
template< typename Name, char... Cs >
struct analyze_traits< Name, internal::istring< Cs... > >
: std::conditional_t< ( sizeof...( Cs ) != 0 ), analyze_any_traits<>, analyze_opt_traits<> >
{};
template< typename Name, typename... Rules >
struct analyze_traits< Name, internal::not_at< Rules... > >
: analyze_traits< Name, typename opt< Rules... >::rule_t >
{};
template< typename Name, internal::result_on_found R, typename Peek, typename Peek::data_t... Cs >
struct analyze_traits< Name, internal::one< R, Peek, Cs... > >
: analyze_any_traits<>
{};
template< typename Name, typename Rule, typename... Rules >
struct analyze_traits< Name, internal::opt< Rule, Rules... > >
: analyze_opt_traits< Rule, Rules... >
{};
template< typename Name, typename... Rules >
struct analyze_traits< Name, internal::plus< Rules... > >
: analyze_traits< Name, typename seq< Rules..., opt< Name > >::rule_t >
{};
template< typename Name, internal::result_on_found R, typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi >
struct analyze_traits< Name, internal::range< R, Peek, Lo, Hi > >
: analyze_any_traits<>
{};
template< typename Name, typename Peek, typename Peek::data_t... Cs >
struct analyze_traits< Name, internal::ranges< Peek, Cs... > >
: analyze_any_traits<>
{};
template< typename Name, typename Head, typename... Rules >
struct analyze_traits< Name, internal::rematch< Head, Rules... > >
: analyze_traits< Name, typename sor< Head, sor< seq< Rules, any >... > >::rule_t > // TODO: Correct (enough)?
{};
template< typename Name, unsigned Cnt, typename... Rules >
struct analyze_traits< Name, internal::rep< Cnt, Rules... > >
: analyze_traits< Name, std::conditional_t< ( Cnt != 0 ), typename seq< Rules... >::rule_t, typename opt< Rules... >::rule_t > >
{};
template< typename Name, unsigned Min, unsigned Max, typename... Rules >
struct analyze_traits< Name, internal::rep_min_max< Min, Max, Rules... > >
: analyze_traits< Name, std::conditional_t< ( Min != 0 ), typename seq< Rules... >::rule_t, typename opt< Rules... >::rule_t > >
{};
template< typename Name, unsigned Max, typename... Rules >
struct analyze_traits< Name, internal::rep_opt< Max, Rules... > >
: analyze_traits< Name, typename opt< Rules... >::rule_t >
{};
template< typename Name, unsigned Amount >
struct analyze_traits< Name, internal::require< Amount > >
: analyze_opt_traits<>
{};
template< typename Name, typename Rule, typename... Rules >
struct analyze_traits< Name, internal::seq< Rule, Rules... > >
: analyze_seq_traits< Rule, Rules... >
{};
template< typename Name, typename Rule, typename... Rules >
struct analyze_traits< Name, internal::sor< Rule, Rules... > >
: analyze_sor_traits< Rule, Rules... >
{};
template< typename Name, typename... Rules >
struct analyze_traits< Name, internal::star< Rules... > >
: analyze_traits< Name, typename opt< Rules..., Name >::rule_t >
{};
template< typename Name, typename State, typename... Rules >
struct analyze_traits< Name, internal::state< State, Rules... > >
: analyze_traits< Name, typename seq< Rules... >::rule_t >
{};
template< typename Name, char... Cs >
struct analyze_traits< Name, internal::string< Cs... > >
: std::conditional_t< ( sizeof...( Cs ) != 0 ), analyze_any_traits<>, analyze_opt_traits<> >
{};
template< typename Name >
struct analyze_traits< Name, internal::success >
: analyze_opt_traits<>
{};
template< typename Name, typename Cond >
struct analyze_traits< Name, internal::until< Cond > >
: analyze_traits< Name, typename Cond::rule_t >
{};
template< typename Name, typename Cond, typename... Rules >
struct analyze_traits< Name, internal::until< Cond, Rules... > >
: analyze_traits< Name, typename seq< star< Rules... >, Cond >::rule_t >
{};
#if defined( __cpp_exceptions )
template< typename Name, typename Cond, typename... Rules >
struct analyze_traits< Name, internal::if_must< true, Cond, Rules... > >
: analyze_traits< Name, typename opt< Cond, Rules... >::rule_t >
{};
template< typename Name, typename Cond, typename... Rules >
struct analyze_traits< Name, internal::if_must< false, Cond, Rules... > >
: analyze_traits< Name, typename seq< Cond, Rules... >::rule_t >
{};
template< typename Name, typename... Rules >
struct analyze_traits< Name, internal::must< Rules... > >
: analyze_traits< Name, typename seq< Rules... >::rule_t >
{};
template< typename Name, typename T >
struct analyze_traits< Name, internal::raise< T > >
: analyze_any_traits<>
{};
template< typename Name, typename Exception, typename... Rules >
struct analyze_traits< Name, internal::try_catch_type< Exception, Rules... > >
: analyze_traits< Name, typename seq< Rules... >::rule_t >
{};
#endif
} // namespace TAO_PEGTL_NAMESPACE
#endif

View File

@ -0,0 +1,56 @@
// Copyright (c) 2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CONTRIB_CHECK_BYTES_HPP
#define TAO_PEGTL_CONTRIB_CHECK_BYTES_HPP
#include "../apply_mode.hpp"
#include "../config.hpp"
#include "../match.hpp"
#include "../nothing.hpp"
#include "../rewind_mode.hpp"
#if defined( __cpp_exceptions )
#include "../parse_error.hpp"
#else
#include <cstdio>
#include <exception>
#endif
namespace TAO_PEGTL_NAMESPACE
{
template< std::size_t Maximum >
struct check_bytes
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
static bool match( ParseInput& in, States&&... st )
{
const auto* start = in.current();
if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ) ) {
if( std::size_t( in.current() - start ) > Maximum ) {
#if defined( __cpp_exceptions )
throw TAO_PEGTL_NAMESPACE::parse_error( "maximum allowed rule consumption exceeded", in );
#else
std::fputs( "maximum allowed rule consumption exceeded\n", stderr );
std::terminate();
#endif
}
return true;
}
return false;
}
};
} // namespace TAO_PEGTL_NAMESPACE
#endif

View File

@ -0,0 +1,94 @@
// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CONTRIB_CONTROL_ACTION_HPP
#define TAO_PEGTL_CONTRIB_CONTROL_ACTION_HPP
#include <utility>
#include "../config.hpp"
#include "../match.hpp"
#include "../nothing.hpp"
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename, typename Rule, template< typename... > class Action, typename ParseInput, typename... States >
inline constexpr bool action_has_unwind = false;
template< typename Rule, template< typename... > class Action, typename ParseInput, typename... States >
inline constexpr bool action_has_unwind< decltype( (void)Action< Rule >::unwind( std::declval< const ParseInput& >(), std::declval< States&& >()... ) ), Rule, Action, ParseInput, States... > = true;
} // namespace internal
struct control_action
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
#if defined( __cpp_exceptions )
if constexpr( internal::action_has_unwind< void, Rule, Action, ParseInput, States... > ) {
try {
return control_action::match_impl< Rule, A, M, Action, Control >( in, st... );
}
catch( ... ) {
Action< Rule >::unwind( const_cast< const ParseInput& >( in ), st... );
throw;
}
}
else {
return control_action::match_impl< Rule, A, M, Action, Control >( in, st... );
}
#else
return control_action::match_impl< Rule, A, M, Action, Control >( in, st... );
#endif
}
template< typename ParseInput, typename... States >
static void start( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept
{}
template< typename ParseInput, typename... States >
static void success( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept
{}
template< typename ParseInput, typename... States >
static void failure( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept
{}
private:
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match_impl( ParseInput& in, States&&... st )
{
Action< Rule >::start( const_cast< const ParseInput& >( in ), st... );
if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ) ) {
Action< Rule >::success( const_cast< const ParseInput& >( in ), st... );
return true;
}
Action< Rule >::failure( const_cast< const ParseInput& >( in ), st... );
return false;
}
};
} // namespace TAO_PEGTL_NAMESPACE
#endif

View File

@ -0,0 +1,152 @@
// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CONTRIB_COVERAGE_HPP
#define TAO_PEGTL_CONTRIB_COVERAGE_HPP
#include <cstddef>
#include <map>
#include <string_view>
#include <vector>
#include "state_control.hpp"
#include "../apply_mode.hpp"
#include "../config.hpp"
#include "../demangle.hpp"
#include "../normal.hpp"
#include "../nothing.hpp"
#include "../parse.hpp"
#include "../rewind_mode.hpp"
#include "../type_list.hpp"
#include "../visit.hpp"
namespace TAO_PEGTL_NAMESPACE
{
struct coverage_info
{
std::size_t start = 0;
std::size_t success = 0;
std::size_t failure = 0;
std::size_t unwind = 0;
std::size_t raise = 0;
};
struct coverage_entry
: coverage_info
{
std::map< std::string_view, coverage_info > branches;
};
using coverage_result = std::map< std::string_view, coverage_entry >;
namespace internal
{
template< typename Rule >
struct coverage_insert
{
static void visit( std::map< std::string_view, coverage_entry >& map )
{
visit_branches( map.try_emplace( demangle< Rule >() ).first->second.branches, typename Rule::subs_t() );
}
template< typename... Ts >
static void visit_branches( std::map< std::string_view, coverage_info >& branches, type_list< Ts... > /*unused*/ )
{
( branches.try_emplace( demangle< Ts >() ), ... );
}
};
struct coverage_state
{
template< typename Rule >
static constexpr bool enable = true;
explicit coverage_state( coverage_result& in_result )
: result( in_result )
{}
coverage_result& result;
std::vector< std::string_view > stack;
template< typename Rule, typename ParseInput, typename... States >
void start( const ParseInput& /*unused*/, States&&... /*unused*/ )
{
const auto name = demangle< Rule >();
++result.at( name ).start;
if( !stack.empty() ) {
++result.at( stack.back() ).branches.at( name ).start;
}
stack.push_back( name );
}
template< typename Rule, typename ParseInput, typename... States >
void success( const ParseInput& /*unused*/, States&&... /*unused*/ )
{
stack.pop_back();
const auto name = demangle< Rule >();
++result.at( name ).success;
if( !stack.empty() ) {
++result.at( stack.back() ).branches.at( name ).success;
}
}
template< typename Rule, typename ParseInput, typename... States >
void failure( const ParseInput& /*unused*/, States&&... /*unused*/ )
{
stack.pop_back();
const auto name = demangle< Rule >();
++result.at( name ).failure;
if( !stack.empty() ) {
++result.at( stack.back() ).branches.at( name ).failure;
}
}
template< typename Rule, typename ParseInput, typename... States >
void raise( const ParseInput& /*unused*/, States&&... /*unused*/ )
{
const auto name = demangle< Rule >();
++result.at( name ).raise;
if( !stack.empty() ) {
++result.at( stack.back() ).branches.at( name ).raise;
}
}
template< typename Rule, typename ParseInput, typename... States >
void unwind( const ParseInput& /*unused*/, States&&... /*unused*/ )
{
stack.pop_back();
const auto name = demangle< Rule >();
++result.at( name ).unwind;
if( !stack.empty() ) {
++result.at( stack.back() ).branches.at( name ).unwind;
}
}
template< typename Rule, typename ParseInput, typename... States >
void apply( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept
{}
template< typename Rule, typename ParseInput, typename... States >
void apply0( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept
{}
};
} // namespace internal
template< typename Rule,
template< typename... > class Action = nothing,
template< typename... > class Control = normal,
typename ParseInput,
typename... States >
bool coverage( ParseInput&& in, coverage_result& result, States&&... st )
{
internal::coverage_state state( result );
visit< Rule, internal::coverage_insert >( state.result ); // Fill map with all sub-rules of the grammar.
return parse< Rule, Action, state_control< Control >::template type >( in, st..., state );
}
} // namespace TAO_PEGTL_NAMESPACE
#endif

View File

@ -0,0 +1,17 @@
// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#ifndef TAO_PEGTL_CONTRIB_FORWARD_HPP
#define TAO_PEGTL_CONTRIB_FORWARD_HPP
#include "../config.hpp"
namespace TAO_PEGTL_NAMESPACE
{
template< typename Name, typename Rule, typename = void >
struct analyze_traits;
} // namespace TAO_PEGTL_NAMESPACE
#endif

Some files were not shown because too many files have changed in this diff Show More