From 63a86a0b7b212807bb7d178a1cfb44e70116f4fa Mon Sep 17 00:00:00 2001 From: Rich Newman Date: Tue, 4 Apr 2023 12:44:48 -0700 Subject: [PATCH 1/4] Propagate the node to the users Control methods. --- include/tao/pegtl/contrib/parse_tree.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/tao/pegtl/contrib/parse_tree.hpp b/include/tao/pegtl/contrib/parse_tree.hpp index 15c9af2de..00d8f41f3 100644 --- a/include/tao/pegtl/contrib/parse_tree.hpp +++ b/include/tao/pegtl/contrib/parse_tree.hpp @@ -290,9 +290,9 @@ namespace tao::pegtl::parse_tree template< typename ParseInput, typename... States > static void start( const ParseInput& in, state< Node >& state, States&&... st ) { - Control< Rule >::start( in, st... ); state.emplace_back(); state.back()->template start< Rule >( in, st... ); + Control< Rule >::start( in, state.back()->children.back(), st... ); } template< typename ParseInput, typename... States > @@ -304,16 +304,19 @@ namespace tao::pegtl::parse_tree transform< Selector< Rule > >( in, n, st... ); if( n ) { state.back()->emplace_back( std::move( n ), st... ); + Control< Rule >::success( in, state.back()->children.back(), st... ); + } else { + auto null_child = std::make_unique(); + Control< Rule >::success( in, null_child, st... ); } - Control< Rule >::success( in, st... ); } template< typename ParseInput, typename... States > static void failure( const ParseInput& in, state< Node >& state, States&&... st ) { state.back()->template failure< Rule >( in, st... ); + Control< Rule >::failure( in, state.back()->children.back(), st... ); state.pop_back(); - Control< Rule >::failure( in, st... ); } template< typename ParseInput, typename... States > From fc24142d099c4f5146b7dc7c9e575417e43b1ebc Mon Sep 17 00:00:00 2001 From: Rich Newman Date: Tue, 4 Apr 2023 15:15:24 -0700 Subject: [PATCH 2/4] Break out a reference to the node to be passed along. (Easier to debug). --- include/tao/pegtl/contrib/parse_tree.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/tao/pegtl/contrib/parse_tree.hpp b/include/tao/pegtl/contrib/parse_tree.hpp index 00d8f41f3..9707080d5 100644 --- a/include/tao/pegtl/contrib/parse_tree.hpp +++ b/include/tao/pegtl/contrib/parse_tree.hpp @@ -292,7 +292,8 @@ namespace tao::pegtl::parse_tree { state.emplace_back(); state.back()->template start< Rule >( in, st... ); - Control< Rule >::start( in, state.back()->children.back(), st... ); + auto &n = state.back()->children.back(); + Control< Rule >::start( in, n, st... ); } template< typename ParseInput, typename... States > From e87f6e1b4503d37e7109b51dc7701b24d58f70ce Mon Sep 17 00:00:00 2001 From: Rich Newman Date: Tue, 11 Apr 2023 11:33:31 -0700 Subject: [PATCH 3/4] Clang-format cleanup. --- include/tao/pegtl/contrib/parse_tree.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/tao/pegtl/contrib/parse_tree.hpp b/include/tao/pegtl/contrib/parse_tree.hpp index 9707080d5..ee805a566 100644 --- a/include/tao/pegtl/contrib/parse_tree.hpp +++ b/include/tao/pegtl/contrib/parse_tree.hpp @@ -292,7 +292,7 @@ namespace tao::pegtl::parse_tree { state.emplace_back(); state.back()->template start< Rule >( in, st... ); - auto &n = state.back()->children.back(); + auto& n = state.back()->children.back(); Control< Rule >::start( in, n, st... ); } @@ -306,7 +306,8 @@ namespace tao::pegtl::parse_tree if( n ) { state.back()->emplace_back( std::move( n ), st... ); Control< Rule >::success( in, state.back()->children.back(), st... ); - } else { + } + else { auto null_child = std::make_unique(); Control< Rule >::success( in, null_child, st... ); } From fd8f99963900a932b6af22030902677f395c6143 Mon Sep 17 00:00:00 2001 From: Rich Newman Date: Tue, 11 Apr 2023 12:05:16 -0700 Subject: [PATCH 4/4] More clang-format cleanup. --- include/tao/pegtl/contrib/parse_tree.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/tao/pegtl/contrib/parse_tree.hpp b/include/tao/pegtl/contrib/parse_tree.hpp index ee805a566..211cdbafc 100644 --- a/include/tao/pegtl/contrib/parse_tree.hpp +++ b/include/tao/pegtl/contrib/parse_tree.hpp @@ -308,8 +308,8 @@ namespace tao::pegtl::parse_tree Control< Rule >::success( in, state.back()->children.back(), st... ); } else { - auto null_child = std::make_unique(); - Control< Rule >::success( in, null_child, st... ); + auto null_child = std::make_unique(); + Control< Rule >::success( in, null_child, st... ); } }