Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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 }} -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

- name: Build
run: cd build ; make -j4
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -26,7 +32,13 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. Visual Studio is a multi-config generator, so we don't use CMAKE_BUILD_TYPE.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B build -DCXX_STD=${{ matrix.cxx_std }}
run: |
if ("${{ matrix.disable_trace }}" -eq "true") {
cmake -B build -DCXX_STD=${{ matrix.cxx_std }} -DDISABLE_TRACE=true
} else {
cmake -B build -DCXX_STD=${{ matrix.cxx_std }}
}
shell: pwsh

- name: Build
working-directory: build
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ Develop status:

[![Windows MSVC](https://github.com/tzlaine/parser/actions/workflows/windows.yml/badge.svg?branch=develop)](https://github.com/tzlaine/parser/actions/workflows/windows.yml)

[![macos-13 - Clang 14](https://github.com/tzlaine/parser/actions/workflows/macos-13.yml/badge.svg?branch=develop)](https://github.com/tzlaine/parser/actions/workflows/macos-13.yml)
[![macos-15 - Clang](https://github.com/tzlaine/parser/actions/workflows/macos-15.yml/badge.svg?branch=develop)](https://github.com/tzlaine/parser/actions/workflows/macos-15.yml)

[![License](https://img.shields.io/badge/license-boost-brightgreen.svg)](LICENSE_1_0.txt)
1 change: 1 addition & 0 deletions doc/parser.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -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`]]

Expand Down
10 changes: 10 additions & 0 deletions doc/tables.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ the input they match unless otherwise stated in the table below.]
[ `std::string` if `_ATTR_np_(p)` is `char` or `char32_t`, otherwise `std::vector<_ATTR_np_(p)>` ]
[ The special value _inf_ may be used for the upper bound; it indicates unlimited repetition. `decltype(_RES_np_(arg0))` and `decltype(_RES_np_(arg1))` each must be implicitly convertible to `int64_t`. Matching _e_ an unlimited number of times creates an infinite loop, which is undefined behavior in C++. _Parser_ will assert in debug mode when it encounters `_rpt_np_(n, _inf_)[_e_]` (this applies to unconditional _e_ only). ]]

[[ `_rpt_np_(arg0, p1)[p2]` ]
[ Matches iff `p2` matches exactly `_RES_np_(arg0)` times, matching `p1` in between each pair of consecutive matches of `p2`. Equivalent to: _e_ for `_RES_np_(arg0) <= 0`, and `_rpt_np_(_RES_np_(arg0) - 1)[p2 >> p1] >> p2` otherwise. ]
[ `std::string` if `_ATTR_np_(p2)` is `char` or `char32_t`, otherwise `std::vector<_ATTR_np_(p2)>` ]
[ The special value _inf_ may be used; it indicates unlimited repetition. `decltype(_RES_np_(arg0))` must be implicitly convertible to `int64_t`. Matching _e_ an unlimited number of times creates an infinite loop, which is undefined behavior in C++. _Parser_ will assert in debug mode when it encounters `_rpt_np_(_inf_)[_e_]` (this applies to unconditional _e_ only). ]]

[[ `_rpt_np_(arg0, arg1, p1)[p2]` ]
[ Matches iff `p2` matches between `_RES_np_(arg0)` and `_RES_np_(arg1)` times, inclusively, matching `p1` in between each pair of consecutive matches of `p2`. Equivalent to: _e_ for `_RES_np_(arg1) <= 0`, and `_rpt_np_(_RES_np_(arg0) - 1, _RES_np_(arg1) - 1)[p2 >> p1] >> p2` otherwise. ]
[ `std::string` if `_ATTR_np_(p2)` is `char` or `char32_t`, otherwise `std::vector<_ATTR_np_(p2)>` ]
[ The special value _inf_ may be used for the upper bound; it indicates unlimited repetition. `decltype(_RES_np_(arg0))` and `decltype(_RES_np_(arg1))` each must be implicitly convertible to `int64_t`. Matching _e_ an unlimited number of times creates an infinite loop, which is undefined behavior in C++. _Parser_ will assert in debug mode when it encounters `_rpt_np_(n, _inf_)[_e_]` (this applies to unconditional _e_ only). ]]

[[ `_if_np_(pred)[p]` ]
[ Equivalent to `_e_(pred) >> p`. ]
[ `_ATTR_np_(p)` ]
Expand Down
26 changes: 22 additions & 4 deletions doc/tutorial.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -1514,9 +1514,10 @@ attribute, simply returns `bool`; this indicates the success or failure of the
parse.]

[warning _Parser_ assumes that all attributes are semi-regular (see
`std::semiregular`). Within the _Parser_ code, attributes are assigned,
moved, copy, and default constructed. There is no support for move-only or
non-default-constructible types.]
`std::semiregular`). Move-only types that are nearly `std::semiregular`,
other than their copy operations, are also supported. Within the _Parser_
code, attributes are move assigned, moved, and default constructed. There is
no support for non-default-constructible types.]

[heading The attribute type trait, _attr_]

Expand Down Expand Up @@ -3766,6 +3767,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 <boost/parser/parser.hpp>
``

When this define is set, all trace-related code is compiled out,
reducing the compile time.

[endsect]

[section Memory Allocation]
Expand Down Expand Up @@ -3983,7 +4000,8 @@ This defines a RAII trace object that will produce the verbose trace requested
by the user if they passed `_trace_::on` to the top-level parse. It only has
effect if `detail::enable_trace(flags)` is `true`. If trace is enabled, it
will show the state of the parse at the point at which it is defined, and then
again when it goes out of scope.
again when it goes out of scope. By defining `BOOST_PARSER_DISABLE_TRACE`,
the trace feature can be disabled globally at compile time.

[important For the tracing code to work, you must define an overload of
`detail::print_parser` for your new parser type/template. See
Expand Down
10 changes: 10 additions & 0 deletions include/boost/parser/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
disable the use of concepts, define this macro. */
# define BOOST_PARSER_DISABLE_CONCEPTS

/** Boost.Parser will generate code to trace the execution of each and every
parser by default. To disable all trace code, define this macro. */
# define BOOST_PARSER_DISABLE_TRACE

/** Define this macro to use `boost::hana::tuple` instead of `std::tuple`
throughout Boost.Parser. */
# define BOOST_PARSER_USE_HANA_TUPLE
Expand Down Expand Up @@ -92,6 +96,12 @@
# define BOOST_PARSER_USE_CONCEPTS 0
#endif

#if defined(BOOST_PARSER_DISABLE_TRACE)
# define BOOST_PARSER_DO_TRACE 0
#else
# define BOOST_PARSER_DO_TRACE 1
#endif

#if defined(__cpp_lib_ranges) && BOOST_PARSER_USE_CONCEPTS
# define BOOST_PARSER_SUBRANGE std::ranges::subrange
#else
Expand Down
13 changes: 12 additions & 1 deletion include/boost/parser/detail/printing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,14 @@ namespace boost { namespace parser { namespace detail {
}

template<typename Context, typename T>
auto resolve(Context const & context, T const & x);
decltype(auto) resolve(Context const & context, T const & x);

template<typename Context>
auto resolve(Context const &, nope n);

template<typename DependentType, bool DoTraceMacro>
constexpr bool trace_disabled = !DoTraceMacro;

template<
bool DoTrace,
typename Iter,
Expand All @@ -606,6 +609,8 @@ namespace boost { namespace parser { namespace detail {
typename Attribute>
struct scoped_trace_t
{
static_assert(!trace_disabled<Iter, BOOST_PARSER_DO_TRACE>);

scoped_trace_t(
std::ostream & os,
Iter & first,
Expand Down Expand Up @@ -681,6 +686,9 @@ namespace boost { namespace parser { namespace detail {
flags f,
Attribute const & attr)
{
if constexpr (!BOOST_PARSER_DO_TRACE)
return;

if constexpr (Context::do_trace) {
std::stringstream oss;
detail::print_parser(context, parser, oss);
Expand All @@ -695,6 +703,9 @@ namespace boost { namespace parser { namespace detail {
template<typename Context, typename Attribute>
auto final_trace(Context const & context, flags f, Attribute const & attr)
{
if constexpr (!BOOST_PARSER_DO_TRACE)
return;

if (!detail::do_trace(f))
return;

Expand Down
Loading
Loading