forked from taocpp/PEGTL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
142 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2023 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_INTERNAL_PARTIAL_HPP | ||
#define TAO_PEGTL_INTERNAL_PARTIAL_HPP | ||
|
||
#include "enable_control.hpp" | ||
|
||
#include "../apply_mode.hpp" | ||
#include "../rewind_mode.hpp" | ||
#include "../type_list.hpp" | ||
|
||
namespace tao::pegtl::internal | ||
{ | ||
template< typename... Rules > | ||
struct partial | ||
{ | ||
using rule_t = partial; | ||
using subs_t = type_list< Rules... >; | ||
|
||
template< apply_mode A, | ||
rewind_mode, | ||
template< typename... > | ||
class Action, | ||
template< typename... > | ||
class Control, | ||
typename ParseInput, | ||
typename... States > | ||
[[nodiscard]] static bool match( ParseInput& in, States&&... st ) | ||
{ | ||
(void)( Control< Rules >::template match< A, rewind_mode::required, Action, Control >( in, st... ) && ... ); | ||
return true; | ||
} | ||
}; | ||
|
||
template< typename... Rules > | ||
inline constexpr bool enable_control< partial< Rules... > > = false; | ||
|
||
} // namespace tao::pegtl::internal | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) 2023 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) | ||
|
||
#include "test.hpp" | ||
|
||
#include "verify_meta.hpp" | ||
#include "verify_rule.hpp" | ||
|
||
namespace tao::pegtl | ||
{ | ||
template< typename Rule > | ||
struct my_action | ||
{}; | ||
|
||
template<> | ||
struct my_action< eof > | ||
{ | ||
static void apply0( bool& b ) | ||
{ | ||
b = true; | ||
} | ||
}; | ||
|
||
void unit_test() | ||
{ | ||
verify_meta< partial< eof >, internal::partial< eof >, eof >(); | ||
verify_meta< partial< eof, any >, internal::partial< eof, any >, eof, any >(); | ||
|
||
verify_analyze< partial< any > >( __LINE__, __FILE__, false, false ); | ||
verify_analyze< partial< eof > >( __LINE__, __FILE__, false, false ); | ||
|
||
verify_rule< partial< one< 'a' > > >( __LINE__, __FILE__, "", result_type::success, 0 ); | ||
verify_rule< partial< one< 'a' > > >( __LINE__, __FILE__, "a", result_type::success, 0 ); | ||
verify_rule< partial< one< 'a' > > >( __LINE__, __FILE__, "aa", result_type::success, 1 ); | ||
verify_rule< partial< one< 'a' > > >( __LINE__, __FILE__, "ab", result_type::success, 1 ); | ||
verify_rule< partial< one< 'a' > > >( __LINE__, __FILE__, "ba", result_type::success, 2 ); | ||
|
||
verify_rule< partial< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "", result_type::success, 0 ); | ||
verify_rule< partial< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", result_type::success, 0 ); | ||
verify_rule< partial< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ab", result_type::success, 0 ); | ||
verify_rule< partial< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aba", result_type::success, 1 ); | ||
verify_rule< partial< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abab", result_type::success, 2 ); | ||
verify_rule< partial< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bab", result_type::success, 3 ); | ||
verify_rule< partial< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "cb", result_type::success, 2 ); | ||
|
||
#if defined( __cpp_exceptions ) | ||
verify_rule< must< partial< one< 'a' > > > >( __LINE__, __FILE__, "", result_type::success, 0 ); | ||
verify_rule< must< partial< one< 'a' > > > >( __LINE__, __FILE__, "a", result_type::success, 0 ); | ||
verify_rule< must< partial< one< 'a' > > > >( __LINE__, __FILE__, "aa", result_type::success, 1 ); | ||
verify_rule< must< partial< one< 'a' > > > >( __LINE__, __FILE__, "ab", result_type::success, 1 ); | ||
verify_rule< must< partial< one< 'a' > > > >( __LINE__, __FILE__, "ba", result_type::success, 2 ); | ||
|
||
verify_rule< must< partial< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "", result_type::success, 0 ); | ||
verify_rule< must< partial< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "a", result_type::success, 0 ); | ||
verify_rule< must< partial< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "ab", result_type::success, 0 ); | ||
verify_rule< must< partial< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "aba", result_type::success, 1 ); | ||
verify_rule< must< partial< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "abab", result_type::success, 2 ); | ||
verify_rule< must< partial< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "bab", result_type::success, 3 ); | ||
verify_rule< must< partial< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "cb", result_type::success, 2 ); | ||
#endif | ||
|
||
bool success = false; | ||
TAO_PEGTL_TEST_ASSERT( parse< partial< eof >, my_action >( memory_input( "", __FUNCTION__ ), success ) ); | ||
TAO_PEGTL_TEST_ASSERT( success ); | ||
} | ||
|
||
} // namespace tao::pegtl | ||
|
||
#include "main.hpp" |