-
Notifications
You must be signed in to change notification settings - Fork 230
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
8 changed files
with
369 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2024 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_RULES_HPP | ||
#define TAO_PEGTL_CONTRIB_ALPHABET_RULES_HPP | ||
|
||
#include "../ascii.hpp" | ||
#include "../config.hpp" | ||
|
||
namespace TAO_PEGTL_NAMESPACE::alphabet::rules | ||
{ | ||
struct a : ascii::one< 'a' > {}; | ||
struct b : ascii::one< 'b' > {}; | ||
struct c : ascii::one< 'c' > {}; | ||
struct d : ascii::one< 'd' > {}; | ||
struct e : ascii::one< 'e' > {}; | ||
struct f : ascii::one< 'f' > {}; | ||
struct g : ascii::one< 'g' > {}; | ||
struct h : ascii::one< 'h' > {}; | ||
struct i : ascii::one< 'i' > {}; | ||
struct j : ascii::one< 'j' > {}; | ||
struct k : ascii::one< 'k' > {}; | ||
struct l : ascii::one< 'l' > {}; | ||
struct m : ascii::one< 'm' > {}; | ||
struct n : ascii::one< 'n' > {}; | ||
struct o : ascii::one< 'o' > {}; | ||
struct p : ascii::one< 'p' > {}; | ||
struct q : ascii::one< 'q' > {}; | ||
struct r : ascii::one< 'r' > {}; | ||
struct s : ascii::one< 's' > {}; | ||
struct t : ascii::one< 't' > {}; | ||
struct u : ascii::one< 'u' > {}; | ||
struct v : ascii::one< 'v' > {}; | ||
struct w : ascii::one< 'w' > {}; | ||
struct x : ascii::one< 'x' > {}; | ||
struct y : ascii::one< 'y' > {}; | ||
struct z : ascii::one< 'z' > {}; | ||
|
||
struct A : ascii::one< 'A' > {}; // NOLINT(readability-identifier-naming) | ||
struct B : ascii::one< 'B' > {}; // NOLINT(readability-identifier-naming) | ||
struct C : ascii::one< 'C' > {}; // NOLINT(readability-identifier-naming) | ||
struct D : ascii::one< 'D' > {}; // NOLINT(readability-identifier-naming) | ||
struct E : ascii::one< 'E' > {}; // NOLINT(readability-identifier-naming) | ||
struct F : ascii::one< 'F' > {}; // NOLINT(readability-identifier-naming) | ||
struct G : ascii::one< 'G' > {}; // NOLINT(readability-identifier-naming) | ||
struct H : ascii::one< 'H' > {}; // NOLINT(readability-identifier-naming) | ||
struct I : ascii::one< 'I' > {}; // NOLINT(readability-identifier-naming,misc-confusable-identifiers) | ||
struct J : ascii::one< 'J' > {}; // NOLINT(readability-identifier-naming) | ||
struct K : ascii::one< 'K' > {}; // NOLINT(readability-identifier-naming) | ||
struct L : ascii::one< 'L' > {}; // NOLINT(readability-identifier-naming) | ||
struct M : ascii::one< 'M' > {}; // NOLINT(readability-identifier-naming) | ||
struct N : ascii::one< 'N' > {}; // NOLINT(readability-identifier-naming) | ||
struct O : ascii::one< 'O' > {}; // NOLINT(readability-identifier-naming) | ||
struct P : ascii::one< 'P' > {}; // NOLINT(readability-identifier-naming) | ||
struct Q : ascii::one< 'Q' > {}; // NOLINT(readability-identifier-naming) | ||
struct R : ascii::one< 'R' > {}; // NOLINT(readability-identifier-naming) | ||
struct S : ascii::one< 'S' > {}; // NOLINT(readability-identifier-naming) | ||
struct T : ascii::one< 'T' > {}; // NOLINT(readability-identifier-naming) | ||
struct U : ascii::one< 'U' > {}; // NOLINT(readability-identifier-naming) | ||
struct V : ascii::one< 'V' > {}; // NOLINT(readability-identifier-naming) | ||
struct W : ascii::one< 'W' > {}; // NOLINT(readability-identifier-naming) | ||
struct X : ascii::one< 'X' > {}; // NOLINT(readability-identifier-naming) | ||
struct Y : ascii::one< 'Y' > {}; // NOLINT(readability-identifier-naming) | ||
struct Z : ascii::one< 'Z' > {}; // NOLINT(readability-identifier-naming) | ||
|
||
} // namespace TAO_PEGTL_NAMESPACE::alphabet::rules | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// Copyright (c) 2024 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 "test_utility.hpp" | ||
|
||
#include <tao/pegtl/action/add_state.hpp> | ||
#include <tao/pegtl/contrib/alphabet_rules.hpp> | ||
|
||
namespace TAO_PEGTL_NAMESPACE | ||
{ | ||
bool ctor = false; | ||
bool dtor = false; | ||
|
||
struct state1 | ||
{ | ||
state1() | ||
{ | ||
TAO_PEGTL_TEST_ASSERT( !ctor ); | ||
TAO_PEGTL_TEST_ASSERT( !dtor ); | ||
ctor = true; | ||
} | ||
|
||
~state1() | ||
{ | ||
TAO_PEGTL_TEST_ASSERT( ctor ); | ||
TAO_PEGTL_TEST_ASSERT( !dtor ); | ||
dtor = true; | ||
} | ||
|
||
template< typename ParseInput > | ||
void success( const ParseInput& in, std::size_t& st ) | ||
{ | ||
TAO_PEGTL_TEST_ASSERT( ctor ); | ||
TAO_PEGTL_TEST_ASSERT( !dtor ); | ||
st = in.current_position().count; | ||
} | ||
|
||
state1( state1&& ) = delete; | ||
state1( const state1& ) = delete; | ||
|
||
void operator=( state1&& ) = delete; | ||
void operator=( const state1&& ) = delete; | ||
}; | ||
|
||
struct state2 | ||
{ | ||
template< typename ParseInput > | ||
state2( const ParseInput& in, const int ) | ||
{ | ||
TAO_PEGTL_TEST_ASSERT( !ctor ); | ||
TAO_PEGTL_TEST_ASSERT( !dtor ); | ||
TAO_PEGTL_TEST_ASSERT( in.current_position().count == 1 ); | ||
ctor = true; | ||
} | ||
|
||
~state2() | ||
{ | ||
TAO_PEGTL_TEST_ASSERT( ctor ); | ||
TAO_PEGTL_TEST_ASSERT( !dtor ); | ||
dtor = true; | ||
} | ||
|
||
state2( state2&& ) = delete; | ||
state2( const state2& ) = delete; | ||
|
||
void operator=( state2&& ) = delete; | ||
void operator=( const state2&& ) = delete; | ||
}; | ||
|
||
using namespace alphabet::rules; | ||
|
||
struct grammar | ||
: seq< a, sor< b, c >, d, eof > | ||
{}; | ||
|
||
template< typename Rule > | ||
struct action1 | ||
: nothing< Rule > | ||
{}; | ||
|
||
template<> | ||
struct action1< sor< b, c > > | ||
: add_state< state1 > | ||
{}; | ||
|
||
template< typename Rule > | ||
struct action2 | ||
: nothing< Rule > | ||
{}; | ||
|
||
template<> | ||
struct action2< sor< b, c > > | ||
: add_state< state2 > | ||
{}; | ||
|
||
void unit_test() | ||
{ | ||
// state1 parse success | ||
{ | ||
ctor = false; | ||
dtor = false; | ||
std::size_t st = 0; | ||
view_input<> in( "abd" ); | ||
const bool b = parse< grammar, action1 >( in, st ); | ||
TAO_PEGTL_TEST_ASSERT( b ); | ||
TAO_PEGTL_TEST_ASSERT( ctor ); | ||
TAO_PEGTL_TEST_ASSERT( dtor ); | ||
TAO_PEGTL_TEST_ASSERT( st == 2 ); | ||
} | ||
// state1 parse failure | ||
{ | ||
ctor = false; | ||
dtor = false; | ||
std::size_t st = 0; | ||
view_input<> in( "ad" ); | ||
const bool b = parse< grammar, action1 >( in, st ); | ||
TAO_PEGTL_TEST_ASSERT( !b ); | ||
TAO_PEGTL_TEST_ASSERT( ctor ); | ||
TAO_PEGTL_TEST_ASSERT( dtor ); | ||
TAO_PEGTL_TEST_ASSERT( st == 0 ); | ||
} | ||
// state2 parse success | ||
{ | ||
ctor = false; | ||
dtor = false; | ||
const int i = 42; | ||
view_input<> in( "abd" ); | ||
const bool b = parse< grammar, action2 >( in, i ); | ||
TAO_PEGTL_TEST_ASSERT( b ); | ||
TAO_PEGTL_TEST_ASSERT( ctor ); | ||
TAO_PEGTL_TEST_ASSERT( dtor ); | ||
TAO_PEGTL_TEST_ASSERT( i == 42 ); | ||
} | ||
// state2 parse failure | ||
{ | ||
ctor = false; | ||
dtor = false; | ||
const int i = 42; | ||
view_input<> in( "ad" ); | ||
const bool b = parse< grammar, action2 >( in, i ); | ||
TAO_PEGTL_TEST_ASSERT( !b ); | ||
TAO_PEGTL_TEST_ASSERT( ctor ); | ||
TAO_PEGTL_TEST_ASSERT( dtor ); | ||
TAO_PEGTL_TEST_ASSERT( i == 42 ); | ||
} | ||
} | ||
|
||
} // namespace TAO_PEGTL_NAMESPACE | ||
|
||
#include "main.hpp" |
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,56 @@ | ||
// Copyright (c) 2020-2024 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 <type_traits> | ||
|
||
#include "test.hpp" | ||
#include "test_utility.hpp" | ||
|
||
#include <tao/pegtl/action/change_control.hpp> | ||
|
||
namespace TAO_PEGTL_NAMESPACE | ||
{ | ||
template< template< typename... > class Control2 > | ||
struct test_control | ||
{ | ||
template< apply_mode A, | ||
rewind_mode M, | ||
template< typename... > class Action, | ||
template< typename... > class Control, | ||
typename ParseInput > | ||
[[nodiscard]] static bool match( ParseInput& /*unused*/ ) noexcept | ||
{ | ||
return std::is_same_v< Control< eof >, Control2< eof > >; | ||
} | ||
}; | ||
|
||
template< typename Rule > | ||
struct normal2 | ||
: normal< Rule > | ||
{}; | ||
|
||
template< typename Rule > | ||
struct action2 | ||
: nothing< Rule > | ||
{}; | ||
|
||
template<> | ||
struct action2< seq< one< 'a' >, test_control< normal2 > > > | ||
: change_control< normal2 > | ||
{}; | ||
|
||
struct grammar | ||
: must< test_control< normal >, seq< one< 'a' >, test_control< normal2 > >, eof > | ||
{}; | ||
|
||
void unit_test() | ||
{ | ||
view_input<> in( "a" ); | ||
const bool b = parse< grammar, action2 >( in ); | ||
TAO_PEGTL_TEST_ASSERT( b ); | ||
} | ||
|
||
} // namespace TAO_PEGTL_NAMESPACE | ||
|
||
#include "main.hpp" |
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
Oops, something went wrong.