Skip to content

Commit

Permalink
More fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Nov 17, 2024
1 parent 455ec4a commit 77b08fb
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 6 deletions.
170 changes: 170 additions & 0 deletions include/tao/pegtl/internal/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace TAO_PEGTL_NAMESPACE::internal
template< typename Peek, typename Func, Func Tion >
struct function;

#if defined( __GNUC__ ) || defined( __clang__ )

template< bool E, typename Input, bool ( *Tion )( Input& ) noexcept( E ) >
struct function< void, bool ( * )( Input& ) noexcept( E ), Tion >
{
Expand Down Expand Up @@ -99,6 +101,174 @@ namespace TAO_PEGTL_NAMESPACE::internal
}
};

#else

template< typename Input, bool ( *Tion )( Input& ) noexcept( true ) >
struct function< void, bool ( * )( Input& ) noexcept( true ), Tion >
{
using rule_t = function;
using subs_t = empty_list;

template< typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in ) noexcept( true )
{
return Tion( in );
}
};

template< typename Input, bool ( *Tion )( Input& ) noexcept( false ) >
struct function< void, bool ( * )( Input& ) noexcept( false ), Tion >
{
using rule_t = function;
using subs_t = empty_list;

template< typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in ) noexcept( false )
{
return Tion( in );
}
};

template< typename Input, typename... States, bool ( *Tion )( Input&, States... ) noexcept( true ) >
struct function< void, bool ( * )( Input&, States... ) noexcept( true ), Tion >
{
using rule_t = function;
using subs_t = empty_list;

template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in, States... st ) noexcept( true )
{
return Tion( in, st... );
}
};

template< typename Input, typename... States, bool ( *Tion )( Input&, States... ) noexcept( false ) >
struct function< void, bool ( * )( Input&, States... ) noexcept( false ), Tion >
{
using rule_t = function;
using subs_t = empty_list;

template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in, States... st ) noexcept( false )
{
return Tion( in, st... );
}
};

template< typename Peek, typename Data, bool ( *Tion )( Data ) noexcept( true ) >
struct function< Peek, bool ( * )( Data ) noexcept( true ), Tion >
{
using peek_t = Peek;
// using data_t = typename Peek::data_t;

using rule_t = function;
using subs_t = empty_list;

template< typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in )
{
if( const auto t = Peek::peek( in ) ) {
if( Tion( t.data() ) ) {
in.template consume< function >( t.size() );
return true;
}
}
return false;
}
};

template< typename Peek, typename Data, bool ( *Tion )( Data ) noexcept( false ) >
struct function< Peek, bool ( * )( Data ) noexcept( false ), Tion >
{
using peek_t = Peek;
// using data_t = typename Peek::data_t;

using rule_t = function;
using subs_t = empty_list;

template< typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in )
{
if( const auto t = Peek::peek( in ) ) {
if( Tion( t.data() ) ) {
in.template consume< function >( t.size() );
return true;
}
}
return false;
}
};

template< typename Peek, typename Data, typename... States, bool ( *Tion )( Data, States... ) noexcept( true ) >
struct function< Peek, bool ( * )( Data, States... ) noexcept( true ), Tion >
{
using peek_t = Peek;
// using data_t = typename Peek::data_t;

using rule_t = function;
using subs_t = empty_list;

template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in, States... st )
{
if( const auto t = Peek::peek( in ) ) {
if( Tion( t.data(), st... ) ) {
in.template consume< function >( t.size() );
return true;
}
}
return false;
}
};

template< typename Peek, typename Data, typename... States, bool ( *Tion )( Data, States... ) noexcept( false ) >
struct function< Peek, bool ( * )( Data, States... ) noexcept( false ), Tion >
{
using peek_t = Peek;
// using data_t = typename Peek::data_t;

using rule_t = function;
using subs_t = empty_list;

template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in, States... st )
{
if( const auto t = Peek::peek( in ) ) {
if( Tion( t.data(), st... ) ) {
in.template consume< function >( t.size() );
return true;
}
}
return false;
}
};

#endif

template< typename Peek, typename Func, Func Tion >
inline constexpr bool enable_control< function< Peek, Func, Tion > > = false;

Expand Down
4 changes: 4 additions & 0 deletions include/tao/pegtl/parse_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <type_traits>
#include <utility>

#if !defined( __cpp_exceptions )
#error "Exception support required for tao/pegtl/parse_error.hpp"
#endif

#include "config.hpp"
#include "parse_error_base.hpp"

Expand Down
4 changes: 4 additions & 0 deletions include/tao/pegtl/parse_error_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <string>
#include <string_view>

#if !defined( __cpp_exceptions )
#error "Exception support required for tao/pegtl/parse_error_base.hpp"
#endif

#include "config.hpp"

namespace TAO_PEGTL_NAMESPACE
Expand Down
2 changes: 2 additions & 0 deletions src/example/pegtl/abnf2pegtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

#include <tao/pegtl/contrib/abnf.hpp>
#include <tao/pegtl/contrib/parse_tree.hpp>
#if defined( __cpp_exceptions )
#include <tao/pegtl/control/must_if.hpp>
#endif

namespace TAO_PEGTL_NAMESPACE
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/buffer_cstream_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace TAO_PEGTL_NAMESPACE

void unit_test()
{
const char* const filename = "src/test/pegtl/file_data.txt";
const char* const filename = "src/test/pegtl/data/test_data.txt";
{
std::FILE* stream = internal::read_file_open( filename );
TAO_PEGTL_TEST_ASSERT( stream != nullptr );
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/buffer_istream_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace TAO_PEGTL_NAMESPACE
}
}
#endif
const char* filename = "src/test/pegtl/file_data.txt";
const char* filename = "src/test/pegtl/data/test_data.txt";
{
std::ifstream stream( filename );
static_istream_input< void > in( stream );
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/test/pegtl/internal_file_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace TAO_PEGTL_NAMESPACE
const std::string s = "dummy content\n";
const std::string dummy_content = s + s + s + s + s + s + s + s + s + s + s;

internal::file_mapper mapper( "src/test/pegtl/file_data.txt" );
internal::file_mapper mapper( "src/test/pegtl/data/test_data.txt" );
TAO_PEGTL_TEST_ASSERT( !mapper.empty() );
TAO_PEGTL_TEST_ASSERT( mapper.size() == 154 );
TAO_PEGTL_TEST_ASSERT( std::string_view( mapper.data(), mapper.size() ) == dummy_content );
Expand Down
6 changes: 3 additions & 3 deletions src/test/pegtl/verify_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ namespace TAO_PEGTL_NAMESPACE
}
#endif
{
T in( "src/test/pegtl/file_data.txt" );
TAO_PEGTL_TEST_ASSERT( in.direct_source() == "src/test/pegtl/file_data.txt" );
T in( "src/test/pegtl/data/test_data.txt" );
TAO_PEGTL_TEST_ASSERT( in.direct_source() == "src/test/pegtl/data/test_data.txt" );
TAO_PEGTL_TEST_ASSERT( parse< file_grammar >( in ) );
TAO_PEGTL_TEST_ASSERT( in.direct_source() == "src/test/pegtl/file_data.txt" );
TAO_PEGTL_TEST_ASSERT( in.direct_source() == "src/test/pegtl/data/test_data.txt" );
}
{
T in( TAO_PEGTL_TEST_FILENAME );
Expand Down

0 comments on commit 77b08fb

Please sign in to comment.