From 7fd90f50a216d9d11c2681558321475174548efd Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Thu, 7 Aug 2025 14:10:37 +0200 Subject: [PATCH 1/9] Add define BOOST_PARSER_DISABLE_TRACE to disable trace mode at compile time. The trace feature doubles the compile time, even if never used. This patch introduces the preprocessor define BOOST_PARSER_DISABLE_TRACE to deactivate this feature at compile time. --- include/boost/parser/parser.hpp | 72 +++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/include/boost/parser/parser.hpp b/include/boost/parser/parser.hpp index 1f833da7..291ce566 100644 --- a/include/boost/parser/parser.hpp +++ b/include/boost/parser/parser.hpp @@ -9041,10 +9041,14 @@ namespace boost { namespace parser { "If you're seeing this error, you're trying to get parse() to " "fill in attr above, using the attribute generated by parser. " "However, parser does not generate an attribute."); +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return reset = detail::parse_impl( first, last, parser, parser.error_handler_, attr); - } else { + } + else +#endif + { return reset = detail::parse_impl( first, last, parser, parser.error_handler_, attr); } @@ -9059,10 +9063,14 @@ namespace boost { namespace parser { "If you're seeing this error, you're trying to get parse() to " "fill in attr above, using the attribute generated by parser. " "However, parser does not generate an attribute."); +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return reset = detail::parse_impl( f, l, parser, parser.error_handler_, attr); - } else { + } + else +#endif + { return reset = detail::parse_impl( f, l, parser, parser.error_handler_, attr); } @@ -9163,10 +9171,14 @@ namespace boost { namespace parser { trace trace_mode = trace::off) { if constexpr (!detail::is_char8_iter_v) { +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::parse_impl( first, last, parser, parser.error_handler_); - } else { + } + else +#endif + { return detail::parse_impl( first, last, parser, parser.error_handler_); } @@ -9176,10 +9188,14 @@ namespace boost { namespace parser { auto f = r.begin(); auto const l = r.end(); auto _ = detail::scoped_base_assign(first, f); +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::parse_impl( f, l, parser, parser.error_handler_); - } else { + } + else +#endif + { return detail::parse_impl( f, l, parser, parser.error_handler_); } @@ -9282,6 +9298,7 @@ namespace boost { namespace parser { "If you're seeing this error, you're trying to get parse() to " "fill in attr above, using the attribute generated by parser. " "However, parser does not generate an attribute."); +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return reset = detail::skip_parse_impl( first, @@ -9290,7 +9307,10 @@ namespace boost { namespace parser { skip, parser.error_handler_, attr); - } else { + } + else +#endif + { return reset = detail::skip_parse_impl( first, last, @@ -9310,10 +9330,14 @@ namespace boost { namespace parser { "If you're seeing this error, you're trying to get parse() to " "fill in attr above, using the attribute generated by parser. " "However, parser does not generate an attribute."); +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return reset = detail::skip_parse_impl( f, l, parser, skip, parser.error_handler_, attr); - } else { + } + else +#endif + { return reset = detail::skip_parse_impl( f, l, parser, skip, parser.error_handler_, attr); } @@ -9415,10 +9439,14 @@ namespace boost { namespace parser { trace trace_mode = trace::off) { if constexpr (!detail::is_char8_iter_v) { +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::skip_parse_impl( first, last, parser, skip, parser.error_handler_); - } else { + } + else +#endif + { return detail::skip_parse_impl( first, last, parser, skip, parser.error_handler_); } @@ -9428,10 +9456,14 @@ namespace boost { namespace parser { auto f = r.begin(); auto const l = r.end(); auto _ = detail::scoped_base_assign(first, f); +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::skip_parse_impl( f, l, parser, skip, parser.error_handler_); - } else { + } + else +#endif + { return detail::skip_parse_impl( f, l, parser, skip, parser.error_handler_); } @@ -9532,10 +9564,14 @@ namespace boost { namespace parser { trace trace_mode = trace::off) { if constexpr (!detail::is_char8_iter_v) { +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::callback_parse_impl( first, last, parser, parser.error_handler_, callbacks); - } else { + } + else +#endif + { return detail::callback_parse_impl( first, last, parser, parser.error_handler_, callbacks); } @@ -9545,10 +9581,14 @@ namespace boost { namespace parser { auto f = r.begin(); auto const l = r.end(); auto _ = detail::scoped_base_assign(first, f); +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::callback_parse_impl( f, l, parser, parser.error_handler_, callbacks); - } else { + } + else +#endif + { return detail::callback_parse_impl( f, l, parser, parser.error_handler_, callbacks); } @@ -9657,6 +9697,7 @@ namespace boost { namespace parser { trace trace_mode = trace::off) { if constexpr (!detail::is_char8_iter_v) { +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::callback_skip_parse_impl( first, @@ -9665,7 +9706,10 @@ namespace boost { namespace parser { skip, parser.error_handler_, callbacks); - } else { + } + else +#endif + { return detail::callback_skip_parse_impl( first, last, @@ -9680,10 +9724,14 @@ namespace boost { namespace parser { auto f = r.begin(); auto const l = r.end(); auto _ = detail::scoped_base_assign(first, f); +#ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::callback_skip_parse_impl( f, l, parser, skip, parser.error_handler_, callbacks); - } else { + } + else +#endif + { return detail::callback_skip_parse_impl( f, l, parser, skip, parser.error_handler_, callbacks); } From 41bbad17af429910d76e5f73aad7888e1bfb2677 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Wed, 10 Dec 2025 19:04:27 +0100 Subject: [PATCH 2/9] guard instantiations of scoped_trace by ifdef --- include/boost/parser/parser.hpp | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/include/boost/parser/parser.hpp b/include/boost/parser/parser.hpp index 291ce566..cf2d94d2 100644 --- a/include/boost/parser/parser.hpp +++ b/include/boost/parser/parser.hpp @@ -3177,6 +3177,7 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, @@ -3185,6 +3186,7 @@ namespace boost { namespace parser { detail::in_apply_parser(flags) ? detail::disable_trace(flags) : flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE if constexpr (detail::is_optional_v) { detail::optional_type attr; @@ -3341,8 +3343,10 @@ namespace boost { namespace parser { Attribute & retval) const { //[ opt_parser_trace + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE //] //[ opt_parser_skip @@ -3505,8 +3509,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE use_parser_t const use_parser{ first, last, context, skip, flags, success}; @@ -3629,8 +3635,10 @@ namespace boost { namespace parser { decltype(detail::hl::transform(parsers_, use_parser)); result_t retval{}; + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first_, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE call_impl( first, @@ -3665,8 +3673,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first_, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE Iter first = first_; use_parser_t const use_parser{ @@ -4298,6 +4308,7 @@ namespace boost { namespace parser { std::decay_t{}))> retval{}; + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first_, @@ -4306,6 +4317,7 @@ namespace boost { namespace parser { detail::in_apply_parser(flags) ? detail::disable_trace(flags) : flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE std::decay_t{}))> indices; @@ -4349,6 +4361,7 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first_, @@ -4357,6 +4370,7 @@ namespace boost { namespace parser { detail::in_apply_parser(flags) ? detail::disable_trace(flags) : flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE Iter first = first_; @@ -4703,8 +4717,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE auto const initial_first = first; auto attr = parser_.call( @@ -4769,8 +4785,10 @@ namespace boost { namespace parser { detail::flags flags, bool & success) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, detail::global_nope); + #endif // BOOST_PARSER_DISABLE_TRACE auto attr = parser_.call(first, last, context, skip, flags, success); if (success && detail::gen_attrs(flags)) @@ -4794,8 +4812,11 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE + auto attr = parser_.call(first, last, context, skip, flags, success); if (success && detail::gen_attrs(flags)) @@ -4822,8 +4843,10 @@ namespace boost { namespace parser { detail::flags flags, bool & success) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, detail::global_nope); + #endif // BOOST_PARSER_DISABLE_TRACE parser_.call( first, @@ -4850,8 +4873,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE parser_.call( first, @@ -4901,8 +4926,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE auto const initial_first = first; parser_.call( @@ -4966,8 +4993,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE auto const initial_first = first; parser_.call( @@ -5042,8 +5071,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE parser_.call( first, @@ -5102,8 +5133,10 @@ namespace boost { namespace parser { auto context = context_; ++context.no_case_depth_; + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE parser_.call(first, last, context, skip, flags, success, retval); } @@ -5149,8 +5182,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE if constexpr (detail::is_nope_v) { parser_.call( @@ -5213,8 +5248,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE auto first_copy = first; parser_.call( @@ -5380,8 +5417,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE auto [trie, _0] = detail::get_trie(context, ref()); auto const lookup = context.no_case_depth_ @@ -5455,8 +5494,10 @@ namespace boost { namespace parser { tag_type * const tag_ptr = nullptr; auto const rule_context = detail::make_rule_context( context, tag_ptr, retval, locals, params); + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, rule_context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE bool dont_assign = false; if constexpr (in_recursion) { @@ -5552,8 +5593,10 @@ namespace boost { namespace parser { auto const rule_context = detail::make_rule_context( context, tag_ptr, retval, locals, params); + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, rule_context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE bool dont_assign = false; parse_rule( @@ -6730,8 +6773,10 @@ namespace boost { namespace parser { detail::flags flags, bool & success) const noexcept { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, detail::global_nope); + #endif // BOOST_PARSER_DISABLE_TRACE BOOST_PARSER_SUBRANGE const where(first, first); auto const predicate_context = detail::make_action_context( context, detail::global_nope, where); @@ -6758,8 +6803,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE BOOST_PARSER_SUBRANGE const where(first, first); auto const predicate_context = detail::make_action_context( context, detail::global_nope, where); @@ -6809,8 +6856,10 @@ namespace boost { namespace parser { detail::flags flags, bool & success) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, detail::global_nope); + #endif // BOOST_PARSER_DISABLE_TRACE if (first != last) success = false; return {}; @@ -6831,8 +6880,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE if (first != last) success = false; } @@ -6861,8 +6912,10 @@ namespace boost { namespace parser { detail::flags flags, bool &) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, detail::global_nope); + #endif // BOOST_PARSER_DISABLE_TRACE return detail::resolve(context, attr_); } @@ -6881,8 +6934,10 @@ namespace boost { namespace parser { bool & success, Attribute_ & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE if (detail::gen_attrs(flags)) detail::assign_copy(retval, detail::resolve(context, attr_)); } @@ -6947,8 +7002,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE if (first == last) { success = false; @@ -7112,8 +7169,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE if (first == last) { success = false; @@ -7263,8 +7322,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE if (first == last) { success = false; @@ -7343,8 +7404,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE if (first == last) { success = false; @@ -7465,8 +7528,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE if (first == last) { success = false; @@ -7629,8 +7694,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE if (first == last) { success = false; @@ -7950,8 +8017,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE if (first == last) { success = false; @@ -8117,8 +8186,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE auto compare = [no_case = context.no_case_depth_](char32_t a, char32_t b) { @@ -8206,8 +8277,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE T attr = 0; auto const initial = first; success = @@ -8347,8 +8420,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE T attr = 0; auto const initial = first; success = @@ -8462,8 +8537,10 @@ namespace boost { namespace parser { bool & success, Attribute & retval) const { + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE T attr = 0; auto const initial = first; success = detail::numeric::parse_real(first, last, attr); @@ -8582,8 +8659,10 @@ namespace boost { namespace parser { "It looks like you tried to write switch_(val). You need at " "least one alternative, like: switch_(val)(value_1, " "parser_1)(value_2, parser_2)...")); + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace( *this, first, last, context, flags, retval); + #endif // BOOST_PARSER_DISABLE_TRACE or_parser_.call(first, last, context, skip, flags, success, retval); } From 028cc59dbeef8c3e4968a2108dbc46b815017037 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Thu, 11 Dec 2025 11:42:34 +0100 Subject: [PATCH 3/9] ifdef away definition of scoped_trace add a unit test --- include/boost/parser/detail/printing.hpp | 2 ++ include/boost/parser/parser.hpp | 14 ++++++++++++ test/CMakeLists.txt | 1 + test/disable_trace.cpp | 27 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 test/disable_trace.cpp diff --git a/include/boost/parser/detail/printing.hpp b/include/boost/parser/detail/printing.hpp index 52facf7b..0d14bbb6 100644 --- a/include/boost/parser/detail/printing.hpp +++ b/include/boost/parser/detail/printing.hpp @@ -598,6 +598,7 @@ namespace boost { namespace parser { namespace detail { template auto resolve(Context const &, nope n); + #ifndef BOOST_PARSER_DISABLE_TRACE template< bool DoTrace, typename Iter, @@ -708,6 +709,7 @@ namespace boost { namespace parser { namespace detail { } os << "--------------------" << std::endl; } + #endif // BOOST_PARSER_DISABLE_TRACE }}} diff --git a/include/boost/parser/parser.hpp b/include/boost/parser/parser.hpp index cf2d94d2..befa1d2e 100644 --- a/include/boost/parser/parser.hpp +++ b/include/boost/parser/parser.hpp @@ -2455,8 +2455,10 @@ namespace boost { namespace parser { flags, success, attr); +#ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, attr); +#endif // BOOST_PARSER_DISABLE_TRACE return success; } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -2509,8 +2511,10 @@ namespace boost { namespace parser { detail::null_parser{}, flags, success); +#ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, nope{}); +#endif // BOOST_PARSER_DISABLE_TRACE return detail::make_parse_result(attr_, success); } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -2564,8 +2568,10 @@ namespace boost { namespace parser { detail::null_parser{}, flags, success); +#ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, nope{}); +#endif // BOOST_PARSER_DISABLE_TRACE return success; } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -2615,8 +2621,10 @@ namespace boost { namespace parser { try { parser(first, last, context, skip, flags, success, attr); detail::skip(first, last, skip, flags); +#ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, attr); +#endif // BOOST_PARSER_DISABLE_TRACE return success; } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -2668,8 +2676,10 @@ namespace boost { namespace parser { attr_t attr_ = parser(first, last, context, skip, flags, success); detail::skip(first, last, skip, flags); +#ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, nope{}); +#endif // BOOST_PARSER_DISABLE_TRACE return detail::make_parse_result(attr_, success); } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -2721,8 +2731,10 @@ namespace boost { namespace parser { try { parser(first, last, context, skip, flags, success); detail::skip(first, last, skip, flags); +#ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, nope{}); +#endif // BOOST_PARSER_DISABLE_TRACE return success; } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -8633,8 +8645,10 @@ namespace boost { namespace parser { using attr_t = decltype(or_parser_.call( first, last, context, skip, flags, success)); attr_t attr{}; +#ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace(*this, first, last, context, flags, attr); +#endif // BOOST_PARSER_DISABLE_TRACE attr = or_parser_.call(first, last, context, skip, flags, success); return attr; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eebcf19d..75b074f1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -82,6 +82,7 @@ add_test_executable(parser_seq_permutations_1) add_test_executable(parser_seq_permutations_2) add_test_executable(parser_or_permutations_1) add_test_executable(parser_or_permutations_2) +add_test_executable(disable_trace) if (MSVC) add_executable(vs_output_tracing tracing.cpp) diff --git a/test/disable_trace.cpp b/test/disable_trace.cpp new file mode 100644 index 00000000..dd12a4c3 --- /dev/null +++ b/test/disable_trace.cpp @@ -0,0 +1,27 @@ +/** +* Copyright (C) 2025 + * + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ + +#define BOOST_PARSER_DISABLE_TRACE + +#include +#include + +int main() +{ + namespace bp = boost::parser; + { + auto const parser = + bp::string("FOO") >> -(bp::string("bar") | bp::string("foo")); + + auto result = bp::parse("FOOfoo", parser); + BOOST_TEST(result); + BOOST_TEST(bp::get(*result, bp::llong<0>{}) == std::string("FOO")); + BOOST_TEST(bp::get(*result, bp::llong<1>{}) == std::string("foo")); + } + return boost::report_errors(); +} \ No newline at end of file From 807ce58511d8bd38ca692f90d664f851357ae35f Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Thu, 11 Dec 2025 22:13:15 +0100 Subject: [PATCH 4/9] consistent indentation and commenting --- include/boost/parser/parser.hpp | 76 ++++++++++++++++----------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/include/boost/parser/parser.hpp b/include/boost/parser/parser.hpp index befa1d2e..9e8ab2bd 100644 --- a/include/boost/parser/parser.hpp +++ b/include/boost/parser/parser.hpp @@ -2455,10 +2455,10 @@ namespace boost { namespace parser { flags, success, attr); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, attr); -#endif // BOOST_PARSER_DISABLE_TRACE + #endif // BOOST_PARSER_DISABLE_TRACE return success; } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -2511,10 +2511,10 @@ namespace boost { namespace parser { detail::null_parser{}, flags, success); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, nope{}); -#endif // BOOST_PARSER_DISABLE_TRACE + #endif // BOOST_PARSER_DISABLE_TRACE return detail::make_parse_result(attr_, success); } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -2568,10 +2568,10 @@ namespace boost { namespace parser { detail::null_parser{}, flags, success); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, nope{}); -#endif // BOOST_PARSER_DISABLE_TRACE + #endif // BOOST_PARSER_DISABLE_TRACE return success; } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -2621,10 +2621,10 @@ namespace boost { namespace parser { try { parser(first, last, context, skip, flags, success, attr); detail::skip(first, last, skip, flags); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, attr); -#endif // BOOST_PARSER_DISABLE_TRACE + #endif // BOOST_PARSER_DISABLE_TRACE return success; } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -2676,10 +2676,10 @@ namespace boost { namespace parser { attr_t attr_ = parser(first, last, context, skip, flags, success); detail::skip(first, last, skip, flags); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, nope{}); -#endif // BOOST_PARSER_DISABLE_TRACE + #endif // BOOST_PARSER_DISABLE_TRACE return detail::make_parse_result(attr_, success); } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -2731,10 +2731,10 @@ namespace boost { namespace parser { try { parser(first, last, context, skip, flags, success); detail::skip(first, last, skip, flags); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (Debug) detail::final_trace(context, flags, nope{}); -#endif // BOOST_PARSER_DISABLE_TRACE + #endif // BOOST_PARSER_DISABLE_TRACE return success; } catch (parse_error const & e) { if (error_handler(initial_first, last, e) == @@ -8645,10 +8645,10 @@ namespace boost { namespace parser { using attr_t = decltype(or_parser_.call( first, last, context, skip, flags, success)); attr_t attr{}; -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE [[maybe_unused]] auto _ = detail::scoped_trace(*this, first, last, context, flags, attr); -#endif // BOOST_PARSER_DISABLE_TRACE + #endif // BOOST_PARSER_DISABLE_TRACE attr = or_parser_.call(first, last, context, skip, flags, success); return attr; } @@ -9134,13 +9134,13 @@ namespace boost { namespace parser { "If you're seeing this error, you're trying to get parse() to " "fill in attr above, using the attribute generated by parser. " "However, parser does not generate an attribute."); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return reset = detail::parse_impl( first, last, parser, parser.error_handler_, attr); } else -#endif + #endif // BOOST_PARSER_DISABLE_TRACE { return reset = detail::parse_impl( first, last, parser, parser.error_handler_, attr); @@ -9156,13 +9156,13 @@ namespace boost { namespace parser { "If you're seeing this error, you're trying to get parse() to " "fill in attr above, using the attribute generated by parser. " "However, parser does not generate an attribute."); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return reset = detail::parse_impl( f, l, parser, parser.error_handler_, attr); } else -#endif + #endif // BOOST_PARSER_DISABLE_TRACE { return reset = detail::parse_impl( f, l, parser, parser.error_handler_, attr); @@ -9264,13 +9264,13 @@ namespace boost { namespace parser { trace trace_mode = trace::off) { if constexpr (!detail::is_char8_iter_v) { -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::parse_impl( first, last, parser, parser.error_handler_); } else -#endif + #endif // BOOST_PARSER_DISABLE_TRACE { return detail::parse_impl( first, last, parser, parser.error_handler_); @@ -9281,13 +9281,13 @@ namespace boost { namespace parser { auto f = r.begin(); auto const l = r.end(); auto _ = detail::scoped_base_assign(first, f); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::parse_impl( f, l, parser, parser.error_handler_); } else -#endif + #endif // BOOST_PARSER_DISABLE_TRACE { return detail::parse_impl( f, l, parser, parser.error_handler_); @@ -9391,7 +9391,7 @@ namespace boost { namespace parser { "If you're seeing this error, you're trying to get parse() to " "fill in attr above, using the attribute generated by parser. " "However, parser does not generate an attribute."); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return reset = detail::skip_parse_impl( first, @@ -9402,7 +9402,7 @@ namespace boost { namespace parser { attr); } else -#endif +#endif // BOOST_PARSER_DISABLE_TRACE { return reset = detail::skip_parse_impl( first, @@ -9423,13 +9423,13 @@ namespace boost { namespace parser { "If you're seeing this error, you're trying to get parse() to " "fill in attr above, using the attribute generated by parser. " "However, parser does not generate an attribute."); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return reset = detail::skip_parse_impl( f, l, parser, skip, parser.error_handler_, attr); } else -#endif + #endif // BOOST_PARSER_DISABLE_TRACE { return reset = detail::skip_parse_impl( f, l, parser, skip, parser.error_handler_, attr); @@ -9532,13 +9532,13 @@ namespace boost { namespace parser { trace trace_mode = trace::off) { if constexpr (!detail::is_char8_iter_v) { -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::skip_parse_impl( first, last, parser, skip, parser.error_handler_); } else -#endif + #endif // BOOST_PARSER_DISABLE_TRACE { return detail::skip_parse_impl( first, last, parser, skip, parser.error_handler_); @@ -9549,13 +9549,13 @@ namespace boost { namespace parser { auto f = r.begin(); auto const l = r.end(); auto _ = detail::scoped_base_assign(first, f); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::skip_parse_impl( f, l, parser, skip, parser.error_handler_); } else -#endif + #endif // BOOST_PARSER_DISABLE_TRACE { return detail::skip_parse_impl( f, l, parser, skip, parser.error_handler_); @@ -9657,13 +9657,13 @@ namespace boost { namespace parser { trace trace_mode = trace::off) { if constexpr (!detail::is_char8_iter_v) { -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::callback_parse_impl( first, last, parser, parser.error_handler_, callbacks); } else -#endif + #endif // BOOST_PARSER_DISABLE_TRACE { return detail::callback_parse_impl( first, last, parser, parser.error_handler_, callbacks); @@ -9674,13 +9674,13 @@ namespace boost { namespace parser { auto f = r.begin(); auto const l = r.end(); auto _ = detail::scoped_base_assign(first, f); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::callback_parse_impl( f, l, parser, parser.error_handler_, callbacks); } else -#endif + #endif // BOOST_PARSER_DISABLE_TRACE { return detail::callback_parse_impl( f, l, parser, parser.error_handler_, callbacks); @@ -9790,7 +9790,7 @@ namespace boost { namespace parser { trace trace_mode = trace::off) { if constexpr (!detail::is_char8_iter_v) { -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::callback_skip_parse_impl( first, @@ -9801,7 +9801,7 @@ namespace boost { namespace parser { callbacks); } else -#endif + #endif // BOOST_PARSER_DISABLE_TRACE { return detail::callback_skip_parse_impl( first, @@ -9817,13 +9817,13 @@ namespace boost { namespace parser { auto f = r.begin(); auto const l = r.end(); auto _ = detail::scoped_base_assign(first, f); -#ifndef BOOST_PARSER_DISABLE_TRACE + #ifndef BOOST_PARSER_DISABLE_TRACE if (trace_mode == trace::on) { return detail::callback_skip_parse_impl( f, l, parser, skip, parser.error_handler_, callbacks); } else -#endif + #endif // BOOST_PARSER_DISABLE_TRACE { return detail::callback_skip_parse_impl( f, l, parser, skip, parser.error_handler_, callbacks); From 15a5eab9331963f1b76f7884f080d7247d4e8986 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Thu, 11 Dec 2025 22:24:57 +0100 Subject: [PATCH 5/9] add some documentation --- doc/parser.qbk | 1 + doc/tutorial.qbk | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/doc/parser.qbk b/doc/parser.qbk index b6ab37d7..509ccf49 100644 --- a/doc/parser.qbk +++ b/doc/parser.qbk @@ -148,6 +148,7 @@ [def _RULES_ [macroref BOOST_PARSER_DEFINE_RULES `BOOST_PARSER_DEFINE_RULES`]] [def _AGGR_SIZE_ [macroref BOOST_PARSER_MAX_AGGREGATE_SIZE `BOOST_PARSER_MAX_AGGREGATE_SIZE`]] [def _SUBRNG_ [macroref BOOST_PARSER_SUBRANGE `BOOST_PARSER_SUBRANGE`]] +[def _DISABLE_TRACE_ [macroref BOOST_PARSER_DISABLE_TRACE `BOOST_PARSER_DISABLE_TRACE`]] [def __p_ [globalref boost::parser::_p `_p`]] diff --git a/doc/tutorial.qbk b/doc/tutorial.qbk index aefc7cc0..5f37d723 100644 --- a/doc/tutorial.qbk +++ b/doc/tutorial.qbk @@ -3766,6 +3766,22 @@ Some things to be aware of when looking at _Parser_ trace output: produces that value. In these cases, you'll see the resolved value of the parse argument. +[heading Compile-time trace disabling] + +While trace mode is very useful for debugging, it does have some overhead. +Most parser templates are instantiated twice: Once with tracing enabled, +once with tracing disabled. +If you want to completely disable trace functionality at compile time, you can define +`BOOST_PARSER_DISABLE_TRACE` before including any Boost.Parser headers: + +[teletype]`` +#define BOOST_PARSER_DISABLE_TRACE +#include +`` + +When this define is set, all trace-related code is compiled out, +reducing the compile time. + [endsect] [section Memory Allocation] From 1ffc96650f5bf13676cc8f0f92f8acd4544fcc23 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Fri, 12 Dec 2025 21:10:30 +0100 Subject: [PATCH 6/9] build everything without tracing in CI --- .github/workflows/ubuntu.yml | 13 ++++++++++++- .github/workflows/windows.yml | 14 +++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index d5692bf5..c41be9dd 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -18,6 +18,13 @@ jobs: compiler_version: [g++-10, g++-11] cxx_std: [17, 20] os: [ubuntu-22.04] + disable_trace: [false] + include: + # Test with trace disabled + - compiler_version: g++-11 + cxx_std: 20 + os: ubuntu-22.04 + disable_trace: true runs-on: ${{ matrix.os }} @@ -30,7 +37,11 @@ jobs: run: | mkdir build cd build - cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }} + if [ "${{ matrix.disable_trace }}" = "true" ]; then + cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }} -DCMAKE_CXX_FLAGS="-DBOOST_PARSER_DISABLE_TRACE" + else + cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }} + fi - name: Build run: cd build ; make -j4 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 87b70a01..f88aee40 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -17,6 +17,12 @@ jobs: matrix: cxx_std: [17, 20, 23] os: [windows-2022] + disable_trace: [false] + include: + # Test with trace disabled + - cxx_std: 20 + os: windows-2022 + disable_trace: true runs-on: ${{ matrix.os }} @@ -26,7 +32,13 @@ jobs: - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCXX_STD=${{ matrix.cxx_std }} + run: | + if ("${{ matrix.disable_trace }}" -eq "true") { + cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCXX_STD=${{ matrix.cxx_std }} -DCMAKE_CXX_FLAGS="/DBOOST_PARSER_DISABLE_TRACE" + } else { + cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCXX_STD=${{ matrix.cxx_std }} + } + shell: pwsh - name: Build working-directory: build From 1a088048e00b91d9cf419c26420a2cbe223cfdb2 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Fri, 12 Dec 2025 21:15:50 +0100 Subject: [PATCH 7/9] fix another inconsistent indentation --- include/boost/parser/parser.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/parser/parser.hpp b/include/boost/parser/parser.hpp index 9e8ab2bd..02737ac3 100644 --- a/include/boost/parser/parser.hpp +++ b/include/boost/parser/parser.hpp @@ -9402,7 +9402,7 @@ namespace boost { namespace parser { attr); } else -#endif // BOOST_PARSER_DISABLE_TRACE + #endif // BOOST_PARSER_DISABLE_TRACE { return reset = detail::skip_parse_impl( first, From cac6623dafb9721443524d6a4ca6794de942da41 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Sat, 13 Dec 2025 08:23:45 +0100 Subject: [PATCH 8/9] more consistent formatting --- include/boost/parser/parser.hpp | 36 +++++++++++---------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/include/boost/parser/parser.hpp b/include/boost/parser/parser.hpp index 02737ac3..9d999fa6 100644 --- a/include/boost/parser/parser.hpp +++ b/include/boost/parser/parser.hpp @@ -9138,8 +9138,7 @@ namespace boost { namespace parser { if (trace_mode == trace::on) { return reset = detail::parse_impl( first, last, parser, parser.error_handler_, attr); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return reset = detail::parse_impl( @@ -9160,8 +9159,7 @@ namespace boost { namespace parser { if (trace_mode == trace::on) { return reset = detail::parse_impl( f, l, parser, parser.error_handler_, attr); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return reset = detail::parse_impl( @@ -9268,8 +9266,7 @@ namespace boost { namespace parser { if (trace_mode == trace::on) { return detail::parse_impl( first, last, parser, parser.error_handler_); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return detail::parse_impl( @@ -9285,8 +9282,7 @@ namespace boost { namespace parser { if (trace_mode == trace::on) { return detail::parse_impl( f, l, parser, parser.error_handler_); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return detail::parse_impl( @@ -9400,8 +9396,7 @@ namespace boost { namespace parser { skip, parser.error_handler_, attr); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return reset = detail::skip_parse_impl( @@ -9427,8 +9422,7 @@ namespace boost { namespace parser { if (trace_mode == trace::on) { return reset = detail::skip_parse_impl( f, l, parser, skip, parser.error_handler_, attr); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return reset = detail::skip_parse_impl( @@ -9536,8 +9530,7 @@ namespace boost { namespace parser { if (trace_mode == trace::on) { return detail::skip_parse_impl( first, last, parser, skip, parser.error_handler_); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return detail::skip_parse_impl( @@ -9553,8 +9546,7 @@ namespace boost { namespace parser { if (trace_mode == trace::on) { return detail::skip_parse_impl( f, l, parser, skip, parser.error_handler_); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return detail::skip_parse_impl( @@ -9661,8 +9653,7 @@ namespace boost { namespace parser { if (trace_mode == trace::on) { return detail::callback_parse_impl( first, last, parser, parser.error_handler_, callbacks); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return detail::callback_parse_impl( @@ -9678,8 +9669,7 @@ namespace boost { namespace parser { if (trace_mode == trace::on) { return detail::callback_parse_impl( f, l, parser, parser.error_handler_, callbacks); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return detail::callback_parse_impl( @@ -9799,8 +9789,7 @@ namespace boost { namespace parser { skip, parser.error_handler_, callbacks); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return detail::callback_skip_parse_impl( @@ -9821,8 +9810,7 @@ namespace boost { namespace parser { if (trace_mode == trace::on) { return detail::callback_skip_parse_impl( f, l, parser, skip, parser.error_handler_, callbacks); - } - else + } else #endif // BOOST_PARSER_DISABLE_TRACE { return detail::callback_skip_parse_impl( From 8fd8da4abde02bdf5d5a742108c7dedc73bc1dcd Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Sat, 13 Dec 2025 08:52:42 +0100 Subject: [PATCH 9/9] add CMake option for DISABLE_TRACE --- .github/workflows/ubuntu.yml | 2 +- .github/workflows/windows.yml | 2 +- CMakeLists.txt | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index c41be9dd..a36233f1 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -38,7 +38,7 @@ jobs: mkdir build cd build if [ "${{ matrix.disable_trace }}" = "true" ]; then - cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }} -DCMAKE_CXX_FLAGS="-DBOOST_PARSER_DISABLE_TRACE" + cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }} -DDISABLE_TRACE=true else cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }} fi diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index f88aee40..971ac66c 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -34,7 +34,7 @@ jobs: # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: | if ("${{ matrix.disable_trace }}" -eq "true") { - cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCXX_STD=${{ matrix.cxx_std }} -DCMAKE_CXX_FLAGS="/DBOOST_PARSER_DISABLE_TRACE" + cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCXX_STD=${{ matrix.cxx_std }} -DDISABLE_TRACE=true } else { cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCXX_STD=${{ matrix.cxx_std }} } diff --git a/CMakeLists.txt b/CMakeLists.txt index c9d78d7a..115d0b30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,12 @@ if (BUILD_WITH_HANA) add_definitions(-DBOOST_PARSER_USE_HANA_TUPLE) endif() +set(DISABLE_TRACE false CACHE BOOL + "Disable parser trace functionality (defines BOOST_PARSER_DISABLE_TRACE).") +if (DISABLE_TRACE) + add_definitions(-DBOOST_PARSER_DISABLE_TRACE) +endif() + ################################################## # Dependencies