Skip to content

Commit

Permalink
Move helper to contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Feb 17, 2018
1 parent c1ace23 commit 9d4989b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
11 changes: 11 additions & 0 deletions include/tao/pegtl/contrib/parse_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ namespace tao

} // namespace internal

// some nodes don't need to store their content,
// use this helper as a base class to derive your specialization from.
struct remove_content : std::true_type
{
template< typename Node >
static void transform( std::unique_ptr< Node >& n ) noexcept( noexcept( n->remove_content() ) )
{
n->remove_content();
}
};

template< typename Rule, typename Node, template< typename > class S = internal::store_all, typename Input >
std::unique_ptr< Node > parse( Input& in )
{
Expand Down
19 changes: 4 additions & 15 deletions src/example/pegtl/parse_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,10 @@ namespace example
template<> struct store< integer > : std::true_type {};
template<> struct store< variable > : std::true_type {};

// some nodes don't need to store their content,
// the existance (and the type-id) are sufficient.
struct remove_content : std::true_type
{
// we simply reset the end iterator as a marker.
static void transform( std::unique_ptr< parse_tree::node >& n ) noexcept
{
n->remove_content();
}
};

template<> struct store< plus > : remove_content {};
template<> struct store< minus > : remove_content {};
template<> struct store< multiply > : remove_content {};
template<> struct store< divide > : remove_content {};
template<> struct store< plus > : parse_tree::remove_content {};
template<> struct store< minus > : parse_tree::remove_content {};
template<> struct store< multiply > : parse_tree::remove_content {};
template<> struct store< divide > : parse_tree::remove_content {};
// clang-format on

// after a node is stored successfully, you can add an optional transformer like this:
Expand Down

0 comments on commit 9d4989b

Please sign in to comment.