├── src ├── test │ └── pegtl │ │ ├── data │ │ ├── fail34.json │ │ ├── fail37.json │ │ ├── fail29.json │ │ ├── fail30.json │ │ ├── fail31.json │ │ ├── fail38.json │ │ ├── fail16.json │ │ ├── fail33.json │ │ ├── fail2.json │ │ ├── fail24.json │ │ ├── fail4.json │ │ ├── fail8.json │ │ ├── fail19.json │ │ ├── fail23.json │ │ ├── fail27.json │ │ ├── fail28.json │ │ ├── fail35.json │ │ ├── fail36.json │ │ ├── fail9.json │ │ ├── fail20.json │ │ ├── fail5.json │ │ ├── fail6.json │ │ ├── fail7.json │ │ ├── fail11.json │ │ ├── fail12.json │ │ ├── fail14.json │ │ ├── fail21.json │ │ ├── fail25.json │ │ ├── fail15.json │ │ ├── fail17.json │ │ ├── fail22.json │ │ ├── fail3.json │ │ ├── fail26.json │ │ ├── fail32.json │ │ ├── fail13.json │ │ ├── fail18.json │ │ ├── pass2.json │ │ ├── fail1.json │ │ ├── fail10.json │ │ ├── fail39.json │ │ ├── pass3.json │ │ └── pass1.json │ │ ├── file_data.txt │ │ ├── file_äöü𝄞_data.txt │ │ ├── test_empty.cpp │ │ ├── file_file.cpp │ │ ├── rule_if_then_else.cpp │ │ ├── rule_if_must_else.cpp │ │ ├── rule_seq.cpp │ │ ├── contains.cpp │ │ ├── main.hpp │ │ ├── file_mmap.cpp │ │ ├── rule_enable.cpp │ │ ├── rule_disable.cpp │ │ ├── argv_input.cpp │ │ ├── contrib_print.cpp │ │ ├── icu_general.cpp │ │ ├── file_read.cpp │ │ ├── rule_discard.cpp │ │ ├── rule_success.cpp │ │ ├── contrib_separated_seq.cpp │ │ ├── visit.cpp │ │ ├── rule_action.cpp │ │ ├── rule_control.cpp │ │ ├── rule_eof.cpp │ │ ├── rule_failure.cpp │ │ ├── rule_everything.cpp │ │ ├── rule_must.cpp │ │ ├── contrib_function.cpp │ │ ├── contrib_partial_trace.cpp │ │ ├── result_type.hpp │ │ ├── ascii_two.cpp │ │ ├── contrib_if_then.cpp │ │ ├── file_cstream.cpp │ │ ├── rule_try_catch_return_false.cpp │ │ ├── verify_char.hpp │ │ ├── internal_file_opener.cpp │ │ ├── test_result.cpp │ │ ├── data_cstring.cpp │ │ ├── error_message_2.cpp │ │ ├── contrib_trace1.cpp │ │ ├── error_message_3.cpp │ │ ├── rule_state.cpp │ │ ├── rule_bol.cpp │ │ ├── contrib_parse_tree_to_dot.cpp │ │ ├── restart_input.cpp │ │ ├── rule_bof.cpp │ │ ├── ascii_three.cpp │ │ ├── rule_raise.cpp │ │ ├── check_bytes.cpp │ │ ├── limit_bytes.cpp │ │ ├── file_istream.cpp │ │ ├── contrib_to_string.cpp │ │ ├── test_setup.cpp │ │ ├── error_message.cpp │ │ ├── rule_try_catch_raise_nested.cpp │ │ ├── action_enable.cpp │ │ └── contrib_limit_depth.cpp └── example │ └── pegtl │ ├── json_print_debug.cpp │ ├── json_print_names.cpp │ ├── analyze.cpp │ ├── uri_print_debug.cpp │ ├── uri_print_names.cpp │ ├── json_analyze.cpp │ ├── lua53_analyze.cpp │ ├── lua53_parse.cpp │ ├── parse_tree_user_state.cpp │ ├── uri_trace.cpp │ ├── proto3.cpp │ ├── modulus_match.cpp │ ├── json_unescape.hpp │ ├── hello_world.cpp │ ├── json_trace.cpp │ └── json_coverage.cpp ├── .codecov.yml ├── .gitignore ├── .cmake └── pegtl-config.cmake.in ├── .pkg-config └── pegtl.pc.in ├── include └── tao │ ├── pegtl │ ├── config.hpp │ ├── version.hpp │ ├── require_apply.hpp │ ├── require_apply0.hpp │ ├── rewind_mode.hpp │ ├── tracking_mode.hpp │ ├── apply_mode.hpp │ ├── nothing.hpp │ ├── contrib │ │ ├── forward.hpp │ │ ├── internal │ │ │ ├── peek_uint8.hpp │ │ │ ├── peek_mask_uint8.hpp │ │ │ ├── peek_utf32.hpp │ │ │ ├── vector_stack_guard.hpp │ │ │ ├── peek_uint.hpp │ │ │ └── set_stack_guard.hpp │ │ ├── to_string.hpp │ │ ├── json_pointer.hpp │ │ ├── instantiate.hpp │ │ ├── rep_string.hpp │ │ ├── separated_seq.hpp │ │ └── function.hpp │ ├── internal │ │ ├── dependent_false.hpp │ │ ├── result_on_found.hpp │ │ ├── list.hpp │ │ ├── list_tail.hpp │ │ ├── pad_opt.hpp │ │ ├── minus.hpp │ │ ├── rep_min.hpp │ │ ├── list_tail_pad.hpp │ │ ├── has_unwind.hpp │ │ ├── stream_to_string.hpp │ │ ├── has_error_message.hpp │ │ ├── star_must.hpp │ │ ├── list_must.hpp │ │ ├── bump_help.hpp │ │ ├── identifier.hpp │ │ ├── if_must_else.hpp │ │ ├── pad.hpp │ │ ├── has_apply.hpp │ │ ├── has_apply0.hpp │ │ ├── path_to_string.hpp │ │ ├── data_and_size.hpp │ │ ├── bof.hpp │ │ ├── bol.hpp │ │ ├── eof.hpp │ │ ├── failure.hpp │ │ ├── success.hpp │ │ ├── enable_control.hpp │ │ ├── has_current_position.hpp │ │ ├── peek_char.hpp │ │ ├── star.hpp │ │ ├── eol.hpp │ │ ├── discard.hpp │ │ ├── missing_apply0.hpp │ │ ├── opt.hpp │ │ ├── eolf.hpp │ │ ├── cr_eol.hpp │ │ ├── lf_eol.hpp │ │ ├── everything.hpp │ │ ├── crlf_eol.hpp │ │ ├── cr_crlf_eol.hpp │ │ ├── extract_position.hpp │ │ ├── missing_apply.hpp │ │ ├── unwind_guard.hpp │ │ ├── require.hpp │ │ ├── cstring_reader.hpp │ │ ├── bytes.hpp │ │ ├── apply0_single.hpp │ │ ├── mmap_file.hpp │ │ ├── lf_crlf_eol.hpp │ │ ├── bump.hpp │ │ ├── apply_single.hpp │ │ ├── partial.hpp │ │ ├── star_partial.hpp │ │ ├── raise.hpp │ │ ├── has_match.hpp │ │ ├── inputerator.hpp │ │ ├── istream_reader.hpp │ │ ├── apply0.hpp │ │ ├── enable.hpp │ │ ├── disable.hpp │ │ └── at.hpp │ ├── cstream_input.hpp │ ├── istream_input.hpp │ ├── enable_action.hpp │ ├── disable_action.hpp │ ├── change_control.hpp │ ├── discard_input.hpp │ ├── eol.hpp │ ├── discard_input_on_success.hpp │ ├── discard_input_on_failure.hpp │ ├── type_list.hpp │ ├── parse_error_base.hpp │ ├── change_action.hpp │ ├── file_input.hpp │ ├── argv_input.hpp │ ├── utf8.hpp │ └── mmap_input.hpp │ └── pegtl.hpp ├── .github └── workflows │ ├── clang-format.yml │ ├── clang-analyze.yml │ ├── code-coverage.yml │ ├── sanitizer.yml │ ├── clang-tidy.yml │ ├── android.yml │ ├── msys.yml │ └── macos.yml └── LICENSE_1_0.txt /src/test/pegtl/data/fail34.json: -------------------------------------------------------------------------------- 1 | 00 -------------------------------------------------------------------------------- /src/test/pegtl/data/fail37.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/pegtl/data/fail29.json: -------------------------------------------------------------------------------- 1 | [0e] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail30.json: -------------------------------------------------------------------------------- 1 | [0e+] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail31.json: -------------------------------------------------------------------------------- 1 | [0e+-1] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail38.json: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/test/pegtl/data/fail16.json: -------------------------------------------------------------------------------- 1 | [\naked] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail33.json: -------------------------------------------------------------------------------- 1 | ["mismatch"} -------------------------------------------------------------------------------- /src/test/pegtl/data/fail2.json: -------------------------------------------------------------------------------- 1 | ["Unclosed array" -------------------------------------------------------------------------------- /src/test/pegtl/data/fail24.json: -------------------------------------------------------------------------------- 1 | ['single quote'] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail4.json: -------------------------------------------------------------------------------- 1 | ["extra comma",] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail8.json: -------------------------------------------------------------------------------- 1 | ["Extra close"]] -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | ignore: 2 | - src/example/**/* 3 | -------------------------------------------------------------------------------- /src/test/pegtl/data/fail19.json: -------------------------------------------------------------------------------- 1 | {"Missing colon" null} -------------------------------------------------------------------------------- /src/test/pegtl/data/fail23.json: -------------------------------------------------------------------------------- 1 | ["Bad value", truth] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail27.json: -------------------------------------------------------------------------------- 1 | ["line 2 | break"] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail28.json: -------------------------------------------------------------------------------- 1 | ["line\ 2 | break"] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail35.json: -------------------------------------------------------------------------------- 1 | ["bracket mismatch"} -------------------------------------------------------------------------------- /src/test/pegtl/data/fail36.json: -------------------------------------------------------------------------------- 1 | {"bracket":"mismatch"] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail9.json: -------------------------------------------------------------------------------- 1 | {"Extra comma": true,} -------------------------------------------------------------------------------- /src/test/pegtl/data/fail20.json: -------------------------------------------------------------------------------- 1 | {"Double colon":: null} -------------------------------------------------------------------------------- /src/test/pegtl/data/fail5.json: -------------------------------------------------------------------------------- 1 | ["double extra comma",,] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail6.json: -------------------------------------------------------------------------------- 1 | [ , "<-- missing value"] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail7.json: -------------------------------------------------------------------------------- 1 | ["Comma after the close"], -------------------------------------------------------------------------------- /src/test/pegtl/data/fail11.json: -------------------------------------------------------------------------------- 1 | {"Illegal expression": 1 + 2} -------------------------------------------------------------------------------- /src/test/pegtl/data/fail12.json: -------------------------------------------------------------------------------- 1 | {"Illegal invocation": alert()} -------------------------------------------------------------------------------- /src/test/pegtl/data/fail14.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot be hex": 0x14} -------------------------------------------------------------------------------- /src/test/pegtl/data/fail21.json: -------------------------------------------------------------------------------- 1 | {"Comma instead of colon", null} -------------------------------------------------------------------------------- /src/test/pegtl/data/fail25.json: -------------------------------------------------------------------------------- 1 | [" tab character in string "] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail15.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \x15"] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail17.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \017"] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail22.json: -------------------------------------------------------------------------------- 1 | ["Colon instead of comma": false] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail3.json: -------------------------------------------------------------------------------- 1 | {unquoted_key: "keys must be quoted"} -------------------------------------------------------------------------------- /src/test/pegtl/data/fail26.json: -------------------------------------------------------------------------------- 1 | ["tab\ character\ in\ string\ "] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail32.json: -------------------------------------------------------------------------------- 1 | {"Comma instead if closing brace": true, -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | build 3 | private 4 | /.vs 5 | /.vscode 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /src/test/pegtl/data/fail13.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot have leading zeroes": 013} -------------------------------------------------------------------------------- /src/test/pegtl/data/fail18.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /src/test/pegtl/data/pass2.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /src/test/pegtl/data/fail1.json: -------------------------------------------------------------------------------- 1 | "A JSON payload should be an object or array, not a string." -------------------------------------------------------------------------------- /src/test/pegtl/data/fail10.json: -------------------------------------------------------------------------------- 1 | {"Extra value after close": true} "misplaced quoted value" -------------------------------------------------------------------------------- /src/test/pegtl/data/fail39.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taocpp/PEGTL/HEAD/src/test/pegtl/data/fail39.json -------------------------------------------------------------------------------- /src/test/pegtl/data/pass3.json: -------------------------------------------------------------------------------- 1 | { 2 | "JSON Test Pattern pass3": { 3 | "The outermost value": "must be an object or array.", 4 | "In this test": "It is an object." 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/test/pegtl/file_data.txt: -------------------------------------------------------------------------------- 1 | dummy content 2 | dummy content 3 | dummy content 4 | dummy content 5 | dummy content 6 | dummy content 7 | dummy content 8 | dummy content 9 | dummy content 10 | dummy content 11 | dummy content 12 | -------------------------------------------------------------------------------- /.cmake/pegtl-config.cmake.in: -------------------------------------------------------------------------------- 1 | # When a dependency is added with add_subdirectory, but searched with find_package 2 | 3 | # Redirect to the directory added with add_subdirectory 4 | add_subdirectory("@PROJECT_SOURCE_DIR@" "@PROJECT_BINARY_DIR@") 5 | -------------------------------------------------------------------------------- /src/test/pegtl/file_äöü𝄞_data.txt: -------------------------------------------------------------------------------- 1 | dummy content 2 | dummy content 3 | dummy content 4 | dummy content 5 | dummy content 6 | dummy content 7 | dummy content 8 | dummy content 9 | dummy content 10 | dummy content 11 | dummy content 12 | -------------------------------------------------------------------------------- /.pkg-config/pegtl.pc.in: -------------------------------------------------------------------------------- 1 | includedir="@CMAKE_INSTALL_PREFIX@/@PEGTL_INSTALL_INCLUDE_DIR@" 2 | 3 | Name: @PROJECT_NAME@ 4 | Description: @CMAKE_PROJECT_DESCRIPTION@ 5 | Version: @PROJECT_VERSION@ 6 | URL: @CMAKE_PROJECT_HOMEPAGE_URL@ 7 | Cflags: -I${includedir} -------------------------------------------------------------------------------- /include/tao/pegtl/config.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONFIG_HPP 6 | #define TAO_PEGTL_CONFIG_HPP 7 | 8 | #if !defined( TAO_PEGTL_NAMESPACE ) 9 | #define TAO_PEGTL_NAMESPACE tao::pegtl 10 | #endif 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/test/pegtl/test_empty.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | namespace TAO_PEGTL_NAMESPACE 8 | { 9 | void unit_test() 10 | {} 11 | 12 | } // namespace TAO_PEGTL_NAMESPACE 13 | 14 | #include "main.hpp" 15 | -------------------------------------------------------------------------------- /.github/workflows/clang-format.yml: -------------------------------------------------------------------------------- 1 | name: clang-format 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - 'README.md' 7 | - 'doc/**' 8 | pull_request: 9 | paths-ignore: 10 | - 'README.md' 11 | - 'doc/**' 12 | 13 | jobs: 14 | clang-format: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | - uses: DoozyX/clang-format-lint-action@v0.15 20 | with: 21 | extensions: 'hpp,cpp' 22 | clangFormatVersion: 15 23 | -------------------------------------------------------------------------------- /include/tao/pegtl/version.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_VERSION_HPP 6 | #define TAO_PEGTL_VERSION_HPP 7 | 8 | #define TAO_PEGTL_VERSION "4.0.0" 9 | 10 | #define TAO_PEGTL_VERSION_MAJOR 4 11 | #define TAO_PEGTL_VERSION_MINOR 0 12 | #define TAO_PEGTL_VERSION_PATCH 0 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/test/pegtl/file_file.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_file.hpp" 7 | 8 | namespace TAO_PEGTL_NAMESPACE 9 | { 10 | void unit_test() 11 | { 12 | verify_file< file_input<> >(); 13 | } 14 | 15 | } // namespace TAO_PEGTL_NAMESPACE 16 | 17 | #include "main.hpp" 18 | -------------------------------------------------------------------------------- /include/tao/pegtl/require_apply.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_REQUIRE_APPLY_HPP 6 | #define TAO_PEGTL_REQUIRE_APPLY_HPP 7 | 8 | #include "config.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | struct require_apply 13 | {}; 14 | 15 | } // namespace TAO_PEGTL_NAMESPACE 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/tao/pegtl/require_apply0.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_REQUIRE_APPLY0_HPP 6 | #define TAO_PEGTL_REQUIRE_APPLY0_HPP 7 | 8 | #include "config.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | struct require_apply0 13 | {}; 14 | 15 | } // namespace TAO_PEGTL_NAMESPACE 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/example/pegtl/json_print_debug.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | int main() // NOLINT(bugprone-exception-escape) 11 | { 12 | TAO_PEGTL_NAMESPACE::print_debug< TAO_PEGTL_NAMESPACE::json::text >( std::cout ); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/example/pegtl/json_print_names.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | int main() // NOLINT(bugprone-exception-escape) 11 | { 12 | TAO_PEGTL_NAMESPACE::print_names< TAO_PEGTL_NAMESPACE::json::text >( std::cout ); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /include/tao/pegtl/rewind_mode.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_REWIND_MODE_HPP 6 | #define TAO_PEGTL_REWIND_MODE_HPP 7 | 8 | #include "config.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | enum class rewind_mode : bool 13 | { 14 | required, 15 | optional 16 | }; 17 | 18 | } // namespace TAO_PEGTL_NAMESPACE 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/tao/pegtl/tracking_mode.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_TRACKING_MODE_HPP 6 | #define TAO_PEGTL_TRACKING_MODE_HPP 7 | 8 | #include "config.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | enum class tracking_mode : bool 13 | { 14 | eager, 15 | lazy 16 | }; 17 | 18 | } // namespace TAO_PEGTL_NAMESPACE 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/tao/pegtl/apply_mode.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_APPLY_MODE_HPP 6 | #define TAO_PEGTL_APPLY_MODE_HPP 7 | 8 | #include "config.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | enum class apply_mode : bool 13 | { 14 | action = true, 15 | nothing = false 16 | }; 17 | 18 | } // namespace TAO_PEGTL_NAMESPACE 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/tao/pegtl/nothing.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_NOTHING_HPP 6 | #define TAO_PEGTL_NOTHING_HPP 7 | 8 | #include "config.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | template< typename Rule > 13 | struct nothing 14 | {}; 15 | 16 | using maybe_nothing = nothing< void >; 17 | 18 | } // namespace TAO_PEGTL_NAMESPACE 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/forward.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_FORWARD_HPP 6 | #define TAO_PEGTL_CONTRIB_FORWARD_HPP 7 | 8 | #include "../config.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | template< typename Name, typename Rule, typename = void > 13 | struct analyze_traits; 14 | 15 | } // namespace TAO_PEGTL_NAMESPACE 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/dependent_false.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_DEPENDENT_FALSE_HPP 6 | #define TAO_PEGTL_INTERNAL_DEPENDENT_FALSE_HPP 7 | 8 | #include "../config.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE::internal 11 | { 12 | template< typename... > 13 | inline constexpr bool dependent_false = false; 14 | 15 | } // namespace TAO_PEGTL_NAMESPACE::internal 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/result_on_found.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_RESULT_ON_FOUND_HPP 6 | #define TAO_PEGTL_INTERNAL_RESULT_ON_FOUND_HPP 7 | 8 | #include "../config.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE::internal 11 | { 12 | enum class result_on_found : bool 13 | { 14 | success = true, 15 | failure = false 16 | }; 17 | 18 | } // namespace TAO_PEGTL_NAMESPACE::internal 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/list.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_LIST_HPP 6 | #define TAO_PEGTL_INTERNAL_LIST_HPP 7 | 8 | #include "seq.hpp" 9 | #include "star.hpp" 10 | 11 | #include "../config.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | template< typename Rule, typename Sep > 16 | using list = seq< Rule, star< Sep, Rule > >; 17 | 18 | } // namespace TAO_PEGTL_NAMESPACE::internal 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_if_then_else.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_ifmt.hpp" 7 | 8 | namespace TAO_PEGTL_NAMESPACE 9 | { 10 | void unit_test() 11 | { 12 | verify_meta< if_then_else< digit, alpha, print >, internal::if_then_else< digit, alpha, print >, digit, alpha, print >(); 13 | 14 | verify_ifmt< if_then_else >(); 15 | } 16 | 17 | } // namespace TAO_PEGTL_NAMESPACE 18 | 19 | #include "main.hpp" 20 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/list_tail.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_LIST_TAIL_HPP 6 | #define TAO_PEGTL_INTERNAL_LIST_TAIL_HPP 7 | 8 | #include "seq.hpp" 9 | #include "star_partial.hpp" 10 | 11 | #include "../config.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | template< typename Rule, typename Sep > 16 | using list_tail = seq< Rule, star_partial< Sep, Rule > >; 17 | 18 | } // namespace TAO_PEGTL_NAMESPACE::internal 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /.github/workflows/clang-analyze.yml: -------------------------------------------------------------------------------- 1 | name: clang-analyze 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - 'README.md' 7 | - 'doc/**' 8 | pull_request: 9 | paths-ignore: 10 | - 'README.md' 11 | - 'doc/**' 12 | 13 | jobs: 14 | clang-analyze: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - run: sudo apt-get update -yq 21 | 22 | - run: sudo apt-get install -yq clang-tools 23 | 24 | - run: scan-build cmake -E make_directory build 25 | 26 | - working-directory: build/ 27 | run: scan-build cmake $GITHUB_WORKSPACE 28 | 29 | - working-directory: build/ 30 | run: scan-build cmake --build . 31 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/pad_opt.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_PAD_OPT_HPP 6 | #define TAO_PEGTL_INTERNAL_PAD_OPT_HPP 7 | 8 | #include "opt.hpp" 9 | #include "seq.hpp" 10 | #include "star.hpp" 11 | 12 | #include "../config.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE::internal 15 | { 16 | template< typename Rule, typename Pad > 17 | using pad_opt = seq< star< Pad >, opt< Rule, star< Pad > > >; 18 | 19 | } // namespace TAO_PEGTL_NAMESPACE::internal 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/minus.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_MINUS_HPP 6 | #define TAO_PEGTL_INTERNAL_MINUS_HPP 7 | 8 | #include "eof.hpp" 9 | #include "not_at.hpp" 10 | #include "rematch.hpp" 11 | #include "seq.hpp" 12 | 13 | #include "../config.hpp" 14 | 15 | namespace TAO_PEGTL_NAMESPACE::internal 16 | { 17 | template< typename M, typename S > 18 | using minus = rematch< M, not_at< S, eof > >; 19 | 20 | } // namespace TAO_PEGTL_NAMESPACE::internal 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/rep_min.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_REP_MIN_HPP 6 | #define TAO_PEGTL_INTERNAL_REP_MIN_HPP 7 | 8 | #include "rep.hpp" 9 | #include "seq.hpp" 10 | #include "star.hpp" 11 | 12 | #include "../config.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE::internal 15 | { 16 | template< unsigned Min, typename Rule, typename... Rules > 17 | using rep_min = seq< rep< Min, Rule, Rules... >, star< Rule, Rules... > >; 18 | 19 | } // namespace TAO_PEGTL_NAMESPACE::internal 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/example/pegtl/analyze.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include 8 | 9 | using namespace TAO_PEGTL_NAMESPACE; 10 | 11 | struct bar; 12 | 13 | struct foo 14 | : sor< digit, bar > 15 | {}; 16 | 17 | struct bar 18 | : plus< foo > // seq< foo, opt< bar > > 19 | {}; 20 | 21 | int main() // NOLINT(bugprone-exception-escape) 22 | { 23 | if( analyze< foo >( 1 ) != 0 ) { 24 | std::cerr << "there are problems" << std::endl; 25 | return 1; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_if_must_else.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cout << "Exception support disabled, skipping test..." << std::endl; 10 | } 11 | #else 12 | 13 | #include "test.hpp" 14 | #include "verify_ifmt.hpp" 15 | 16 | namespace TAO_PEGTL_NAMESPACE 17 | { 18 | void unit_test() 19 | { 20 | verify_ifmt< if_must_else >( result_type::global_failure ); 21 | } 22 | 23 | } // namespace TAO_PEGTL_NAMESPACE 24 | 25 | #include "main.hpp" 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_seq.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include "verify_meta.hpp" 8 | #include "verify_seqs.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | void unit_test() 13 | { 14 | verify_meta< seq<>, internal::success >(); 15 | verify_meta< seq< alpha >, internal::seq< alpha >, alpha >(); 16 | verify_meta< seq< alpha, digit >, internal::seq< alpha, digit >, alpha, digit >(); 17 | 18 | verify_seqs< seq >(); 19 | } 20 | 21 | } // namespace TAO_PEGTL_NAMESPACE 22 | 23 | #include "main.hpp" 24 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/list_tail_pad.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_LIST_TAIL_PAD_HPP 6 | #define TAO_PEGTL_INTERNAL_LIST_TAIL_PAD_HPP 7 | 8 | #include "pad.hpp" 9 | #include "seq.hpp" 10 | #include "star_partial.hpp" 11 | 12 | #include "../config.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE::internal 15 | { 16 | template< typename Rule, typename Sep, typename Pad > 17 | using list_tail_pad = seq< Rule, star_partial< lpad< Sep, Pad >, lpad< Rule, Pad > > >; 18 | 19 | } // namespace TAO_PEGTL_NAMESPACE::internal 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/example/pegtl/uri_print_debug.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cerr << "Exception support required, example unavailable." << std::endl; 10 | return 1; 11 | } 12 | #else 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | int main() // NOLINT(bugprone-exception-escape) 20 | { 21 | TAO_PEGTL_NAMESPACE::print_debug< TAO_PEGTL_NAMESPACE::uri::URI >( std::cout ); 22 | return 0; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/example/pegtl/uri_print_names.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cerr << "Exception support required, example unavailable." << std::endl; 10 | return 1; 11 | } 12 | #else 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | int main() // NOLINT(bugprone-exception-escape) 20 | { 21 | TAO_PEGTL_NAMESPACE::print_names< TAO_PEGTL_NAMESPACE::uri::URI >( std::cout ); 22 | return 0; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/test/pegtl/contains.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include "test.hpp" 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | // clang-format off 12 | struct A : plus< alpha, opt< A > > {}; 13 | struct B : star< sor< space, digit, A > > {}; 14 | struct grammar : seq< A, B > {}; 15 | // clang-format on 16 | 17 | void unit_test() 18 | { 19 | static_assert( contains_v< grammar, digit > ); 20 | static_assert( !contains_v< grammar, xdigit > ); 21 | } 22 | 23 | } // namespace TAO_PEGTL_NAMESPACE 24 | 25 | #include "main.hpp" 26 | -------------------------------------------------------------------------------- /src/test/pegtl/main.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_SRC_TEST_PEGTL_MAIN_HPP 6 | #define TAO_PEGTL_SRC_TEST_PEGTL_MAIN_HPP 7 | 8 | #include 9 | #include 10 | 11 | int main( int /*unused*/, char** argv ) 12 | { 13 | TAO_PEGTL_NAMESPACE::unit_test(); 14 | 15 | if( TAO_PEGTL_NAMESPACE::failed != 0 ) { 16 | std::cerr << "pegtl: unit test " << argv[ 0 ] << " failed " << TAO_PEGTL_NAMESPACE::failed << std::endl; // LCOV_EXCL_LINE 17 | } 18 | return ( TAO_PEGTL_NAMESPACE::failed == 0 ) ? EXIT_SUCCESS : EXIT_FAILURE; 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/has_unwind.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_HAS_UNWIND_HPP 6 | #define TAO_PEGTL_INTERNAL_HAS_UNWIND_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | template< typename, typename... > 15 | inline constexpr bool has_unwind = false; 16 | 17 | template< typename C, typename... S > 18 | inline constexpr bool has_unwind< C, decltype( C::unwind( std::declval< S >()... ) ), S... > = true; 19 | 20 | } // namespace TAO_PEGTL_NAMESPACE::internal 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/test/pegtl/file_mmap.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | // this include gives us _POSIX_MAPPED_FILES to test and mmap_input<> if it is set 6 | #include 7 | 8 | #if defined( _POSIX_MAPPED_FILES ) || defined( _WIN32 ) 9 | 10 | #include "test.hpp" 11 | #include "verify_file.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE 14 | { 15 | void unit_test() 16 | { 17 | verify_file< mmap_input<> >(); 18 | } 19 | 20 | } // namespace TAO_PEGTL_NAMESPACE 21 | 22 | #include "main.hpp" 23 | 24 | #else 25 | 26 | int main() 27 | { 28 | return 0; 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_enable.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include "verify_meta.hpp" 8 | #include "verify_seqs.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | void unit_test() 13 | { 14 | verify_meta< enable<>, internal::success >(); 15 | verify_meta< enable< eof >, internal::enable< eof >, eof >(); 16 | verify_meta< enable< eof, any >, internal::enable< internal::seq< eof, any > >, internal::seq< eof, any > >(); 17 | 18 | verify_seqs< enable >(); 19 | } 20 | 21 | } // namespace TAO_PEGTL_NAMESPACE 22 | 23 | #include "main.hpp" 24 | -------------------------------------------------------------------------------- /.github/workflows/code-coverage.yml: -------------------------------------------------------------------------------- 1 | name: Code Coverage 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - 'README.md' 7 | - 'doc/**' 8 | pull_request: 9 | paths-ignore: 10 | - 'README.md' 11 | - 'doc/**' 12 | 13 | jobs: 14 | code-coverage: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - run: cmake -E make_directory build 21 | 22 | - working-directory: build/ 23 | run: cmake $GITHUB_WORKSPACE -DPEGTL_BUILD_EXAMPLES=OFF -DCMAKE_CXX_FLAGS="-coverage" 24 | 25 | - working-directory: build/ 26 | run: cmake --build . 27 | 28 | - working-directory: build/ 29 | run: ctest --output-on-failure 30 | 31 | - working-directory: build/ 32 | run: bash <(curl -s https://codecov.io/bash) 33 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_disable.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include "verify_meta.hpp" 8 | #include "verify_seqs.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | void unit_test() 13 | { 14 | verify_meta< disable<>, internal::success >(); 15 | verify_meta< disable< eof >, internal::disable< eof >, eof >(); 16 | verify_meta< disable< eof, any >, internal::disable< internal::seq< eof, any > >, internal::seq< eof, any > >(); 17 | 18 | verify_seqs< disable >(); 19 | } 20 | 21 | } // namespace TAO_PEGTL_NAMESPACE 22 | 23 | #include "main.hpp" 24 | -------------------------------------------------------------------------------- /src/test/pegtl/argv_input.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include "test.hpp" 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | void unit_test() 12 | { 13 | char data[ 12 ]; 14 | std::memcpy( data, "foo\0bar\0baz", 12 ); 15 | char* argv[] = { data, data + 4, data + 8 }; 16 | argv_input in( argv, 1 ); 17 | TAO_PEGTL_TEST_ASSERT( in.source() == "argv[1]" ); 18 | const auto result = parse< string< 'b', 'a', 'r' > >( in ); 19 | TAO_PEGTL_TEST_ASSERT( result ); 20 | } 21 | 22 | } // namespace TAO_PEGTL_NAMESPACE 23 | 24 | #include "main.hpp" 25 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/stream_to_string.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_STREAM_TO_STRING_HPP 6 | #define TAO_PEGTL_INTERNAL_STREAM_TO_STRING_HPP 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "../config.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE::internal 15 | { 16 | template< typename T > 17 | [[nodiscard]] std::string stream_to_string( const T& t ) 18 | { 19 | std::ostringstream oss; 20 | oss << t; 21 | return std::move( oss ).str(); 22 | } 23 | 24 | } // namespace TAO_PEGTL_NAMESPACE::internal 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/has_error_message.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_HAS_ERROR_MESSAGE_HPP 6 | #define TAO_PEGTL_INTERNAL_HAS_ERROR_MESSAGE_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | template< typename Rule, typename = const char* > 15 | inline constexpr bool has_error_message = false; 16 | 17 | template< typename Rule > 18 | inline constexpr bool has_error_message< Rule, std::decay_t< decltype( Rule::error_message ) > > = true; 19 | 20 | } // namespace TAO_PEGTL_NAMESPACE::internal 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/star_must.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_STAR_MUST_HPP 6 | #define TAO_PEGTL_INTERNAL_STAR_MUST_HPP 7 | 8 | #if !defined( __cpp_exceptions ) 9 | #error "Exception support required for tao/pegtl/internal/star_must.hpp" 10 | #else 11 | 12 | #include "if_must.hpp" 13 | #include "star.hpp" 14 | 15 | #include "../config.hpp" 16 | 17 | namespace TAO_PEGTL_NAMESPACE::internal 18 | { 19 | template< typename Cond, typename... Rules > 20 | using star_must = star< if_must< false, Cond, Rules... > >; 21 | 22 | } // namespace TAO_PEGTL_NAMESPACE::internal 23 | 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /src/example/pegtl/json_analyze.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace pegtl = TAO_PEGTL_NAMESPACE; 12 | 13 | namespace example 14 | { 15 | using grammar = pegtl::seq< pegtl::json::text, pegtl::eof >; 16 | 17 | } // namespace example 18 | 19 | int main() // NOLINT(bugprone-exception-escape) 20 | { 21 | if( pegtl::analyze< example::grammar >() != 0 ) { 22 | std::cerr << "cycles without progress detected!" << std::endl; 23 | return 1; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/list_must.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_LIST_MUST_HPP 6 | #define TAO_PEGTL_INTERNAL_LIST_MUST_HPP 7 | 8 | #if !defined( __cpp_exceptions ) 9 | #error "Exception support required for tao/pegtl/internal/list_must.hpp" 10 | #else 11 | 12 | #include "must.hpp" 13 | #include "seq.hpp" 14 | #include "star.hpp" 15 | 16 | #include "../config.hpp" 17 | 18 | namespace TAO_PEGTL_NAMESPACE::internal 19 | { 20 | template< typename Rule, typename Sep > 21 | using list_must = seq< Rule, star< Sep, must< Rule > > >; 22 | 23 | } // namespace TAO_PEGTL_NAMESPACE::internal 24 | 25 | #endif 26 | #endif 27 | -------------------------------------------------------------------------------- /src/example/pegtl/lua53_analyze.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cerr << "Exception support required, example unavailable." << std::endl; 10 | return 1; 11 | } 12 | #else 13 | 14 | #include 15 | 16 | #include 17 | 18 | #include "lua53.hpp" 19 | 20 | int main() // NOLINT(bugprone-exception-escape) 21 | { 22 | if( const auto problems = TAO_PEGTL_NAMESPACE::analyze< lua53::grammar >() != 0 ) { 23 | std::cout << "problems: " << problems << std::endl; 24 | return 1; 25 | } 26 | return 0; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/test/pegtl/contrib_print.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include "test.hpp" 8 | 9 | #include 10 | 11 | namespace TAO_PEGTL_NAMESPACE 12 | { 13 | using grammar = seq< alpha, digit >; 14 | 15 | void unit_test() 16 | { 17 | // Just enough to see that it compiles and nothing explodes; 18 | // the output format probabaly changes between compilers and 19 | // versions making a proper test difficult. 20 | print_names< grammar >( std::cout ); 21 | print_debug< grammar >( std::cout ); 22 | } 23 | 24 | } // namespace TAO_PEGTL_NAMESPACE 25 | 26 | #include "main.hpp" 27 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/bump_help.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_BUMP_HELP_HPP 6 | #define TAO_PEGTL_INTERNAL_BUMP_HELP_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | template< typename Rule, typename ParseInput > 15 | void bump_help( ParseInput& in, const std::size_t count ) 16 | { 17 | if constexpr( Rule::test_any( ParseInput::eol_t::ch ) ) { 18 | in.bump( count ); 19 | } 20 | else { 21 | in.bump_in_this_line( count ); 22 | } 23 | } 24 | 25 | } // namespace TAO_PEGTL_NAMESPACE::internal 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/identifier.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_IDENTIFIER_HPP 6 | #define TAO_PEGTL_INTERNAL_IDENTIFIER_HPP 7 | 8 | #include "peek_char.hpp" 9 | #include "ranges.hpp" 10 | #include "seq.hpp" 11 | #include "star.hpp" 12 | 13 | #include "../config.hpp" 14 | 15 | namespace TAO_PEGTL_NAMESPACE::internal 16 | { 17 | using identifier_first = ranges< peek_char, 'a', 'z', 'A', 'Z', '_' >; 18 | using identifier_other = ranges< peek_char, 'a', 'z', 'A', 'Z', '0', '9', '_' >; 19 | using identifier = seq< identifier_first, star< identifier_other > >; 20 | 21 | } // namespace TAO_PEGTL_NAMESPACE::internal 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/if_must_else.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_IF_MUST_ELSE_HPP 6 | #define TAO_PEGTL_INTERNAL_IF_MUST_ELSE_HPP 7 | 8 | #if !defined( __cpp_exceptions ) 9 | #error "Exception support required for tao/pegtl/internal/if_must_else.hpp" 10 | #else 11 | 12 | #include "if_then_else.hpp" 13 | #include "must.hpp" 14 | 15 | #include "../config.hpp" 16 | 17 | namespace TAO_PEGTL_NAMESPACE::internal 18 | { 19 | template< typename Cond, typename Then, typename Else > 20 | using if_must_else = if_then_else< Cond, must< Then >, must< Else > >; 21 | 22 | } // namespace TAO_PEGTL_NAMESPACE::internal 23 | 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /src/test/pegtl/icu_general.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_meta.hpp" 7 | #include "verify_rule.hpp" 8 | 9 | //#include 10 | 11 | namespace TAO_PEGTL_NAMESPACE 12 | { 13 | void unit_test() 14 | { 15 | // verify_analyze< utf8::icu::alphabetic >( __LINE__, __FILE__, true, false ); 16 | 17 | // verify_rule< utf8::icu::alphabetic >( __LINE__, __FILE__, "", result_type::local_failure, 0 ); 18 | // verify_rule< utf8::icu::alphabetic >( __LINE__, __FILE__, "a", result_type::success ); 19 | } 20 | 21 | } // namespace TAO_PEGTL_NAMESPACE 22 | 23 | #include "main.hpp" 24 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/pad.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_PAD_HPP 6 | #define TAO_PEGTL_INTERNAL_PAD_HPP 7 | 8 | #include "seq.hpp" 9 | #include "star.hpp" 10 | 11 | #include "../config.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | template< typename Rule, typename Pad1 > 16 | using lpad = seq< star< Pad1 >, Rule >; 17 | 18 | template< typename Rule, typename Pad1, typename Pad2 = Pad1 > 19 | using pad = seq< star< Pad1 >, Rule, star< Pad2 > >; 20 | 21 | template< typename Rule, typename Pad2 > 22 | using rpad = seq< Rule, star< Pad2 > >; 23 | 24 | } // namespace TAO_PEGTL_NAMESPACE::internal 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/has_apply.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_HAS_APPLY_HPP 6 | #define TAO_PEGTL_INTERNAL_HAS_APPLY_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | template< typename, typename, template< typename... > class, typename... > 15 | inline constexpr bool has_apply = false; 16 | 17 | template< typename C, template< typename... > class Action, typename... S > 18 | inline constexpr bool has_apply< C, decltype( C::template apply< Action >( std::declval< S >()... ) ), Action, S... > = true; 19 | 20 | } // namespace TAO_PEGTL_NAMESPACE::internal 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/example/pegtl/lua53_parse.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cerr << "Exception support required, example unavailable." << std::endl; 10 | return 1; 11 | } 12 | #else 13 | 14 | #include 15 | 16 | #include "lua53.hpp" 17 | 18 | int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) 19 | { 20 | for( int i = 1; i < argc; ++i ) { 21 | TAO_PEGTL_NAMESPACE::file_input in( argv[ i ] ); 22 | const auto r = TAO_PEGTL_NAMESPACE::parse< lua53::grammar >( in ); 23 | std::cout << argv[ i ] << " " << r << std::endl; 24 | } 25 | return 0; 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/test/pegtl/file_read.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_file.hpp" 7 | 8 | namespace TAO_PEGTL_NAMESPACE 9 | { 10 | template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > 11 | struct open_input 12 | : public read_input< P, Eol > 13 | { 14 | explicit open_input( const std::filesystem::path& path ) 15 | : read_input< P, Eol >( internal::read_file_open( path ), path ) 16 | {} 17 | }; 18 | 19 | void unit_test() 20 | { 21 | verify_file< read_input<> >(); 22 | verify_file< open_input<> >(); 23 | } 24 | 25 | } // namespace TAO_PEGTL_NAMESPACE 26 | 27 | #include "main.hpp" 28 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/has_apply0.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_HAS_APPLY0_HPP 6 | #define TAO_PEGTL_INTERNAL_HAS_APPLY0_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | template< typename, typename, template< typename... > class, typename... > 15 | inline constexpr bool has_apply0 = false; 16 | 17 | template< typename C, template< typename... > class Action, typename... S > 18 | inline constexpr bool has_apply0< C, decltype( C::template apply0< Action >( std::declval< S >()... ) ), Action, S... > = true; 19 | 20 | } // namespace TAO_PEGTL_NAMESPACE::internal 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/path_to_string.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_PATH_TO_STRING_HPP 6 | #define TAO_PEGTL_INTERNAL_PATH_TO_STRING_HPP 7 | 8 | #include 9 | #include 10 | 11 | #include "../config.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | [[nodiscard]] inline std::string path_to_string( const std::filesystem::path& path ) 16 | { 17 | #if defined( __cpp_char8_t ) 18 | const auto s = path.u8string(); 19 | return { reinterpret_cast< const char* >( s.data() ), s.size() }; 20 | #else 21 | return path.u8string(); 22 | #endif 23 | } 24 | 25 | } // namespace TAO_PEGTL_NAMESPACE::internal 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/data_and_size.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_DATA_AND_SIZE_HPP 6 | #define TAO_PEGTL_INTERNAL_DATA_AND_SIZE_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | template< typename Data > 15 | struct data_and_size 16 | { 17 | Data data; 18 | std::size_t size; 19 | 20 | using data_t = Data; 21 | 22 | [[nodiscard]] explicit operator bool() const noexcept 23 | { 24 | return size > 0; 25 | } 26 | }; 27 | 28 | using bool_and_size = data_and_size< bool >; 29 | 30 | } // namespace TAO_PEGTL_NAMESPACE::internal 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /.github/workflows/sanitizer.yml: -------------------------------------------------------------------------------- 1 | name: Sanitizer 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - 'README.md' 7 | - 'doc/**' 8 | pull_request: 9 | paths-ignore: 10 | - 'README.md' 11 | - 'doc/**' 12 | 13 | jobs: 14 | sanitizer: 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | cxx: [g++, clang++] 19 | sanitizer: [address, undefined] 20 | 21 | runs-on: ubuntu-latest 22 | 23 | env: 24 | CXX: ${{ matrix.cxx }} 25 | 26 | steps: 27 | - uses: actions/checkout@v3 28 | 29 | - run: cmake -E make_directory build 30 | 31 | - working-directory: build/ 32 | run: cmake $GITHUB_WORKSPACE -DPEGTL_BUILD_EXAMPLES=OFF -DCMAKE_CXX_FLAGS="-fsanitize=${{ matrix.sanitizer }}" 33 | 34 | - working-directory: build/ 35 | run: cmake --build . 36 | 37 | - working-directory: build/ 38 | run: ctest --output-on-failure 39 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_discard.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include "verify_meta.hpp" 8 | #include "verify_rule.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | void unit_test() 13 | { 14 | verify_meta< discard, internal::discard >(); 15 | 16 | verify_analyze< discard >( __LINE__, __FILE__, false, false ); 17 | 18 | verify_rule< discard >( __LINE__, __FILE__, "", result_type::success, 0 ); 19 | 20 | for( char i = 1; i < 127; ++i ) { 21 | char t[] = { i, 0 }; 22 | verify_rule< discard >( __LINE__, __FILE__, std::string( t ), result_type::success, 1 ); 23 | } 24 | } 25 | 26 | } // namespace TAO_PEGTL_NAMESPACE 27 | 28 | #include "main.hpp" 29 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_success.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include "verify_meta.hpp" 8 | #include "verify_rule.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | void unit_test() 13 | { 14 | verify_meta< success, internal::success >(); 15 | 16 | verify_analyze< success >( __LINE__, __FILE__, false, false ); 17 | 18 | verify_rule< success >( __LINE__, __FILE__, "", result_type::success, 0 ); 19 | 20 | for( char i = 1; i < 127; ++i ) { 21 | char t[] = { i, 0 }; 22 | verify_rule< success >( __LINE__, __FILE__, std::string( t ), result_type::success, 1 ); 23 | } 24 | } 25 | 26 | } // namespace TAO_PEGTL_NAMESPACE 27 | 28 | #include "main.hpp" 29 | -------------------------------------------------------------------------------- /src/test/pegtl/contrib_separated_seq.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include 8 | 9 | // clang-format off 10 | struct A {}; 11 | struct B {}; 12 | struct C {}; 13 | struct D {}; 14 | 15 | struct S {}; 16 | // clang-format on 17 | 18 | using namespace TAO_PEGTL_NAMESPACE; 19 | static_assert( std::is_base_of_v< internal::seq<>, separated_seq< S > > ); 20 | static_assert( std::is_base_of_v< internal::seq< A >, separated_seq< S, A > > ); 21 | static_assert( std::is_base_of_v< internal::seq< A, S, B >, separated_seq< S, A, B > > ); 22 | static_assert( std::is_base_of_v< internal::seq< A, S, B, S, C, S, D >, separated_seq< S, A, B, C, D > > ); 23 | 24 | int main() 25 | {} 26 | -------------------------------------------------------------------------------- /src/test/pegtl/visit.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | #include 7 | 8 | #include "test.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | using grammar = seq< plus< alpha >, star< sor< space, digit > > >; 13 | 14 | template< typename Name > 15 | struct visitor 16 | { 17 | static void visit( std::vector< std::string >& names ) 18 | { 19 | names.emplace_back( demangle< Name >() ); 20 | } 21 | }; 22 | 23 | void unit_test() 24 | { 25 | std::vector< std::string > names; 26 | visit< grammar, visitor >( names ); 27 | TAO_PEGTL_TEST_ASSERT( names.size() == 7 ); 28 | } 29 | 30 | } // namespace TAO_PEGTL_NAMESPACE 31 | 32 | #include "main.hpp" 33 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/bof.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_BOF_HPP 6 | #define TAO_PEGTL_INTERNAL_BOF_HPP 7 | 8 | #include "enable_control.hpp" 9 | 10 | #include "../config.hpp" 11 | #include "../type_list.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | struct bof 16 | { 17 | using rule_t = bof; 18 | using subs_t = empty_list; 19 | 20 | template< typename ParseInput > 21 | [[nodiscard]] static bool match( ParseInput& in ) noexcept 22 | { 23 | return in.byte() == 0; 24 | } 25 | }; 26 | 27 | template<> 28 | inline constexpr bool enable_control< bof > = false; 29 | 30 | } // namespace TAO_PEGTL_NAMESPACE::internal 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/bol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_BOL_HPP 6 | #define TAO_PEGTL_INTERNAL_BOL_HPP 7 | 8 | #include "enable_control.hpp" 9 | 10 | #include "../config.hpp" 11 | #include "../type_list.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | struct bol 16 | { 17 | using rule_t = bol; 18 | using subs_t = empty_list; 19 | 20 | template< typename ParseInput > 21 | [[nodiscard]] static bool match( ParseInput& in ) noexcept 22 | { 23 | return in.column() == 1; 24 | } 25 | }; 26 | 27 | template<> 28 | inline constexpr bool enable_control< bol > = false; 29 | 30 | } // namespace TAO_PEGTL_NAMESPACE::internal 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_action.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include "verify_meta.hpp" 8 | #include "verify_seqs.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | template< typename... Rules > 13 | using test_action_rule = action< nothing, Rules... >; 14 | 15 | void unit_test() 16 | { 17 | verify_meta< action< nothing >, internal::success >(); 18 | verify_meta< action< nothing, eof >, internal::action< nothing, eof >, eof >(); 19 | verify_meta< action< nothing, eof, any >, internal::action< nothing, internal::seq< eof, any > >, internal::seq< eof, any > >(); 20 | 21 | verify_seqs< test_action_rule >(); 22 | } 23 | 24 | } // namespace TAO_PEGTL_NAMESPACE 25 | 26 | #include "main.hpp" 27 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/eof.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_EOF_HPP 6 | #define TAO_PEGTL_INTERNAL_EOF_HPP 7 | 8 | #include "enable_control.hpp" 9 | 10 | #include "../config.hpp" 11 | #include "../type_list.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | struct eof 16 | { 17 | using rule_t = eof; 18 | using subs_t = empty_list; 19 | 20 | template< typename ParseInput > 21 | [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.empty() ) ) 22 | { 23 | return in.empty(); 24 | } 25 | }; 26 | 27 | template<> 28 | inline constexpr bool enable_control< eof > = false; 29 | 30 | } // namespace TAO_PEGTL_NAMESPACE::internal 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/failure.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_FAILURE_HPP 6 | #define TAO_PEGTL_INTERNAL_FAILURE_HPP 7 | 8 | #include "enable_control.hpp" 9 | 10 | #include "../config.hpp" 11 | #include "../type_list.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | struct failure 16 | { 17 | using rule_t = failure; 18 | using subs_t = empty_list; 19 | 20 | template< typename ParseInput > 21 | [[nodiscard]] static bool match( ParseInput& /*unused*/ ) noexcept 22 | { 23 | return false; 24 | } 25 | }; 26 | 27 | template<> 28 | inline constexpr bool enable_control< failure > = false; 29 | 30 | } // namespace TAO_PEGTL_NAMESPACE::internal 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/success.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_SUCCESS_HPP 6 | #define TAO_PEGTL_INTERNAL_SUCCESS_HPP 7 | 8 | #include "enable_control.hpp" 9 | 10 | #include "../config.hpp" 11 | #include "../type_list.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | struct success 16 | { 17 | using rule_t = success; 18 | using subs_t = empty_list; 19 | 20 | template< typename ParseInput > 21 | [[nodiscard]] static bool match( ParseInput& /*unused*/ ) noexcept 22 | { 23 | return true; 24 | } 25 | }; 26 | 27 | template<> 28 | inline constexpr bool enable_control< success > = false; 29 | 30 | } // namespace TAO_PEGTL_NAMESPACE::internal 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_control.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include "verify_meta.hpp" 8 | #include "verify_seqs.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | template< typename... Rules > 13 | using test_control_rule = control< normal, Rules... >; 14 | 15 | void unit_test() 16 | { 17 | verify_meta< control< normal >, internal::success >(); 18 | verify_meta< control< normal, eof >, internal::control< normal, eof >, eof >(); 19 | verify_meta< control< normal, eof, any >, internal::control< normal, internal::seq< eof, any > >, internal::seq< eof, any > >(); 20 | 21 | verify_seqs< test_control_rule >(); 22 | } 23 | 24 | } // namespace TAO_PEGTL_NAMESPACE 25 | 26 | #include "main.hpp" 27 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/enable_control.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_ENABLE_CONTROL_HPP 6 | #define TAO_PEGTL_INTERNAL_ENABLE_CONTROL_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | // This class is a simple tagging mechanism. 15 | // By default, enable_control< Rule > is 'true'. 16 | // Each internal (!) rule that should be hidden 17 | // from the control and action class' callbacks 18 | // simply specializes enable_control<> to return 19 | // 'true' for the above expression. 20 | 21 | template< typename Rule > 22 | inline constexpr bool enable_control = true; 23 | 24 | } // namespace TAO_PEGTL_NAMESPACE::internal 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_eof.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_char.hpp" 7 | #include "verify_meta.hpp" 8 | #include "verify_rule.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | void unit_test() 13 | { 14 | verify_meta< eof, internal::eof >(); 15 | 16 | verify_analyze< eof >( __LINE__, __FILE__, false, false ); 17 | 18 | verify_rule< eof >( __LINE__, __FILE__, "", result_type::success, 0 ); 19 | 20 | for( char i = 1; i < 127; ++i ) { 21 | verify_char< eof >( __LINE__, __FILE__, i, result_type::local_failure ); 22 | } 23 | verify_rule< eof >( __LINE__, __FILE__, "abcdefghijklmn", result_type::local_failure, 14 ); 24 | } 25 | 26 | } // namespace TAO_PEGTL_NAMESPACE 27 | 28 | #include "main.hpp" 29 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_failure.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_char.hpp" 7 | #include "verify_meta.hpp" 8 | #include "verify_rule.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | void unit_test() 13 | { 14 | verify_meta< failure, internal::failure >(); 15 | 16 | verify_analyze< failure >( __LINE__, __FILE__, true, false ); // "Success implies consumption" is true because "success" never happens. 17 | 18 | verify_rule< failure >( __LINE__, __FILE__, "", result_type::local_failure, 0 ); 19 | 20 | for( char i = 1; i < 127; ++i ) { 21 | verify_char< failure >( __LINE__, __FILE__, i, result_type::local_failure ); 22 | } 23 | } 24 | 25 | } // namespace TAO_PEGTL_NAMESPACE 26 | 27 | #include "main.hpp" 28 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/has_current_position.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_HAS_CURRENT_POSITION_HPP 6 | #define TAO_PEGTL_INTERNAL_HAS_CURRENT_POSITION_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | template< typename, typename = void > 15 | inline constexpr bool has_current_position = false; 16 | 17 | template< typename C > 18 | inline constexpr bool has_current_position< C, decltype( (void)std::declval< C >().current_position(), void() ) > = true; 19 | 20 | // The (void) is to shut up a warning from GCC 9 and 10 about the return value of the nodiscard-function current_position() being ignored. 21 | 22 | } // namespace TAO_PEGTL_NAMESPACE::internal 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/example/pegtl/parse_tree_user_state.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | using namespace TAO_PEGTL_NAMESPACE; 11 | 12 | template< typename > 13 | using selector = std::true_type; 14 | 15 | struct user_state 16 | {}; 17 | 18 | template< typename Rule > 19 | struct work 20 | {}; 21 | 22 | template<> 23 | struct work< success > 24 | { 25 | template< typename ActionInput > 26 | static void apply( const ActionInput& /*unused*/, user_state& /*unused*/ ) 27 | {} 28 | }; 29 | 30 | int main() 31 | { 32 | memory_input input( "", "dummy" ); 33 | 34 | user_state state; 35 | auto root = parse_tree::parse< success, selector, work >( input, state ); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/peek_char.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_PEEK_CHAR_HPP 6 | #define TAO_PEGTL_INTERNAL_PEEK_CHAR_HPP 7 | 8 | #include 9 | 10 | #include "data_and_size.hpp" 11 | 12 | #include "../config.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE::internal 15 | { 16 | struct peek_char 17 | { 18 | using data_t = char; 19 | using pair_t = data_and_size< char >; 20 | 21 | template< typename ParseInput > 22 | [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.empty() ) ) 23 | { 24 | if( in.empty() ) { 25 | return { 0, 0 }; 26 | } 27 | return { in.peek_char(), 1 }; 28 | } 29 | }; 30 | 31 | } // namespace TAO_PEGTL_NAMESPACE::internal 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/star.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_STAR_HPP 6 | #define TAO_PEGTL_INTERNAL_STAR_HPP 7 | 8 | #include "enable_control.hpp" 9 | #include "seq.hpp" 10 | #include "star_partial.hpp" 11 | 12 | #include "../config.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE::internal 15 | { 16 | template< typename Rule, typename... Rules > 17 | struct star 18 | : star< seq< Rule, Rules... > > 19 | {}; 20 | 21 | template< typename Rule > 22 | struct star< Rule > 23 | : star_partial< Rule > 24 | { 25 | using rule_t = star; 26 | }; 27 | 28 | template< typename Rule, typename... Rules > 29 | inline constexpr bool enable_control< star< Rule, Rules... > > = false; 30 | 31 | } // namespace TAO_PEGTL_NAMESPACE::internal 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/eol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_EOL_HPP 6 | #define TAO_PEGTL_INTERNAL_EOL_HPP 7 | 8 | #include "enable_control.hpp" 9 | 10 | #include "../config.hpp" 11 | #include "../type_list.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | struct eol 16 | { 17 | using rule_t = eol; 18 | using subs_t = empty_list; 19 | 20 | template< typename ParseInput > 21 | [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( ParseInput::eol_t::eol_match( in ) ) ) 22 | { 23 | return ParseInput::eol_t::eol_match( in ).data; 24 | } 25 | }; 26 | 27 | template<> 28 | inline constexpr bool enable_control< eol > = false; 29 | 30 | } // namespace TAO_PEGTL_NAMESPACE::internal 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_everything.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_meta.hpp" 7 | #include "verify_rule.hpp" 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | void unit_test() 12 | { 13 | verify_meta< everything, internal::everything< std::size_t > >(); 14 | 15 | verify_analyze< everything >( __LINE__, __FILE__, false, false ); 16 | 17 | verify_rule< everything >( __LINE__, __FILE__, "", result_type::success ); 18 | verify_rule< everything >( __LINE__, __FILE__, "asodfuaofj", result_type::success ); 19 | verify_rule< everything >( __LINE__, __FILE__, "asfhalfj;alsjfdo;asjdfo;asjf;laskjdfl;afwfj2;093vmu;oaivu;v390fm;aosumvos3fefalihgfis", result_type::success ); 20 | } 21 | 22 | } // namespace TAO_PEGTL_NAMESPACE 23 | 24 | #include "main.hpp" 25 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_must.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cout << "Exception support disabled, skipping test..." << std::endl; 10 | } 11 | #else 12 | 13 | #include "test.hpp" 14 | #include "verify_seqs.hpp" 15 | 16 | namespace TAO_PEGTL_NAMESPACE 17 | { 18 | void unit_test() 19 | { 20 | verify_meta< must<>, internal::success >(); 21 | verify_meta< must< alpha >, internal::must< alpha >, alpha >(); 22 | verify_meta< must< alpha, digit >, internal::seq< internal::must< alpha >, internal::must< digit > >, internal::must< alpha >, internal::must< digit > >(); 23 | 24 | verify_seqs< must >( result_type::global_failure ); 25 | } 26 | 27 | } // namespace TAO_PEGTL_NAMESPACE 28 | 29 | #include "main.hpp" 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/discard.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_DISCARD_HPP 6 | #define TAO_PEGTL_INTERNAL_DISCARD_HPP 7 | 8 | #include "enable_control.hpp" 9 | 10 | #include "../config.hpp" 11 | #include "../type_list.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | struct discard 16 | { 17 | using rule_t = discard; 18 | using subs_t = empty_list; 19 | 20 | template< typename ParseInput > 21 | [[nodiscard]] static bool match( ParseInput& in ) noexcept 22 | { 23 | static_assert( noexcept( in.discard() ) ); 24 | in.discard(); 25 | return true; 26 | } 27 | }; 28 | 29 | template<> 30 | inline constexpr bool enable_control< discard > = false; 31 | 32 | } // namespace TAO_PEGTL_NAMESPACE::internal 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/test/pegtl/contrib_function.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | bool call1 = false; 12 | 13 | [[nodiscard]] bool func1( memory_input<>& /*unused*/, int /*unused*/, char*& /*unused*/, const double& /*unused*/ ) 14 | { 15 | call1 = true; 16 | return true; 17 | } 18 | 19 | struct rule1 : TAO_PEGTL_NAMESPACE::function< func1 > 20 | {}; 21 | 22 | void unit_test() 23 | { 24 | int i = 42; 25 | char c = 'a'; 26 | double d = 42.0; 27 | memory_input in( "foo", __FUNCTION__ ); 28 | TAO_PEGTL_TEST_ASSERT( parse< rule1 >( in, i, &c, d ) ); 29 | TAO_PEGTL_TEST_ASSERT( call1 ); 30 | } 31 | 32 | } // namespace TAO_PEGTL_NAMESPACE 33 | 34 | #include "main.hpp" 35 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/internal/peek_uint8.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UINT8_HPP 6 | #define TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UINT8_HPP 7 | 8 | #include 9 | #include 10 | 11 | #include "../../internal/data_and_size.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | struct peek_uint8 16 | { 17 | using data_t = std::uint8_t; 18 | using pair_t = data_and_size< std::uint8_t >; 19 | 20 | template< typename ParseInput > 21 | [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.empty() ) ) 22 | { 23 | if( in.empty() ) { 24 | return { 0, 0 }; 25 | } 26 | return { in.peek_uint8(), 1 }; 27 | } 28 | }; 29 | 30 | } // namespace TAO_PEGTL_NAMESPACE::internal 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/example/pegtl/uri_trace.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cerr << "Exception support required, example unavailable." << std::endl; 10 | return 1; 11 | } 12 | #else 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace pegtl = TAO_PEGTL_NAMESPACE; 21 | 22 | using grammar = pegtl::must< pegtl::uri::URI >; 23 | 24 | int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) 25 | { 26 | for( int i = 1; i < argc; ++i ) { 27 | std::cout << "Parsing " << argv[ i ] << std::endl; 28 | pegtl::argv_input in( argv, i ); 29 | pegtl::complete_trace< grammar >( in ); 30 | } 31 | return 0; 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/missing_apply0.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_MISSING_APPLY0_HPP 6 | #define TAO_PEGTL_INTERNAL_MISSING_APPLY0_HPP 7 | 8 | #include "../config.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE::internal 11 | { 12 | template< typename Control, 13 | template< typename... > 14 | class Action, 15 | typename ParseInput, 16 | typename... States > 17 | void missing_apply0( ParseInput& in, States&&... st ) 18 | { 19 | // This function only exists for better error messages, which means that it is only called when we know that it won't compile. 20 | // LCOV_EXCL_START 21 | (void)Control::template apply0< Action >( in, st... ); 22 | // LCOV_EXCL_STOP 23 | } 24 | 25 | } // namespace TAO_PEGTL_NAMESPACE::internal 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/opt.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_OPT_HPP 6 | #define TAO_PEGTL_INTERNAL_OPT_HPP 7 | 8 | #include "enable_control.hpp" 9 | #include "partial.hpp" 10 | #include "seq.hpp" 11 | #include "success.hpp" 12 | 13 | #include "../config.hpp" 14 | 15 | namespace TAO_PEGTL_NAMESPACE::internal 16 | { 17 | template< typename... Rules > 18 | struct opt 19 | : opt< seq< Rules... > > 20 | {}; 21 | 22 | template<> 23 | struct opt<> 24 | : success 25 | {}; 26 | 27 | template< typename Rule > 28 | struct opt< Rule > 29 | : partial< Rule > 30 | { 31 | using rule_t = opt; 32 | }; 33 | 34 | template< typename... Rules > 35 | inline constexpr bool enable_control< opt< Rules... > > = false; 36 | 37 | } // namespace TAO_PEGTL_NAMESPACE::internal 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/eolf.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_EOLF_HPP 6 | #define TAO_PEGTL_INTERNAL_EOLF_HPP 7 | 8 | #include "enable_control.hpp" 9 | 10 | #include "../config.hpp" 11 | #include "../type_list.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | struct eolf 16 | { 17 | using rule_t = eolf; 18 | using subs_t = empty_list; 19 | 20 | template< typename ParseInput > 21 | [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( ParseInput::eol_t::eol_match( in ) ) ) 22 | { 23 | const auto p = ParseInput::eol_t::eol_match( in ); 24 | return p.data || ( p.size == 0 ); 25 | } 26 | }; 27 | 28 | template<> 29 | inline constexpr bool enable_control< eolf > = false; 30 | 31 | } // namespace TAO_PEGTL_NAMESPACE::internal 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/test/pegtl/contrib_partial_trace.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | // clang-format off 12 | struct inner : seq< one< 'a' >, sor< one< 'b' >, one< 'c' >, inner > > {}; 13 | struct outer : seq< one< 'x' >, inner, one< 'y' > > {}; 14 | 15 | // how to run a tracer on a *part* of the grammar: 16 | template< typename > struct partial_action {}; 17 | template<> struct partial_action< inner > : trace_standard {}; 18 | // clang-format on 19 | 20 | void unit_test() 21 | { 22 | memory_input in( "xaacy", "trace test please ignore" ); 23 | const auto result = parse< outer, partial_action >( in ); 24 | TAO_PEGTL_TEST_ASSERT( result ); 25 | } 26 | 27 | } // namespace TAO_PEGTL_NAMESPACE 28 | 29 | #include "main.hpp" 30 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/cr_eol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_CR_EOL_HPP 6 | #define TAO_PEGTL_INTERNAL_CR_EOL_HPP 7 | 8 | #include "data_and_size.hpp" 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | struct cr_eol 15 | { 16 | static constexpr int ch = '\r'; 17 | 18 | template< typename ParseInput > 19 | [[nodiscard]] static bool_and_size eol_match( ParseInput& in ) noexcept( noexcept( in.size( 1 ) ) ) 20 | { 21 | bool_and_size p = { false, in.size( 1 ) }; 22 | if( p.size > 0 ) { 23 | if( in.peek_char() == '\r' ) { 24 | in.bump_to_next_line(); 25 | p.data = true; 26 | } 27 | } 28 | return p; 29 | } 30 | }; 31 | 32 | } // namespace TAO_PEGTL_NAMESPACE::internal 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/lf_eol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_LF_EOL_HPP 6 | #define TAO_PEGTL_INTERNAL_LF_EOL_HPP 7 | 8 | #include "data_and_size.hpp" 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | struct lf_eol 15 | { 16 | static constexpr int ch = '\n'; 17 | 18 | template< typename ParseInput > 19 | [[nodiscard]] static bool_and_size eol_match( ParseInput& in ) noexcept( noexcept( in.size( 1 ) ) ) 20 | { 21 | bool_and_size p = { false, in.size( 1 ) }; 22 | if( p.size > 0 ) { 23 | if( in.peek_char() == '\n' ) { 24 | in.bump_to_next_line(); 25 | p.data = true; 26 | } 27 | } 28 | return p; 29 | } 30 | }; 31 | 32 | } // namespace TAO_PEGTL_NAMESPACE::internal 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/test/pegtl/result_type.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_SRC_TEST_PEGTL_RESULT_TYPE_HPP 6 | #define TAO_PEGTL_SRC_TEST_PEGTL_RESULT_TYPE_HPP 7 | 8 | #include 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | enum class result_type : int 13 | { 14 | success = 1, 15 | local_failure = 0, 16 | global_failure = -1 17 | }; 18 | 19 | inline std::ostream& operator<<( std::ostream& o, const result_type t ) 20 | { 21 | switch( t ) { 22 | case result_type::success: 23 | return o << "success"; 24 | case result_type::local_failure: 25 | return o << "local_failure"; 26 | case result_type::global_failure: 27 | return o << "global_failure"; 28 | } 29 | return o << static_cast< int >( t ); 30 | } 31 | 32 | } // namespace TAO_PEGTL_NAMESPACE 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/everything.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_EVERYTHING_HPP 6 | #define TAO_PEGTL_INTERNAL_EVERYTHING_HPP 7 | 8 | #include "enable_control.hpp" 9 | 10 | #include "../config.hpp" 11 | #include "../type_list.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | template< typename Size > 16 | struct everything 17 | { 18 | using rule_t = everything; 19 | using subs_t = empty_list; 20 | 21 | template< typename ParseInput > 22 | [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) ) 23 | { 24 | in.bump( in.size( Size( -1 ) ) ); 25 | return true; 26 | } 27 | }; 28 | 29 | template< typename Size > 30 | inline constexpr bool enable_control< everything< Size > > = false; 31 | 32 | } // namespace TAO_PEGTL_NAMESPACE::internal 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/internal/peek_mask_uint8.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_INTERNAL_PEEK_MASK_UINT8_HPP 6 | #define TAO_PEGTL_CONTRIB_INTERNAL_PEEK_MASK_UINT8_HPP 7 | 8 | #include 9 | #include 10 | 11 | #include "../../internal/data_and_size.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | template< std::uint8_t M > 16 | struct peek_mask_uint8 17 | { 18 | using data_t = std::uint8_t; 19 | using pair_t = data_and_size< std::uint8_t >; 20 | 21 | template< typename ParseInput > 22 | [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.empty() ) ) 23 | { 24 | if( in.empty() ) { 25 | return { 0, 0 }; 26 | } 27 | return { std::uint8_t( in.peek_uint8() & M ), 1 }; 28 | } 29 | }; 30 | 31 | } // namespace TAO_PEGTL_NAMESPACE::internal 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/test/pegtl/ascii_two.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_meta.hpp" 7 | #include "verify_rule.hpp" 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | void unit_test() 12 | { 13 | verify_analyze< two< 'a' > >( __LINE__, __FILE__, true, false ); 14 | 15 | verify_rule< two< 'a' > >( __LINE__, __FILE__, "", result_type::local_failure ); 16 | verify_rule< two< 'a' > >( __LINE__, __FILE__, "a", result_type::local_failure ); 17 | verify_rule< two< 'a' > >( __LINE__, __FILE__, "ab", result_type::local_failure ); 18 | verify_rule< two< 'a' > >( __LINE__, __FILE__, "aa", result_type::success ); 19 | verify_rule< two< 'a' > >( __LINE__, __FILE__, "aaa", result_type::success, 1 ); 20 | verify_rule< two< 'a' > >( __LINE__, __FILE__, "aaaa", result_type::success, 2 ); 21 | } 22 | 23 | } // namespace TAO_PEGTL_NAMESPACE 24 | 25 | #include "main.hpp" 26 | -------------------------------------------------------------------------------- /src/test/pegtl/contrib_if_then.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_rule.hpp" 7 | 8 | #include 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | void unit_test() 13 | { 14 | // clang-format off 15 | using grammar = 16 | if_then< one< 'a' >, one< 'b' >, one< 'c' > >:: 17 | else_if_then< one< 'a' >, one< 'b' > >:: 18 | else_then< one< 'c' > >; 19 | // clang-format on 20 | 21 | verify_rule< grammar >( __LINE__, __FILE__, "abc", result_type::success, 0 ); 22 | verify_rule< grammar >( __LINE__, __FILE__, "abcd", result_type::success, 1 ); 23 | verify_rule< grammar >( __LINE__, __FILE__, "ab", result_type::local_failure, 2 ); 24 | verify_rule< grammar >( __LINE__, __FILE__, "c", result_type::success, 0 ); 25 | } 26 | 27 | } // namespace TAO_PEGTL_NAMESPACE 28 | 29 | #include "main.hpp" 30 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/to_string.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_TO_STRING_HPP 6 | #define TAO_PEGTL_CONTRIB_TO_STRING_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE 13 | { 14 | namespace internal 15 | { 16 | template< typename > 17 | struct to_string; 18 | 19 | template< template< char... > class X, char... Cs > 20 | struct to_string< X< Cs... > > 21 | { 22 | [[nodiscard]] static std::string get() 23 | { 24 | const char s[] = { Cs..., 0 }; 25 | return std::string( s, sizeof...( Cs ) ); 26 | } 27 | }; 28 | 29 | } // namespace internal 30 | 31 | template< typename T > 32 | [[nodiscard]] std::string to_string() 33 | { 34 | return internal::to_string< T >::get(); 35 | } 36 | 37 | } // namespace TAO_PEGTL_NAMESPACE 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/crlf_eol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_CRLF_EOL_HPP 6 | #define TAO_PEGTL_INTERNAL_CRLF_EOL_HPP 7 | 8 | #include "data_and_size.hpp" 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | struct crlf_eol 15 | { 16 | static constexpr int ch = '\n'; 17 | 18 | template< typename ParseInput > 19 | [[nodiscard]] static bool_and_size eol_match( ParseInput& in ) noexcept( noexcept( in.size( 2 ) ) ) 20 | { 21 | bool_and_size p = { false, in.size( 2 ) }; 22 | if( p.size > 1 ) { 23 | if( ( in.peek_char() == '\r' ) && ( in.peek_char( 1 ) == '\n' ) ) { 24 | in.bump_to_next_line( 2 ); 25 | p.data = true; 26 | } 27 | } 28 | return p; 29 | } 30 | }; 31 | 32 | } // namespace TAO_PEGTL_NAMESPACE::internal 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/test/pegtl/file_cstream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | #include 7 | 8 | #include "test.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | struct file_content 13 | : seq< TAO_PEGTL_STRING( "dummy content" ), eol, discard > 14 | {}; 15 | 16 | struct file_grammar 17 | : seq< rep_min_max< 11, 11, file_content >, eof > 18 | {}; 19 | 20 | void unit_test() 21 | { 22 | const char* const filename = "src/test/pegtl/file_data.txt"; 23 | #if defined( _MSC_VER ) 24 | std::FILE* stream; 25 | ::fopen_s( &stream, filename, "rb" ); 26 | #else 27 | std::FILE* stream = std::fopen( filename, "rb" ); 28 | #endif 29 | TAO_PEGTL_TEST_ASSERT( stream != nullptr ); 30 | TAO_PEGTL_TEST_ASSERT( parse< file_grammar >( cstream_input( stream, 16, filename ) ) ); 31 | std::fclose( stream ); 32 | } 33 | 34 | } // namespace TAO_PEGTL_NAMESPACE 35 | 36 | #include "main.hpp" 37 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_try_catch_return_false.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cout << "Exception support disabled, skipping test..." << std::endl; 10 | } 11 | #else 12 | 13 | #include "test.hpp" 14 | #include "verify_seqs.hpp" 15 | 16 | namespace TAO_PEGTL_NAMESPACE 17 | { 18 | template< typename... Rules > 19 | using test_try_catch_rule = try_catch_return_false< must< Rules... > >; 20 | 21 | template< typename... Rules > 22 | using test_try_catch_any_rule = try_catch_any_return_false< must< Rules... > >; 23 | 24 | void unit_test() 25 | { 26 | verify_seqs< test_try_catch_rule >(); 27 | verify_seqs< try_catch_return_false >(); 28 | 29 | verify_seqs< test_try_catch_any_rule >(); 30 | verify_seqs< try_catch_any_return_false >(); 31 | } 32 | 33 | } // namespace TAO_PEGTL_NAMESPACE 34 | 35 | #include "main.hpp" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/test/pegtl/verify_char.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_CHAR_HPP 6 | #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_CHAR_HPP 7 | 8 | #include 9 | #include 10 | 11 | #include "result_type.hpp" 12 | #include "verify_rule.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE 15 | { 16 | template< typename Rule > 17 | void verify_char( const std::size_t line, const char* file, const char data, const result_type result ) 18 | { 19 | verify_rule< Rule >( line, file, std::string( std::size_t( 1 ), data ), result, ( result == result_type::success ) ? 0 : 1 ); 20 | } 21 | 22 | template< typename Rule > 23 | void verify_char( const std::size_t line, const char* file, const char data, const bool result ) 24 | { 25 | verify_char< Rule >( line, file, data, result ? result_type::success : result_type::local_failure ); 26 | } 27 | 28 | } // namespace TAO_PEGTL_NAMESPACE 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/cr_crlf_eol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_CR_CRLF_EOL_HPP 6 | #define TAO_PEGTL_INTERNAL_CR_CRLF_EOL_HPP 7 | 8 | #include "data_and_size.hpp" 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | struct cr_crlf_eol 15 | { 16 | static constexpr int ch = '\r'; 17 | 18 | template< typename ParseInput > 19 | [[nodiscard]] static bool_and_size eol_match( ParseInput& in ) noexcept( noexcept( in.size( 2 ) ) ) 20 | { 21 | bool_and_size p = { false, in.size( 2 ) }; 22 | if( p.size > 0 ) { 23 | if( in.peek_char() == '\r' ) { 24 | in.bump_to_next_line( ( p.size = 1 + ( ( p.size > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) ) ); 25 | p.data = true; 26 | } 27 | } 28 | return p; 29 | } 30 | }; 31 | 32 | } // namespace TAO_PEGTL_NAMESPACE::internal 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/extract_position.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_EXTRACT_POSITION_HPP 6 | #define TAO_PEGTL_INTERNAL_EXTRACT_POSITION_HPP 7 | 8 | #include "../config.hpp" 9 | 10 | #include "has_current_position.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | template< typename T > 15 | [[nodiscard]] decltype( auto ) extract_position( const T& t ) 16 | { 17 | if constexpr( !has_current_position< T > ) { 18 | return t; // Assume t is not an input. 19 | } 20 | else if constexpr( !has_current_position< decltype( *t.current() ) > ) { 21 | return t.current_position(); // Assume t is an input of "simple" object (char, enums). 22 | } 23 | else { 24 | return t.current()->current_position(); // Assume t is an input of objects that already have a position (tokens). 25 | } 26 | } 27 | 28 | } // namespace TAO_PEGTL_NAMESPACE::internal 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/missing_apply.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_MISSING_APPLY_HPP 6 | #define TAO_PEGTL_INTERNAL_MISSING_APPLY_HPP 7 | 8 | #include "../config.hpp" 9 | #include "../rewind_mode.hpp" 10 | 11 | namespace TAO_PEGTL_NAMESPACE::internal 12 | { 13 | template< typename Control, 14 | template< typename... > 15 | class Action, 16 | typename ParseInput, 17 | typename... States > 18 | void missing_apply( ParseInput& in, States&&... st ) 19 | { 20 | // This function only exists for better error messages, which means that it is only called when we know that it won't compile. 21 | // LCOV_EXCL_START 22 | auto m = in.template auto_rewind< rewind_mode::required >(); 23 | (void)Control::template apply< Action >( m.inputerator(), in, st... ); 24 | // LCOV_EXCL_STOP 25 | } 26 | 27 | } // namespace TAO_PEGTL_NAMESPACE::internal 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /.github/workflows/clang-tidy.yml: -------------------------------------------------------------------------------- 1 | name: clang-tidy 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - 'README.md' 7 | - 'doc/**' 8 | pull_request: 9 | paths-ignore: 10 | - 'README.md' 11 | - 'doc/**' 12 | 13 | jobs: 14 | clang-tidy: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - name: Install Dependencies 21 | run: | 22 | sudo apt-get -qq update -yq 23 | sudo apt-get -qq install -y clang-tidy --no-install-recommends --no-install-suggests 24 | 25 | - name: Generate Compilation Database 26 | run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON 27 | 28 | - name: Run clang-tidy on Header Files 29 | continue-on-error: true 30 | run: find include/ -type f \( -name "*.hpp" -a ! -name "endian_win.hpp" -a ! -name "mmap_file_win32.hpp" \) | xargs -P $(nproc) -I {} clang-tidy -quiet -p build {} -- -std=c++17 -Iinclude 31 | 32 | - name: Run clang-tidy on tests and examples files 33 | continue-on-error: true 34 | run: find src/ -type f -name "*.cpp" | xargs -P $(nproc) -I {} clang-tidy -quiet -p build {} -- -std=c++17 -Iinclude 35 | -------------------------------------------------------------------------------- /include/tao/pegtl/cstream_input.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CSTREAM_INPUT_HPP 6 | #define TAO_PEGTL_CSTREAM_INPUT_HPP 7 | 8 | #include 9 | 10 | #include "buffer_input.hpp" 11 | #include "config.hpp" 12 | #include "eol.hpp" 13 | 14 | #include "internal/cstream_reader.hpp" 15 | 16 | namespace TAO_PEGTL_NAMESPACE 17 | { 18 | template< typename Eol = eol::lf_crlf, std::size_t Chunk = 64 > 19 | struct cstream_input 20 | : buffer_input< internal::cstream_reader, Eol, std::string, Chunk > 21 | { 22 | template< typename T > 23 | cstream_input( std::FILE* in_stream, const std::size_t in_maximum, T&& in_source ) 24 | : buffer_input< internal::cstream_reader, Eol, std::string, Chunk >( std::forward< T >( in_source ), in_maximum, in_stream ) 25 | {} 26 | }; 27 | 28 | template< typename... Ts > 29 | cstream_input( Ts&&... ) -> cstream_input<>; 30 | 31 | } // namespace TAO_PEGTL_NAMESPACE 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/tao/pegtl/istream_input.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_ISTREAM_INPUT_HPP 6 | #define TAO_PEGTL_ISTREAM_INPUT_HPP 7 | 8 | #include 9 | 10 | #include "buffer_input.hpp" 11 | #include "config.hpp" 12 | #include "eol.hpp" 13 | 14 | #include "internal/istream_reader.hpp" 15 | 16 | namespace TAO_PEGTL_NAMESPACE 17 | { 18 | template< typename Eol = eol::lf_crlf, std::size_t Chunk = 64 > 19 | struct istream_input 20 | : buffer_input< internal::istream_reader, Eol, std::string, Chunk > 21 | { 22 | template< typename T > 23 | istream_input( std::istream& in_stream, const std::size_t in_maximum, T&& in_source ) 24 | : buffer_input< internal::istream_reader, Eol, std::string, Chunk >( std::forward< T >( in_source ), in_maximum, in_stream ) 25 | {} 26 | }; 27 | 28 | template< typename... Ts > 29 | istream_input( Ts&&... ) -> istream_input<>; 30 | 31 | } // namespace TAO_PEGTL_NAMESPACE 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/test/pegtl/internal_file_opener.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) || !defined( _POSIX_MAPPED_FILES ) 6 | #include 7 | int main() 8 | { 9 | std::cout << "Exception support disabled, skipping test..." << std::endl; 10 | } 11 | #else 12 | 13 | #include 14 | 15 | #include "test.hpp" 16 | 17 | namespace TAO_PEGTL_NAMESPACE 18 | { 19 | void unit_test() 20 | { 21 | const internal::file_opener fo( "Makefile" ); 22 | ::close( fo.m_fd ); // Provoke exception, nobody would normally do this. 23 | try { 24 | (void)fo.size(); // expected to throw 25 | 26 | // LCOV_EXCL_START 27 | std::cerr << "pegtl: unit test failed for [ internal::file_opener ] " << std::endl; 28 | ++failed; 29 | // LCOV_EXCL_STOP 30 | } 31 | catch( const std::exception& ) { 32 | } 33 | } 34 | 35 | } // namespace TAO_PEGTL_NAMESPACE 36 | 37 | #include "main.hpp" 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/test/pegtl/test_result.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include "test.hpp" 8 | 9 | #include "result_type.hpp" 10 | 11 | namespace TAO_PEGTL_NAMESPACE 12 | { 13 | void unit_test() 14 | { 15 | { 16 | std::ostringstream oss; 17 | oss << result_type::success; 18 | TAO_PEGTL_TEST_ASSERT( oss.str() == "success" ); 19 | } 20 | { 21 | std::ostringstream oss; 22 | oss << result_type::local_failure; 23 | TAO_PEGTL_TEST_ASSERT( oss.str() == "local_failure" ); 24 | } 25 | { 26 | std::ostringstream oss; 27 | oss << result_type::global_failure; 28 | TAO_PEGTL_TEST_ASSERT( oss.str() == "global_failure" ); 29 | } 30 | { 31 | std::ostringstream oss; 32 | oss << static_cast< result_type >( 1764 ); 33 | TAO_PEGTL_TEST_ASSERT( oss.str() == "1764" ); 34 | } 35 | } 36 | 37 | } // namespace TAO_PEGTL_NAMESPACE 38 | 39 | #include "main.hpp" 40 | -------------------------------------------------------------------------------- /include/tao/pegtl/enable_action.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_ENABLE_ACTION_HPP 6 | #define TAO_PEGTL_ENABLE_ACTION_HPP 7 | 8 | #include "apply_mode.hpp" 9 | #include "config.hpp" 10 | #include "match.hpp" 11 | #include "nothing.hpp" 12 | #include "rewind_mode.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE 15 | { 16 | struct enable_action 17 | : maybe_nothing 18 | { 19 | template< typename Rule, 20 | apply_mode A, 21 | rewind_mode M, 22 | template< typename... > 23 | class Action, 24 | template< typename... > 25 | class Control, 26 | typename ParseInput, 27 | typename... States > 28 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 29 | { 30 | return TAO_PEGTL_NAMESPACE::match< Rule, apply_mode::action, M, Action, Control >( in, st... ); 31 | } 32 | }; 33 | 34 | } // namespace TAO_PEGTL_NAMESPACE 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/tao/pegtl/disable_action.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_DISABLE_ACTION_HPP 6 | #define TAO_PEGTL_DISABLE_ACTION_HPP 7 | 8 | #include "apply_mode.hpp" 9 | #include "config.hpp" 10 | #include "match.hpp" 11 | #include "nothing.hpp" 12 | #include "rewind_mode.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE 15 | { 16 | struct disable_action 17 | : maybe_nothing 18 | { 19 | template< typename Rule, 20 | apply_mode A, 21 | rewind_mode M, 22 | template< typename... > 23 | class Action, 24 | template< typename... > 25 | class Control, 26 | typename ParseInput, 27 | typename... States > 28 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 29 | { 30 | return TAO_PEGTL_NAMESPACE::match< Rule, apply_mode::nothing, M, Action, Control >( in, st... ); 31 | } 32 | }; 33 | 34 | } // namespace TAO_PEGTL_NAMESPACE 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/unwind_guard.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_UNWIND_GUARD_HPP 6 | #define TAO_PEGTL_INTERNAL_UNWIND_GUARD_HPP 7 | 8 | #include 9 | #include 10 | 11 | #include "../config.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | template< typename Unwind > 16 | struct unwind_guard 17 | { 18 | explicit unwind_guard( Unwind&& unwind_impl ) 19 | : unwind( std::move( unwind_impl ) ) 20 | {} 21 | 22 | ~unwind_guard() 23 | { 24 | if( unwind ) { 25 | ( *unwind )(); 26 | } 27 | } 28 | 29 | unwind_guard( const unwind_guard& ) = delete; 30 | unwind_guard( unwind_guard&& ) noexcept = delete; 31 | 32 | unwind_guard& operator=( const unwind_guard& ) = delete; 33 | unwind_guard& operator=( unwind_guard&& ) noexcept = delete; 34 | 35 | std::optional< Unwind > unwind; 36 | }; 37 | 38 | } // namespace TAO_PEGTL_NAMESPACE::internal 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/test/pegtl/data_cstring.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | template< typename Rule, 12 | template< typename... > class Action = nothing, 13 | template< typename... > class Control = normal > 14 | bool parse_cstring( const char* string, const char* source, const std::size_t maximum ) 15 | { 16 | buffer_input< internal::cstring_reader > in( source, maximum, string ); 17 | return parse< Rule, Action, Control >( in ); 18 | } 19 | 20 | struct test_grammar 21 | : seq< string< 'a', 'b', 'c', 'd', 'e', 'f' >, not_at< any >, eof > 22 | {}; 23 | 24 | void unit_test() 25 | { 26 | TAO_PEGTL_TEST_ASSERT( parse_cstring< test_grammar >( "abcdef", "test data", 10 ) ); 27 | TAO_PEGTL_TEST_ASSERT( parse_cstring< test_grammar >( "abcdef\0g", "test data", 10 ) ); 28 | } 29 | 30 | } // namespace TAO_PEGTL_NAMESPACE 31 | 32 | #include "main.hpp" 33 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/require.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_REQUIRE_HPP 6 | #define TAO_PEGTL_INTERNAL_REQUIRE_HPP 7 | 8 | #include "enable_control.hpp" 9 | #include "success.hpp" 10 | 11 | #include "../config.hpp" 12 | #include "../type_list.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE::internal 15 | { 16 | template< unsigned Amount > 17 | struct require; 18 | 19 | template<> 20 | struct require< 0 > 21 | : success 22 | {}; 23 | 24 | template< unsigned Amount > 25 | struct require 26 | { 27 | using rule_t = require; 28 | using subs_t = empty_list; 29 | 30 | template< typename ParseInput > 31 | [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) ) 32 | { 33 | return in.size( Amount ) >= Amount; 34 | } 35 | }; 36 | 37 | template< unsigned Amount > 38 | inline constexpr bool enable_control< require< Amount > > = false; 39 | 40 | } // namespace TAO_PEGTL_NAMESPACE::internal 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/cstring_reader.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_CSTRING_READER_HPP 6 | #define TAO_PEGTL_INTERNAL_CSTRING_READER_HPP 7 | 8 | #include 9 | #include 10 | 11 | #include "../config.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | struct cstring_reader 16 | { 17 | explicit cstring_reader( const char* zero_terminated ) noexcept 18 | : m_cstring( zero_terminated ) 19 | { 20 | assert( m_cstring != nullptr ); 21 | } 22 | 23 | [[nodiscard]] std::size_t operator()( char* buffer, const std::size_t length ) noexcept 24 | { 25 | std::size_t i = 0; 26 | char c; 27 | 28 | while( ( i < length ) && ( ( c = m_cstring[ i ] ) != 0 ) ) { 29 | *buffer++ = c; 30 | ++i; 31 | } 32 | m_cstring += i; 33 | return i; 34 | } 35 | 36 | const char* m_cstring; 37 | }; 38 | 39 | } // namespace TAO_PEGTL_NAMESPACE::internal 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/bytes.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_BYTES_HPP 6 | #define TAO_PEGTL_INTERNAL_BYTES_HPP 7 | 8 | #include "enable_control.hpp" 9 | #include "success.hpp" 10 | 11 | #include "../config.hpp" 12 | #include "../type_list.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE::internal 15 | { 16 | template< unsigned Cnt > 17 | struct bytes 18 | { 19 | using rule_t = bytes; 20 | using subs_t = empty_list; 21 | 22 | template< typename ParseInput > 23 | [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) ) 24 | { 25 | if( in.size( Cnt ) >= Cnt ) { 26 | in.bump( Cnt ); 27 | return true; 28 | } 29 | return false; 30 | } 31 | }; 32 | 33 | template<> 34 | struct bytes< 0 > 35 | : success 36 | {}; 37 | 38 | template< unsigned Cnt > 39 | inline constexpr bool enable_control< bytes< Cnt > > = false; 40 | 41 | } // namespace TAO_PEGTL_NAMESPACE::internal 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/test/pegtl/error_message_2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cout << "Exception support disabled, skipping test..." << std::endl; 10 | } 11 | #else 12 | 13 | #include "test.hpp" 14 | 15 | namespace test2 16 | { 17 | using namespace TAO_PEGTL_NAMESPACE; 18 | 19 | // clang-format off 20 | struct a : one< 'a' > {}; 21 | struct b : one< 'b' > {}; 22 | struct grammar : sor< a, sor< b, TAO_PEGTL_RAISE_MESSAGE( "test123" ) > > {}; 23 | // clang-format on 24 | 25 | } // namespace test2 26 | 27 | namespace TAO_PEGTL_NAMESPACE 28 | { 29 | void unit_test() 30 | { 31 | try { 32 | parse< test2::grammar >( memory_input( "c", __FUNCTION__ ) ); 33 | TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE 34 | } 35 | catch( const parse_error& e ) { 36 | TAO_PEGTL_TEST_ASSERT( e.message() == "test123" ); 37 | } 38 | } 39 | 40 | } // namespace TAO_PEGTL_NAMESPACE 41 | 42 | #include "main.hpp" 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Android 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - 'README.md' 7 | - 'doc/**' 8 | pull_request: 9 | paths-ignore: 10 | - 'README.md' 11 | - 'doc/**' 12 | 13 | jobs: 14 | android: 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | platform: 19 | - android-27 20 | - android-29 21 | abi: 22 | - armeabi-v7a 23 | - arm64-v8a 24 | build_type: [Debug, Release] 25 | runs-on: ubuntu-24.04 26 | steps: 27 | - name: Install Dependencies 28 | run: | 29 | sudo apt -qq update 30 | sudo apt -qq install -y ninja-build --no-install-recommends --no-install-suggests 31 | 32 | - uses: actions/checkout@v4 33 | 34 | - name: Configure CMake 35 | run: | 36 | cmake -S $GITHUB_WORKSPACE -B build \ 37 | -GNinja \ 38 | -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \ 39 | -DANDROID_ABI=${{ matrix.abi }} \ 40 | -DANDROID_PLATFORM=${{ matrix.platform }} \ 41 | -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} 42 | 43 | - name: Build project 44 | run: cmake --build build/ 45 | -------------------------------------------------------------------------------- /src/test/pegtl/contrib_trace1.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include "test.hpp" 8 | 9 | #include 10 | 11 | namespace test 12 | { 13 | using namespace TAO_PEGTL_NAMESPACE; 14 | 15 | #if defined( __cpp_exceptions ) 16 | using grammar = seq< sor< try_catch_return_false< must< one< 'a' > > >, one< 'F' > >, eof >; 17 | #else 18 | using grammar = seq< sor< one< 'a' >, one< 'F' > >, eof >; 19 | #endif 20 | 21 | } // namespace test 22 | 23 | namespace TAO_PEGTL_NAMESPACE 24 | { 25 | void unit_test() 26 | { 27 | const std::string data = "F"; 28 | memory_input in( data, __FILE__ ); 29 | // Just enough to see that it compiles and nothing explodes; 30 | // the output format probabaly changes between compilers and 31 | // versions making a proper test difficult. 32 | standard_trace< test::grammar >( in ); 33 | in.restart(); 34 | complete_trace< test::grammar >( in ); 35 | } 36 | 37 | } // namespace TAO_PEGTL_NAMESPACE 38 | 39 | #include "main.hpp" 40 | -------------------------------------------------------------------------------- /include/tao/pegtl/change_control.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CHANGE_CONTROL_HPP 6 | #define TAO_PEGTL_CHANGE_CONTROL_HPP 7 | 8 | #include "apply_mode.hpp" 9 | #include "config.hpp" 10 | #include "match.hpp" 11 | #include "nothing.hpp" 12 | #include "rewind_mode.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE 15 | { 16 | template< template< typename... > class NewControl > 17 | struct change_control 18 | : maybe_nothing 19 | { 20 | template< typename Rule, 21 | apply_mode A, 22 | rewind_mode M, 23 | template< typename... > 24 | class Action, 25 | template< typename... > 26 | class Control, 27 | typename ParseInput, 28 | typename... States > 29 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 30 | { 31 | return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, NewControl >( in, st... ); 32 | } 33 | }; 34 | 35 | } // namespace TAO_PEGTL_NAMESPACE 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/tao/pegtl/discard_input.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_DISCARD_INPUT_HPP 6 | #define TAO_PEGTL_DISCARD_INPUT_HPP 7 | 8 | #include "apply_mode.hpp" 9 | #include "config.hpp" 10 | #include "match.hpp" 11 | #include "nothing.hpp" 12 | #include "rewind_mode.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE 15 | { 16 | struct discard_input 17 | : maybe_nothing 18 | { 19 | template< typename Rule, 20 | apply_mode A, 21 | rewind_mode M, 22 | template< typename... > 23 | class Action, 24 | template< typename... > 25 | class Control, 26 | typename ParseInput, 27 | typename... States > 28 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 29 | { 30 | const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); 31 | in.discard(); 32 | return result; 33 | } 34 | }; 35 | 36 | } // namespace TAO_PEGTL_NAMESPACE 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /.github/workflows/msys.yml: -------------------------------------------------------------------------------- 1 | name: msys2 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - 'README.md' 7 | - 'doc/**' 8 | pull_request: 9 | paths-ignore: 10 | - 'README.md' 11 | - 'doc/**' 12 | 13 | jobs: 14 | msys2: 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | platform: 19 | - 'UCRT64' 20 | - 'CLANG64' 21 | build_type: [Debug, Release] 22 | 23 | defaults: 24 | run: 25 | shell: msys2 {0} 26 | 27 | runs-on: windows-latest 28 | 29 | steps: 30 | - uses: actions/checkout@v3 31 | 32 | - uses: msys2/setup-msys2@v2 33 | with: 34 | msystem: ${{matrix.platform}} 35 | install: >- 36 | bison 37 | dos2unix 38 | git 39 | pacboy: >- 40 | cc:p 41 | cmake:p 42 | ninja:p 43 | pkgconf:p 44 | update: true 45 | 46 | - run: cmake -E make_directory build 47 | shell: msys2 {0} 48 | 49 | - working-directory: build/ 50 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} 51 | 52 | - working-directory: build/ 53 | run: cmake --build . 54 | 55 | - working-directory: build/ 56 | run: ctest --output-on-failure 57 | -------------------------------------------------------------------------------- /src/example/pegtl/proto3.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cerr << "Exception support required, example unavailable." << std::endl; 10 | return 1; 11 | } 12 | #else 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include "proto3.hpp" 20 | 21 | int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) 22 | { 23 | using namespace TAO_PEGTL_NAMESPACE; 24 | 25 | if( analyze< proto3::proto >() != 0 ) { 26 | return 1; 27 | } 28 | 29 | for( int i = 1; i < argc; ++i ) { 30 | file_input in( argv[ i ] ); 31 | try { 32 | parse< proto3::proto >( in ); 33 | } 34 | catch( const parse_error& e ) { 35 | const auto& p = e.position_object(); 36 | std::cerr << e.what() << '\n' 37 | << in.line_at( p ) << '\n' 38 | << std::setw( int( p.column ) ) << '^' << '\n'; 39 | } 40 | } 41 | return 0; 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/json_pointer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_JSON_POINTER_HPP 6 | #define TAO_PEGTL_CONTRIB_JSON_POINTER_HPP 7 | 8 | #include "../ascii.hpp" 9 | #include "../config.hpp" 10 | #include "../rules.hpp" 11 | #include "../utf8.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::json_pointer 14 | { 15 | // JSON pointer grammar according to RFC 6901 16 | 17 | // clang-format off 18 | struct unescaped : utf8::ranges< 0x0, 0x2E, 0x30, 0x7D, 0x7F, 0x10FFFF > {}; 19 | struct escaped : seq< one< '~' >, one< '0', '1' > > {}; 20 | 21 | struct reference_token : star< sor< unescaped, escaped > > {}; 22 | struct json_pointer : star< one< '/' >, reference_token > {}; 23 | // clang-format on 24 | 25 | // relative JSON pointer, see ... 26 | 27 | // clang-format off 28 | struct non_negative_integer : sor< one< '0' >, plus< digit > > {}; 29 | struct relative_json_pointer : seq< non_negative_integer, sor< one< '#' >, json_pointer > > {}; 30 | // clang-format on 31 | 32 | } // namespace TAO_PEGTL_NAMESPACE::json_pointer 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/tao/pegtl/eol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_EOL_HPP 6 | #define TAO_PEGTL_EOL_HPP 7 | 8 | #include "config.hpp" 9 | 10 | #include "internal/eol.hpp" 11 | 12 | #include "internal/cr_crlf_eol.hpp" 13 | #include "internal/cr_eol.hpp" 14 | #include "internal/crlf_eol.hpp" 15 | #include "internal/lf_crlf_eol.hpp" 16 | #include "internal/lf_eol.hpp" 17 | 18 | namespace TAO_PEGTL_NAMESPACE 19 | { 20 | inline namespace ascii 21 | { 22 | // Struct eol is both a rule and a pseudo-namespace for the 23 | // member structs cr, etc. (which are not themselves rules). 24 | 25 | struct eol 26 | : internal::eol 27 | { 28 | // clang-format off 29 | struct cr : internal::cr_eol {}; 30 | struct cr_crlf : internal::cr_crlf_eol {}; 31 | struct crlf : internal::crlf_eol {}; 32 | struct lf : internal::lf_eol {}; 33 | struct lf_crlf : internal::lf_crlf_eol {}; 34 | // clang-format on 35 | }; 36 | 37 | } // namespace ascii 38 | 39 | } // namespace TAO_PEGTL_NAMESPACE 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/test/pegtl/error_message_3.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cout << "Exception support disabled, skipping test..." << std::endl; 10 | } 11 | #else 12 | 13 | #include "test.hpp" 14 | 15 | namespace test3 16 | { 17 | using namespace TAO_PEGTL_NAMESPACE; 18 | 19 | // clang-format off 20 | struct a : one< 'a' > {}; 21 | 22 | struct b : one< 'b' > { 23 | static constexpr const char* error_message = "test123"; 24 | }; 25 | 26 | struct grammar : sor< a, must< b > > {}; 27 | // clang-format on 28 | 29 | } // namespace test3 30 | 31 | namespace TAO_PEGTL_NAMESPACE 32 | { 33 | void unit_test() 34 | { 35 | try { 36 | parse< test3::grammar >( memory_input( "c", __FUNCTION__ ) ); 37 | TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE 38 | } 39 | catch( const parse_error& e ) { 40 | TAO_PEGTL_TEST_ASSERT( e.message() == "test123" ); 41 | } 42 | } 43 | 44 | } // namespace TAO_PEGTL_NAMESPACE 45 | 46 | #include "main.hpp" 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/apply0_single.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_APPLY0_SINGLE_HPP 6 | #define TAO_PEGTL_INTERNAL_APPLY0_SINGLE_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | template< typename Action > 15 | struct apply0_single 16 | { 17 | template< typename... States > 18 | [[nodiscard]] static auto match( States&&... st ) noexcept( noexcept( Action::apply0( st... ) ) ) 19 | -> std::enable_if_t< std::is_same_v< decltype( Action::apply0( st... ) ), void >, bool > 20 | { 21 | Action::apply0( st... ); 22 | return true; 23 | } 24 | 25 | template< typename... States > 26 | [[nodiscard]] static auto match( States&&... st ) noexcept( noexcept( Action::apply0( st... ) ) ) 27 | -> std::enable_if_t< std::is_same_v< decltype( Action::apply0( st... ) ), bool >, bool > 28 | { 29 | return Action::apply0( st... ); 30 | } 31 | }; 32 | 33 | } // namespace TAO_PEGTL_NAMESPACE::internal 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/example/pegtl/modulus_match.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | using namespace TAO_PEGTL_NAMESPACE; 8 | 9 | namespace modulus 10 | { 11 | template< unsigned M, unsigned R = 0 > 12 | struct my_rule 13 | { 14 | static_assert( M > 1, "Modulus must be greater than 1" ); 15 | static_assert( R < M, "Remainder must be less than modulus" ); 16 | 17 | template< typename ParseInput > 18 | static bool match( ParseInput& in ) 19 | { 20 | if( !in.empty() ) { 21 | if( ( ( *in.current() ) % M ) == R ) { 22 | in.bump( 1 ); 23 | return true; 24 | } 25 | } 26 | return false; 27 | } 28 | }; 29 | 30 | struct grammar 31 | : until< eolf, my_rule< 3 > > 32 | {}; 33 | 34 | } // namespace modulus 35 | 36 | int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) 37 | { 38 | if( argc > 1 ) { 39 | argv_input in( argv, 1 ); 40 | if( !parse< modulus::grammar >( in ) ) { 41 | return 1; 42 | } 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_state.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include "verify_meta.hpp" 8 | #include "verify_seqs.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | struct test_state_state 13 | { 14 | template< typename ParseInput > 15 | explicit test_state_state( const ParseInput& /*unused*/ ) 16 | {} 17 | 18 | template< typename ParseInput > 19 | void success( const ParseInput& /*unused*/ ) const 20 | {} 21 | }; 22 | 23 | template< typename... Rules > 24 | using test_state_rule = state< test_state_state, Rules... >; 25 | 26 | void unit_test() 27 | { 28 | verify_meta< state< test_state_state >, internal::success >(); 29 | verify_meta< state< test_state_state, any >, internal::state< test_state_state, any >, any >(); 30 | verify_meta< state< test_state_state, alpha, digit >, internal::state< test_state_state, internal::seq< alpha, digit > >, internal::seq< alpha, digit > >(); 31 | 32 | verify_seqs< test_state_rule >(); 33 | } 34 | 35 | } // namespace TAO_PEGTL_NAMESPACE 36 | 37 | #include "main.hpp" 38 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_bol.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_meta.hpp" 7 | #include "verify_rule.hpp" 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | void unit_test() 12 | { 13 | verify_meta< bol, internal::bol >(); 14 | 15 | verify_analyze< bol >( __LINE__, __FILE__, false, false ); 16 | 17 | verify_only< bol >( __LINE__, __FILE__, "", result_type::success, 0 ); 18 | 19 | for( char i = 1; i < 127; ++i ) { 20 | const char s[] = { i, 0 }; 21 | verify_only< bol >( __LINE__, __FILE__, s, result_type::success, 1 ); 22 | } 23 | verify_only< seq< alpha, bol > >( __LINE__, __FILE__, "a", result_type::local_failure, 1 ); 24 | verify_only< seq< alpha, bol > >( __LINE__, __FILE__, "ab", result_type::local_failure, 2 ); 25 | verify_only< seq< alpha, bol, alpha > >( __LINE__, __FILE__, "ab", result_type::local_failure, 2 ); 26 | verify_only< seq< alpha, eol, bol, alpha, eof > >( __LINE__, __FILE__, "a\nb", result_type::success, 0 ); 27 | } 28 | 29 | } // namespace TAO_PEGTL_NAMESPACE 30 | 31 | #include "main.hpp" 32 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/mmap_file.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_MMAP_FILE_HPP 6 | #define TAO_PEGTL_INTERNAL_MMAP_FILE_HPP 7 | 8 | #if defined( __unix__ ) || ( defined( __APPLE__ ) && defined( __MACH__ ) ) 9 | #include // Required for _POSIX_MAPPED_FILES 10 | #endif 11 | 12 | #if defined( _POSIX_MAPPED_FILES ) 13 | #include "mmap_file_posix.hpp" 14 | #elif defined( _WIN32 ) 15 | #include "mmap_file_win32.hpp" 16 | #else 17 | #endif 18 | 19 | #include 20 | 21 | #include "../config.hpp" 22 | 23 | namespace TAO_PEGTL_NAMESPACE::internal 24 | { 25 | struct mmap_file 26 | { 27 | const mmap_file_impl data; 28 | 29 | explicit mmap_file( const std::filesystem::path& path ) 30 | : data( path ) 31 | {} 32 | 33 | mmap_file( const mmap_file& ) = delete; 34 | mmap_file( mmap_file&& ) = delete; 35 | 36 | ~mmap_file() = default; 37 | 38 | mmap_file& operator=( const mmap_file& ) = delete; 39 | mmap_file& operator=( mmap_file&& ) = delete; 40 | }; 41 | 42 | } // namespace TAO_PEGTL_NAMESPACE::internal 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/test/pegtl/contrib_parse_tree_to_dot.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include 8 | #include 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | // clang-format off 13 | struct A : one< 'a' > {}; 14 | struct B : one< 'b' > {}; 15 | struct C : one< 'c' > {}; 16 | 17 | #if defined( __cpp_exceptions ) 18 | struct S : if_must< one< '[' >, until< one< ']' > > > {}; 19 | #else 20 | struct S : seq< one< '[' >, until< one< ']' > > > {}; 21 | #endif 22 | 23 | struct D : sor< seq< A, B >, seq< A, C, S > > {}; 24 | // clang-format on 25 | 26 | template< typename Rule > 27 | struct selector 28 | : parse_tree::selector< Rule, parse_tree::store_content::on< A, B, C, D, S > > 29 | {}; 30 | 31 | void unit_test() 32 | { 33 | memory_input in( "ac[\"\\\x01\x7f\b\n\r\f\t\a\v]", "input" ); 34 | const auto root = parse_tree::parse< D, selector >( in ); 35 | parse_tree::print_dot( std::cout, *root ); 36 | } 37 | 38 | } // namespace TAO_PEGTL_NAMESPACE 39 | 40 | #include "main.hpp" 41 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/instantiate.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_INSTANTIATE_HPP 6 | #define TAO_PEGTL_CONTRIB_INSTANTIATE_HPP 7 | 8 | #include "../apply_mode.hpp" 9 | #include "../config.hpp" 10 | #include "../match.hpp" 11 | #include "../nothing.hpp" 12 | #include "../rewind_mode.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE 15 | { 16 | template< typename T > 17 | struct instantiate 18 | : maybe_nothing 19 | { 20 | template< typename Rule, 21 | apply_mode A, 22 | rewind_mode M, 23 | template< typename... > 24 | class Action, 25 | template< typename... > 26 | class Control, 27 | typename ParseInput, 28 | typename... States > 29 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 30 | { 31 | const T t( static_cast< const ParseInput& >( in ), st... ); 32 | return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); 33 | } 34 | }; 35 | 36 | } // namespace TAO_PEGTL_NAMESPACE 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/tao/pegtl/discard_input_on_success.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_DISCARD_INPUT_ON_SUCCESS_HPP 6 | #define TAO_PEGTL_DISCARD_INPUT_ON_SUCCESS_HPP 7 | 8 | #include "apply_mode.hpp" 9 | #include "config.hpp" 10 | #include "match.hpp" 11 | #include "nothing.hpp" 12 | #include "rewind_mode.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE 15 | { 16 | struct discard_input_on_success 17 | : maybe_nothing 18 | { 19 | template< typename Rule, 20 | apply_mode A, 21 | rewind_mode M, 22 | template< typename... > 23 | class Action, 24 | template< typename... > 25 | class Control, 26 | typename ParseInput, 27 | typename... States > 28 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 29 | { 30 | const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); 31 | if( result ) { 32 | in.discard(); 33 | } 34 | return result; 35 | } 36 | }; 37 | 38 | } // namespace TAO_PEGTL_NAMESPACE 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /include/tao/pegtl/discard_input_on_failure.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_DISCARD_INPUT_ON_FAILURE_HPP 6 | #define TAO_PEGTL_DISCARD_INPUT_ON_FAILURE_HPP 7 | 8 | #include "apply_mode.hpp" 9 | #include "config.hpp" 10 | #include "match.hpp" 11 | #include "nothing.hpp" 12 | #include "rewind_mode.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE 15 | { 16 | struct discard_input_on_failure 17 | : maybe_nothing 18 | { 19 | template< typename Rule, 20 | apply_mode A, 21 | rewind_mode M, 22 | template< typename... > 23 | class Action, 24 | template< typename... > 25 | class Control, 26 | typename ParseInput, 27 | typename... States > 28 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 29 | { 30 | const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); 31 | if( !result ) { 32 | in.discard(); 33 | } 34 | return result; 35 | } 36 | }; 37 | 38 | } // namespace TAO_PEGTL_NAMESPACE 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /include/tao/pegtl/type_list.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_TYPE_LIST_HPP 6 | #define TAO_PEGTL_TYPE_LIST_HPP 7 | 8 | #include 9 | 10 | #include "config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE 13 | { 14 | template< typename... Ts > 15 | struct type_list 16 | { 17 | static constexpr std::size_t size = sizeof...( Ts ); 18 | }; 19 | 20 | using empty_list = type_list<>; 21 | 22 | template< typename... > 23 | struct type_list_concat; 24 | 25 | template<> 26 | struct type_list_concat<> 27 | { 28 | using type = empty_list; 29 | }; 30 | 31 | template< typename... Ts > 32 | struct type_list_concat< type_list< Ts... > > 33 | { 34 | using type = type_list< Ts... >; 35 | }; 36 | 37 | template< typename... T0s, typename... T1s, typename... Ts > 38 | struct type_list_concat< type_list< T0s... >, type_list< T1s... >, Ts... > 39 | : type_list_concat< type_list< T0s..., T1s... >, Ts... > 40 | {}; 41 | 42 | template< typename... Ts > 43 | using type_list_concat_t = typename type_list_concat< Ts... >::type; 44 | 45 | } // namespace TAO_PEGTL_NAMESPACE 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/test/pegtl/restart_input.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | namespace TAO_PEGTL_NAMESPACE 8 | { 9 | using grammar = seq< string< 'a', 'b', 'c' >, eof >; 10 | 11 | void test_lazy() 12 | { 13 | const std::string data = "abc"; 14 | memory_input< tracking_mode::lazy, eol::lf_crlf, std::string > in( data, __FUNCTION__ ); 15 | bool success = parse< grammar >( in ); 16 | TAO_PEGTL_TEST_ASSERT( success ); 17 | in.restart(); 18 | success = parse< grammar >( in ); 19 | TAO_PEGTL_TEST_ASSERT( success ); 20 | } 21 | 22 | void test_eager() 23 | { 24 | const std::string data = "abc"; 25 | memory_input< tracking_mode::eager, eol::lf_crlf, std::string > in( std::string_view{ data }, __FUNCTION__ ); 26 | bool success = parse< grammar >( in ); 27 | TAO_PEGTL_TEST_ASSERT( success ); 28 | in.restart(); 29 | success = parse< grammar >( in ); 30 | TAO_PEGTL_TEST_ASSERT( success ); 31 | } 32 | 33 | void unit_test() 34 | { 35 | test_lazy(); 36 | test_eager(); 37 | } 38 | 39 | } // namespace TAO_PEGTL_NAMESPACE 40 | 41 | #include "main.hpp" 42 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/rep_string.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_REP_STRING_HPP 6 | #define TAO_PEGTL_CONTRIB_REP_STRING_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | #include "../internal/string.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE 15 | { 16 | namespace internal 17 | { 18 | template< std::size_t, typename, char... > 19 | struct make_rep_string; 20 | 21 | template< char... Ss, char... Cs > 22 | struct make_rep_string< 0, string< Ss... >, Cs... > 23 | { 24 | using type = string< Ss... >; 25 | }; 26 | 27 | template< std::size_t N, char... Ss, char... Cs > 28 | struct make_rep_string< N, string< Ss... >, Cs... > 29 | : make_rep_string< N - 1, string< Ss..., Cs... >, Cs... > 30 | {}; 31 | 32 | } // namespace internal 33 | 34 | inline namespace ascii 35 | { 36 | template< std::size_t N, char... Cs > 37 | struct rep_string 38 | : internal::make_rep_string< N, internal::string<>, Cs... >::type 39 | {}; 40 | 41 | } // namespace ascii 42 | 43 | } // namespace TAO_PEGTL_NAMESPACE 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/tao/pegtl/parse_error_base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_PARSE_ERROR_BASE_HPP 6 | #define TAO_PEGTL_PARSE_ERROR_BASE_HPP 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "config.hpp" 15 | 16 | namespace TAO_PEGTL_NAMESPACE 17 | { 18 | class parse_error_base 19 | : public std::runtime_error 20 | { 21 | public: 22 | [[nodiscard]] std::string_view message() const noexcept 23 | { 24 | return { what() + m_position_size + 2, m_message_size }; 25 | } 26 | 27 | [[nodiscard]] std::string_view position_string() const noexcept 28 | { 29 | return { what(), m_position_size }; 30 | } 31 | 32 | protected: 33 | const std::size_t m_message_size; 34 | const std::size_t m_position_size; 35 | 36 | parse_error_base( const std::string& msg, const std::string& pos ) 37 | : std::runtime_error( pos + ": " + msg ), 38 | m_message_size( msg.size() ), 39 | m_position_size( pos.size() ) 40 | {} 41 | }; 42 | 43 | } // namespace TAO_PEGTL_NAMESPACE 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/lf_crlf_eol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_LF_CRLF_EOL_HPP 6 | #define TAO_PEGTL_INTERNAL_LF_CRLF_EOL_HPP 7 | 8 | #include "data_and_size.hpp" 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | struct lf_crlf_eol 15 | { 16 | static constexpr int ch = '\n'; 17 | 18 | template< typename ParseInput > 19 | [[nodiscard]] static bool_and_size eol_match( ParseInput& in ) noexcept( noexcept( in.size( 2 ) ) ) 20 | { 21 | bool_and_size p = { false, in.size( 2 ) }; 22 | if( p.size > 0 ) { 23 | const auto a = in.peek_char(); 24 | if( a == '\n' ) { 25 | in.bump_to_next_line(); 26 | p.size = 1; 27 | p.data = true; 28 | } 29 | else if( ( a == '\r' ) && ( p.size > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) { 30 | in.bump_to_next_line( 2 ); 31 | p.size = 2; 32 | p.data = true; 33 | } 34 | } 35 | return p; 36 | } 37 | }; 38 | 39 | } // namespace TAO_PEGTL_NAMESPACE::internal 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/bump.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_BUMP_HPP 6 | #define TAO_PEGTL_INTERNAL_BUMP_HPP 7 | 8 | #include "inputerator.hpp" 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | inline void bump( inputerator& iter, const std::size_t count, const int ch ) noexcept 15 | { 16 | for( std::size_t i = 0; i < count; ++i ) { 17 | if( iter.data[ i ] == ch ) { 18 | ++iter.line; 19 | iter.column = 1; 20 | } 21 | else { 22 | ++iter.column; 23 | } 24 | } 25 | iter.byte += count; 26 | iter.data += count; 27 | } 28 | 29 | inline void bump_in_this_line( inputerator& iter, const std::size_t count ) noexcept 30 | { 31 | iter.data += count; 32 | iter.byte += count; 33 | iter.column += count; 34 | } 35 | 36 | inline void bump_to_next_line( inputerator& iter, const std::size_t count ) noexcept 37 | { 38 | ++iter.line; 39 | iter.byte += count; 40 | iter.column = 1; 41 | iter.data += count; 42 | } 43 | 44 | } // namespace TAO_PEGTL_NAMESPACE::internal 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /include/tao/pegtl/change_action.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CHANGE_ACTION_HPP 6 | #define TAO_PEGTL_CHANGE_ACTION_HPP 7 | 8 | #include 9 | 10 | #include "apply_mode.hpp" 11 | #include "config.hpp" 12 | #include "nothing.hpp" 13 | #include "rewind_mode.hpp" 14 | 15 | namespace TAO_PEGTL_NAMESPACE 16 | { 17 | template< template< typename... > class NewAction > 18 | struct change_action 19 | : maybe_nothing 20 | { 21 | template< typename Rule, 22 | apply_mode A, 23 | rewind_mode M, 24 | template< typename... > 25 | class Action, 26 | template< typename... > 27 | class Control, 28 | typename ParseInput, 29 | typename... States > 30 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 31 | { 32 | static_assert( !std::is_same_v< Action< void >, NewAction< void > >, "old and new action class templates are identical" ); 33 | return Control< Rule >::template match< A, M, NewAction, Control >( in, st... ); 34 | } 35 | }; 36 | 37 | } // namespace TAO_PEGTL_NAMESPACE 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/apply_single.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_APPLY_SINGLE_HPP 6 | #define TAO_PEGTL_INTERNAL_APPLY_SINGLE_HPP 7 | 8 | #include 9 | 10 | #include "../config.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE::internal 13 | { 14 | template< typename Action > 15 | struct apply_single 16 | { 17 | template< typename ActionInput, typename... States > 18 | [[nodiscard]] static auto match( const ActionInput& in, States&&... st ) noexcept( noexcept( Action::apply( in, st... ) ) ) 19 | -> std::enable_if_t< std::is_same_v< decltype( Action::apply( in, st... ) ), void >, bool > 20 | { 21 | Action::apply( in, st... ); 22 | return true; 23 | } 24 | 25 | template< typename ActionInput, typename... States > 26 | [[nodiscard]] static auto match( const ActionInput& in, States&&... st ) noexcept( noexcept( Action::apply( in, st... ) ) ) 27 | -> std::enable_if_t< std::is_same_v< decltype( Action::apply( in, st... ) ), bool >, bool > 28 | { 29 | return Action::apply( in, st... ); 30 | } 31 | }; 32 | 33 | } // namespace TAO_PEGTL_NAMESPACE::internal 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/separated_seq.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_SEPARATED_SEQ_HPP 6 | #define TAO_PEGTL_CONTRIB_SEPARATED_SEQ_HPP 7 | 8 | #include "../config.hpp" 9 | #include "../internal/seq.hpp" 10 | #include "../type_list.hpp" 11 | 12 | namespace TAO_PEGTL_NAMESPACE 13 | { 14 | namespace internal 15 | { 16 | template< typename... > 17 | struct sep; 18 | 19 | template< typename... Ts, typename S, typename Rule, typename... Rules > 20 | struct sep< type_list< Ts... >, S, Rule, Rules... > 21 | : sep< type_list< Ts..., Rule, S >, S, Rules... > 22 | {}; 23 | 24 | template< typename... Ts, typename S, typename Rule > 25 | struct sep< type_list< Ts... >, S, Rule > 26 | { 27 | using type = seq< Ts..., Rule >; 28 | }; 29 | 30 | template< typename S > 31 | struct sep< type_list<>, S > 32 | { 33 | using type = seq<>; 34 | }; 35 | 36 | } // namespace internal 37 | 38 | template< typename S, typename... Rules > 39 | struct separated_seq 40 | : internal::sep< type_list<>, S, Rules... >::type 41 | {}; 42 | 43 | } // namespace TAO_PEGTL_NAMESPACE 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/example/pegtl/json_unescape.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_UNESCAPE_HPP 6 | #define TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_UNESCAPE_HPP 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace example 15 | { 16 | namespace pegtl = TAO_PEGTL_NAMESPACE; 17 | 18 | // Action class for parsing literal strings, uses the PEGTL unescape utilities, cf. unescape.cpp. 19 | 20 | // clang-format off 21 | template< typename Rule > struct json_unescape_action {}; 22 | 23 | template<> struct json_unescape_action< pegtl::json::unicode > : pegtl::unescape::unescape_j {}; 24 | template<> struct json_unescape_action< pegtl::json::escaped_char > : pegtl::unescape::unescape_c< pegtl::json::escaped_char, '"', '\\', '/', '\b', '\f', '\n', '\r', '\t' > {}; 25 | template<> struct json_unescape_action< pegtl::json::unescaped > : pegtl::unescape::append_all {}; 26 | // clang-format on 27 | 28 | using json_unescape = pegtl::change_action_and_states< json_unescape_action, std::string >; 29 | 30 | } // namespace example 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_bof.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_meta.hpp" 7 | #include "verify_rule.hpp" 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | void unit_test() 12 | { 13 | verify_meta< bof, internal::bof >(); 14 | 15 | verify_analyze< bof >( __LINE__, __FILE__, false, false ); 16 | 17 | verify_rule< bof >( __LINE__, __FILE__, "", result_type::success, 0 ); 18 | 19 | for( char i = 1; i < 127; ++i ) { 20 | const char s[] = { i, 0 }; 21 | verify_rule< bof >( __LINE__, __FILE__, s, result_type::success, 1 ); 22 | } 23 | verify_rule< seq< alpha, bof > >( __LINE__, __FILE__, "a", result_type::local_failure, 1 ); 24 | verify_rule< seq< alpha, bof > >( __LINE__, __FILE__, "ab", result_type::local_failure, 2 ); 25 | verify_rule< seq< alpha, bof, alpha > >( __LINE__, __FILE__, "ab", result_type::local_failure, 2 ); 26 | verify_rule< seq< alpha, eol, bof > >( __LINE__, __FILE__, "a\n", result_type::local_failure, 2 ); 27 | verify_rule< seq< alpha, eol, bof > >( __LINE__, __FILE__, "a\nb", result_type::local_failure, 3 ); 28 | } 29 | 30 | } // namespace TAO_PEGTL_NAMESPACE 31 | 32 | #include "main.hpp" 33 | -------------------------------------------------------------------------------- /src/test/pegtl/ascii_three.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | #include "verify_meta.hpp" 7 | #include "verify_rule.hpp" 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | void unit_test() 12 | { 13 | verify_analyze< three< 'a' > >( __LINE__, __FILE__, true, false ); 14 | 15 | verify_rule< three< 'a' > >( __LINE__, __FILE__, "", result_type::local_failure ); 16 | verify_rule< three< 'a' > >( __LINE__, __FILE__, "a", result_type::local_failure ); 17 | verify_rule< three< 'a' > >( __LINE__, __FILE__, "aa", result_type::local_failure ); 18 | verify_rule< three< 'a' > >( __LINE__, __FILE__, "ab", result_type::local_failure ); 19 | verify_rule< three< 'a' > >( __LINE__, __FILE__, "aab", result_type::local_failure ); 20 | verify_rule< three< 'a' > >( __LINE__, __FILE__, "aaa", result_type::success ); 21 | verify_rule< three< 'a' > >( __LINE__, __FILE__, "aaaa", result_type::success, 1 ); 22 | verify_rule< three< 'a' > >( __LINE__, __FILE__, "aaaaa", result_type::success, 2 ); 23 | verify_rule< three< 'a' > >( __LINE__, __FILE__, "aaaaaa", result_type::success, 3 ); 24 | } 25 | 26 | } // namespace TAO_PEGTL_NAMESPACE 27 | 28 | #include "main.hpp" 29 | -------------------------------------------------------------------------------- /LICENSE_1_0.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /include/tao/pegtl/file_input.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_FILE_INPUT_HPP 6 | #define TAO_PEGTL_FILE_INPUT_HPP 7 | 8 | #include "config.hpp" 9 | #include "eol.hpp" 10 | #include "tracking_mode.hpp" 11 | 12 | #if defined( __unix__ ) || ( defined( __APPLE__ ) && defined( __MACH__ ) ) 13 | #include // Required for _POSIX_MAPPED_FILES 14 | #endif 15 | 16 | #if defined( _POSIX_MAPPED_FILES ) || defined( _WIN32 ) 17 | #include "mmap_input.hpp" 18 | #else 19 | #include "read_input.hpp" 20 | #endif 21 | 22 | namespace TAO_PEGTL_NAMESPACE 23 | { 24 | #if defined( _POSIX_MAPPED_FILES ) || defined( _WIN32 ) 25 | template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > 26 | struct file_input 27 | : mmap_input< P, Eol > 28 | { 29 | using mmap_input< P, Eol >::mmap_input; 30 | }; 31 | #else 32 | template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > 33 | struct file_input 34 | : read_input< P, Eol > 35 | { 36 | using read_input< P, Eol >::read_input; 37 | }; 38 | #endif 39 | 40 | template< typename... Ts > 41 | explicit file_input( Ts&&... ) -> file_input<>; 42 | 43 | } // namespace TAO_PEGTL_NAMESPACE 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/internal/peek_utf32.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UTF32_HPP 6 | #define TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UTF32_HPP 7 | 8 | #include 9 | 10 | #include "../../internal/data_and_size.hpp" 11 | 12 | #include "read_uint.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE::internal 15 | { 16 | template< typename R > 17 | struct peek_utf32_impl 18 | { 19 | using data_t = char32_t; 20 | using pair_t = data_and_size< char32_t >; 21 | 22 | static_assert( sizeof( char32_t ) == 4 ); 23 | 24 | template< typename ParseInput > 25 | [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.size( 4 ) ) ) 26 | { 27 | if( in.size( 4 ) < 4 ) { 28 | return { 0, 0 }; 29 | } 30 | const char32_t t = R::read( in.current() ); 31 | if( ( t <= 0x10ffff ) && !( t >= 0xd800 && t <= 0xdfff ) ) { 32 | return { t, 4 }; 33 | } 34 | return { 0, 0 }; 35 | } 36 | }; 37 | 38 | using peek_utf32_be = peek_utf32_impl< read_uint32_be >; 39 | using peek_utf32_le = peek_utf32_impl< read_uint32_le >; 40 | 41 | } // namespace TAO_PEGTL_NAMESPACE::internal 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_raise.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cout << "Exception support disabled, skipping test..." << std::endl; 10 | } 11 | #else 12 | 13 | #include "test.hpp" 14 | 15 | #include "verify_meta.hpp" 16 | 17 | #if defined( _MSC_VER ) 18 | #pragma warning( push ) 19 | #pragma warning( disable : 4702 ) 20 | #endif 21 | 22 | namespace TAO_PEGTL_NAMESPACE 23 | { 24 | void unit_test() 25 | { 26 | verify_meta< raise< int >, internal::raise< int > >(); 27 | verify_meta< raise< any >, internal::raise< any > >(); 28 | 29 | verify_analyze< raise< int > >( __LINE__, __FILE__, true, false ); 30 | verify_analyze< raise< any > >( __LINE__, __FILE__, true, false ); 31 | 32 | memory_input in( "foo", __FUNCTION__ ); 33 | 34 | TAO_PEGTL_TEST_THROWS( parse< raise< int > >( in ) ); 35 | TAO_PEGTL_TEST_ASSERT( in.size( 4 ) == 3 ); 36 | TAO_PEGTL_TEST_THROWS( parse< raise< any > >( in ) ); 37 | TAO_PEGTL_TEST_ASSERT( in.size( 4 ) == 3 ); 38 | } 39 | 40 | } // namespace TAO_PEGTL_NAMESPACE 41 | 42 | #if defined( _MSC_VER ) 43 | #pragma warning( pop ) 44 | #endif 45 | 46 | #include "main.hpp" 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/partial.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_PARTIAL_HPP 6 | #define TAO_PEGTL_INTERNAL_PARTIAL_HPP 7 | 8 | #include "enable_control.hpp" 9 | 10 | #include "../apply_mode.hpp" 11 | #include "../config.hpp" 12 | #include "../rewind_mode.hpp" 13 | #include "../type_list.hpp" 14 | 15 | namespace TAO_PEGTL_NAMESPACE::internal 16 | { 17 | template< typename... Rules > 18 | struct partial 19 | { 20 | using rule_t = partial; 21 | using subs_t = type_list< Rules... >; 22 | 23 | template< apply_mode A, 24 | rewind_mode, 25 | template< typename... > 26 | class Action, 27 | template< typename... > 28 | class Control, 29 | typename ParseInput, 30 | typename... States > 31 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 32 | { 33 | (void)( Control< Rules >::template match< A, rewind_mode::required, Action, Control >( in, st... ) && ... ); 34 | return true; 35 | } 36 | }; 37 | 38 | template< typename... Rules > 39 | inline constexpr bool enable_control< partial< Rules... > > = false; 40 | 41 | } // namespace TAO_PEGTL_NAMESPACE::internal 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/example/pegtl/hello_world.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace pegtl = TAO_PEGTL_NAMESPACE; 11 | 12 | namespace hello 13 | { 14 | // clang-format off 15 | struct prefix : pegtl::string< 'H', 'e', 'l', 'l', 'o', ',', ' ' > {}; 16 | struct name : pegtl::plus< pegtl::alpha > {}; 17 | struct grammar : pegtl::seq< prefix, name, pegtl::one< '!' >, pegtl::eof > {}; 18 | // clang-format on 19 | 20 | template< typename Rule > 21 | struct action 22 | {}; 23 | 24 | template<> 25 | struct action< name > 26 | { 27 | template< typename ActionInput > 28 | static void apply( const ActionInput& in, std::string& v ) 29 | { 30 | v = in.string(); 31 | } 32 | }; 33 | 34 | } // namespace hello 35 | 36 | int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) 37 | { 38 | if( argc > 1 ) { 39 | std::string name; 40 | 41 | pegtl::argv_input in( argv, 1 ); 42 | if( pegtl::parse< hello::grammar, hello::action >( in, name ) ) { 43 | std::cout << "Good bye, " << name << "!" << std::endl; 44 | } 45 | else { 46 | std::cerr << "I don't understand." << std::endl; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/pegtl/check_bytes.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include "test.hpp" 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | struct test_rule 12 | : star< alpha > 13 | {}; 14 | 15 | struct test_grammar 16 | : seq< test_rule, eof > 17 | {}; 18 | 19 | template< typename Rule > 20 | struct test_action 21 | : nothing< Rule > 22 | {}; 23 | 24 | template<> 25 | struct test_action< test_rule > 26 | : check_bytes< 5 > 27 | {}; 28 | 29 | void unit_test() 30 | { 31 | memory_input<> i1( "aaa", __FUNCTION__ ); 32 | const auto r1 = parse< test_grammar >( i1 ); 33 | TAO_PEGTL_TEST_ASSERT( r1 ); 34 | 35 | memory_input<> i2( "aaaaaaaaaaa", __FUNCTION__ ); 36 | const auto r2 = parse< test_grammar >( i2 ); 37 | TAO_PEGTL_TEST_ASSERT( r2 ); 38 | 39 | memory_input<> i3( "aaa", __FUNCTION__ ); 40 | const auto r3 = parse< test_grammar, test_action >( i3 ); 41 | TAO_PEGTL_TEST_ASSERT( r3 ); 42 | 43 | #if defined( __cpp_exceptions ) 44 | memory_input<> i4( "aaaaaaaaaaa", __FUNCTION__ ); 45 | TAO_PEGTL_TEST_THROWS( parse< test_grammar, test_action >( i4 ) ); 46 | #endif 47 | } 48 | 49 | } // namespace TAO_PEGTL_NAMESPACE 50 | 51 | #include "main.hpp" 52 | -------------------------------------------------------------------------------- /src/test/pegtl/limit_bytes.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | 7 | #include "test.hpp" 8 | 9 | namespace TAO_PEGTL_NAMESPACE 10 | { 11 | struct test_rule 12 | : star< alpha > 13 | {}; 14 | 15 | struct test_grammar 16 | : seq< test_rule, eof > 17 | {}; 18 | 19 | template< typename Rule > 20 | struct test_action 21 | : nothing< Rule > 22 | {}; 23 | 24 | template<> 25 | struct test_action< test_rule > 26 | : limit_bytes< 5 > 27 | {}; 28 | 29 | void unit_test() 30 | { 31 | memory_input<> i1( "aaa", __FUNCTION__ ); 32 | const auto r1 = parse< test_grammar >( i1 ); 33 | TAO_PEGTL_TEST_ASSERT( r1 ); 34 | 35 | memory_input<> i2( "aaaaaaaaaaa", __FUNCTION__ ); 36 | const auto r2 = parse< test_grammar >( i2 ); 37 | TAO_PEGTL_TEST_ASSERT( r2 ); 38 | 39 | memory_input<> i3( "aaa", __FUNCTION__ ); 40 | const auto r3 = parse< test_grammar, test_action >( i3 ); 41 | TAO_PEGTL_TEST_ASSERT( r3 ); 42 | 43 | #if defined( __cpp_exceptions ) 44 | memory_input<> i4( "aaaaaaaaaaa", __FUNCTION__ ); 45 | TAO_PEGTL_TEST_THROWS( parse< test_grammar, test_action >( i4 ) ); 46 | #endif 47 | } 48 | 49 | } // namespace TAO_PEGTL_NAMESPACE 50 | 51 | #include "main.hpp" 52 | -------------------------------------------------------------------------------- /src/test/pegtl/file_istream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | #include 7 | 8 | #include "test.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | struct file_content 13 | : seq< TAO_PEGTL_STRING( "dummy content" ), eol, discard > 14 | {}; 15 | 16 | struct file_grammar 17 | : seq< rep_min_max< 11, 11, file_content >, eof > 18 | {}; 19 | 20 | void unit_test() 21 | { 22 | #if defined( __cpp_exceptions ) 23 | { 24 | const char* filename = "src/test/pegtl/no_such_file.txt"; 25 | try { 26 | std::ifstream stream( filename ); 27 | parse< file_grammar >( istream_input( stream, 16, filename ) ); 28 | TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE 29 | } 30 | catch( const std::system_error& e ) { 31 | TAO_PEGTL_TEST_ASSERT( e.code().category() == std::system_category() ); 32 | TAO_PEGTL_TEST_ASSERT( e.code().value() == ENOENT ); 33 | } 34 | } 35 | #endif 36 | 37 | const char* filename = "src/test/pegtl/file_data.txt"; 38 | std::ifstream stream( filename ); 39 | TAO_PEGTL_TEST_ASSERT( parse< file_grammar >( istream_input( stream, 16, filename ) ) ); 40 | } 41 | 42 | } // namespace TAO_PEGTL_NAMESPACE 43 | 44 | #include "main.hpp" 45 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/star_partial.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_STAR_PARTIAL_HPP 6 | #define TAO_PEGTL_INTERNAL_STAR_PARTIAL_HPP 7 | 8 | #include "enable_control.hpp" 9 | 10 | #include "../apply_mode.hpp" 11 | #include "../config.hpp" 12 | #include "../rewind_mode.hpp" 13 | #include "../type_list.hpp" 14 | 15 | namespace TAO_PEGTL_NAMESPACE::internal 16 | { 17 | template< typename... Rules > 18 | struct star_partial 19 | { 20 | using rule_t = star_partial; 21 | using subs_t = type_list< Rules... >; 22 | 23 | template< apply_mode A, 24 | rewind_mode, 25 | template< typename... > 26 | class Action, 27 | template< typename... > 28 | class Control, 29 | typename ParseInput, 30 | typename... States > 31 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 32 | { 33 | while( ( Control< Rules >::template match< A, rewind_mode::required, Action, Control >( in, st... ) && ... ) ) { 34 | } 35 | return true; 36 | } 37 | }; 38 | 39 | template< typename... Rules > 40 | inline constexpr bool enable_control< star_partial< Rules... > > = false; 41 | 42 | } // namespace TAO_PEGTL_NAMESPACE::internal 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/internal/vector_stack_guard.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_INTERNAL_VECTOR_STACK_GUARD_HPP 6 | #define TAO_PEGTL_CONTRIB_INTERNAL_VECTOR_STACK_GUARD_HPP 7 | 8 | #include 9 | #include 10 | 11 | namespace TAO_PEGTL_NAMESPACE::internal 12 | { 13 | template< typename... Cs > 14 | class [[nodiscard]] vector_stack_guard 15 | { 16 | public: 17 | template< typename... Ts > 18 | vector_stack_guard( std::vector< Cs... >& vector, Ts&&... ts ) 19 | : m_s( vector ) 20 | { 21 | m_s.emplace_back( std::forward< Ts >( ts )... ); 22 | } 23 | 24 | vector_stack_guard( vector_stack_guard&& ) = delete; 25 | vector_stack_guard( const vector_stack_guard& ) = delete; 26 | 27 | vector_stack_guard& operator=( vector_stack_guard&& ) = delete; 28 | vector_stack_guard& operator=( const vector_stack_guard& ) = delete; 29 | 30 | ~vector_stack_guard() 31 | { 32 | m_s.pop_back(); 33 | } 34 | 35 | private: 36 | std::vector< Cs... >& m_s; 37 | }; 38 | 39 | template< typename... Cs > 40 | vector_stack_guard( std::vector< Cs... >&, const typename std::vector< Cs... >::value_type& ) -> vector_stack_guard< Cs... >; 41 | 42 | } // namespace TAO_PEGTL_NAMESPACE::internal 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /.github/workflows/macos.yml: -------------------------------------------------------------------------------- 1 | name: macOS 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - 'README.md' 7 | - 'doc/**' 8 | pull_request: 9 | paths-ignore: 10 | - 'README.md' 11 | - 'doc/**' 12 | 13 | jobs: 14 | xcode: 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | include: 19 | - llvm: 18 20 | build_type: Debug 21 | os: macos-14 22 | - llvm: 18 23 | build_type: Release 24 | os: macos-14 25 | - llvm: 16 26 | build_type: Debug 27 | os: macos-13 28 | - llvm: 16 29 | build_type: Release 30 | os: macos-13 31 | runs-on: ${{ matrix.os }} 32 | 33 | steps: 34 | - name: Install Dependencies 35 | run: | 36 | brew update 37 | brew install llvm@${{ matrix.llvm }} 38 | brew install ninja 39 | 40 | - uses: actions/checkout@v4 41 | - name: Configure CMake 42 | run: | 43 | cmake -S $GITHUB_WORKSPACE -B build \ 44 | -GNinja \ 45 | -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ 46 | -DCMAKE_CXX_COMPILER=$(brew --prefix llvm@${{ matrix.llvm }})/bin/clang++ \ 47 | -DCMAKE_LINKER=$(brew --prefix llvm@${{ matrix.llvm }})/bin/ld.lld 48 | 49 | - name: Build project 50 | run: cmake --build build/ --config ${{ matrix.build_type }} 51 | 52 | - name: Run tests 53 | working-directory: build/ 54 | run: ctest -C ${{ matrix.build_type }} --output-on-failure 55 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/raise.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_RAISE_HPP 6 | #define TAO_PEGTL_INTERNAL_RAISE_HPP 7 | 8 | #if !defined( __cpp_exceptions ) 9 | #error "Exception support required for tao/pegtl/internal/raise.hpp" 10 | #else 11 | 12 | #include 13 | 14 | #include "enable_control.hpp" 15 | 16 | #include "../apply_mode.hpp" 17 | #include "../config.hpp" 18 | #include "../rewind_mode.hpp" 19 | #include "../type_list.hpp" 20 | 21 | namespace TAO_PEGTL_NAMESPACE::internal 22 | { 23 | template< typename T > 24 | struct raise 25 | { 26 | using rule_t = raise; 27 | using subs_t = empty_list; 28 | 29 | template< apply_mode, 30 | rewind_mode, 31 | template< typename... > 32 | class Action, 33 | template< typename... > 34 | class Control, 35 | typename ParseInput, 36 | typename... States > 37 | [[noreturn]] static bool match( ParseInput& in, States&&... st ) 38 | { 39 | Control< T >::raise( static_cast< const ParseInput& >( in ), st... ); 40 | } 41 | }; 42 | 43 | template< typename T > 44 | inline constexpr bool enable_control< raise< T > > = false; 45 | 46 | } // namespace TAO_PEGTL_NAMESPACE::internal 47 | 48 | #endif 49 | #endif 50 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/has_match.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_HAS_MATCH_HPP 6 | #define TAO_PEGTL_INTERNAL_HAS_MATCH_HPP 7 | 8 | #include 9 | 10 | #include "../apply_mode.hpp" 11 | #include "../config.hpp" 12 | #include "../rewind_mode.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE::internal 15 | { 16 | template< typename, 17 | typename Rule, 18 | apply_mode A, 19 | rewind_mode M, 20 | template< typename... > 21 | class Action, 22 | template< typename... > 23 | class Control, 24 | typename ParseInput, 25 | typename... States > 26 | inline constexpr bool has_match = false; 27 | 28 | template< typename Rule, 29 | apply_mode A, 30 | rewind_mode M, 31 | template< typename... > 32 | class Action, 33 | template< typename... > 34 | class Control, 35 | typename ParseInput, 36 | typename... States > 37 | inline constexpr bool has_match< decltype( (void)Action< Rule >::template match< Rule, A, M, Action, Control >( std::declval< ParseInput& >(), std::declval< States&& >()... ), bool() ), Rule, A, M, Action, Control, ParseInput, States... > = true; 38 | 39 | } // namespace TAO_PEGTL_NAMESPACE::internal 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/inputerator.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_INPUTERATOR_HPP 6 | #define TAO_PEGTL_INTERNAL_INPUTERATOR_HPP 7 | 8 | #include 9 | #include 10 | 11 | #include "../config.hpp" 12 | 13 | namespace TAO_PEGTL_NAMESPACE::internal 14 | { 15 | struct inputerator 16 | { 17 | inputerator() noexcept = default; 18 | 19 | explicit inputerator( const char* in_data ) noexcept 20 | : data( in_data ) 21 | {} 22 | 23 | inputerator( const char* in_data, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_column ) noexcept 24 | : data( in_data ), 25 | byte( in_byte ), 26 | line( in_line ), 27 | column( in_column ) 28 | { 29 | assert( in_line != 0 ); 30 | assert( in_column != 0 ); 31 | } 32 | 33 | inputerator( const inputerator& ) = default; 34 | inputerator( inputerator&& ) = default; 35 | 36 | ~inputerator() = default; 37 | 38 | inputerator& operator=( const inputerator& ) = default; 39 | inputerator& operator=( inputerator&& ) = default; 40 | 41 | const char* data = nullptr; 42 | 43 | std::size_t byte = 0; 44 | std::size_t line = 1; 45 | std::size_t column = 1; 46 | }; 47 | 48 | } // namespace TAO_PEGTL_NAMESPACE::internal 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /include/tao/pegtl.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_HPP 6 | #define TAO_PEGTL_HPP 7 | 8 | #include "pegtl/config.hpp" 9 | 10 | #include "pegtl/demangle.hpp" 11 | #include "pegtl/parse.hpp" 12 | #include "pegtl/version.hpp" 13 | 14 | #include "pegtl/ascii.hpp" 15 | #include "pegtl/rules.hpp" 16 | #include "pegtl/utf8.hpp" 17 | 18 | #include "pegtl/argv_input.hpp" 19 | #include "pegtl/buffer_input.hpp" 20 | #include "pegtl/cstream_input.hpp" 21 | #include "pegtl/istream_input.hpp" 22 | #include "pegtl/memory_input.hpp" 23 | #include "pegtl/read_input.hpp" 24 | #include "pegtl/string_input.hpp" 25 | 26 | // This has to be included *after* the above inputs, 27 | // otherwise the amalgamated header will not work! 28 | #include "pegtl/file_input.hpp" 29 | 30 | #include "pegtl/change_action.hpp" 31 | #include "pegtl/change_action_and_state.hpp" 32 | #include "pegtl/change_action_and_states.hpp" 33 | #include "pegtl/change_control.hpp" 34 | #include "pegtl/change_state.hpp" 35 | #include "pegtl/change_states.hpp" 36 | 37 | #include "pegtl/disable_action.hpp" 38 | #include "pegtl/enable_action.hpp" 39 | 40 | #include "pegtl/discard_input.hpp" 41 | #include "pegtl/discard_input_on_failure.hpp" 42 | #include "pegtl/discard_input_on_success.hpp" 43 | 44 | #include "pegtl/visit.hpp" 45 | 46 | #if defined( __cpp_exceptions ) 47 | #include "pegtl/must_if.hpp" 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/istream_reader.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_ISTREAM_READER_HPP 6 | #define TAO_PEGTL_INTERNAL_ISTREAM_READER_HPP 7 | 8 | #include 9 | 10 | #if defined( __cpp_exceptions ) 11 | #include 12 | #else 13 | #include 14 | #include 15 | #endif 16 | 17 | #include "../config.hpp" 18 | 19 | namespace TAO_PEGTL_NAMESPACE::internal 20 | { 21 | struct istream_reader 22 | { 23 | explicit istream_reader( std::istream& s ) noexcept 24 | : m_istream( s ) 25 | {} 26 | 27 | [[nodiscard]] std::size_t operator()( char* buffer, const std::size_t length ) 28 | { 29 | m_istream.read( buffer, static_cast< std::streamsize >( length ) ); 30 | 31 | if( const auto r = m_istream.gcount() ) { 32 | return static_cast< std::size_t >( r ); 33 | } 34 | if( m_istream.eof() ) { 35 | return 0; 36 | } 37 | #if defined( __cpp_exceptions ) 38 | const auto ec = errno; 39 | throw std::system_error( ec, std::system_category(), "std::istream::read() failed" ); 40 | #else 41 | std::fputs( "std::istream::read() failed\n", stderr ); 42 | std::terminate(); 43 | #endif 44 | } 45 | 46 | std::istream& m_istream; 47 | }; 48 | 49 | } // namespace TAO_PEGTL_NAMESPACE::internal 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/test/pegtl/contrib_to_string.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | #include 8 | #include 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | void unit_test() 13 | { 14 | TAO_PEGTL_TEST_ASSERT( to_string< string<> >().empty() ); 15 | TAO_PEGTL_TEST_ASSERT( ( to_string< string< 'a', 'b', 'c' > >() == "abc" ) ); 16 | 17 | TAO_PEGTL_TEST_ASSERT( to_string< istring<> >().empty() ); 18 | TAO_PEGTL_TEST_ASSERT( ( to_string< istring< 'a', 'b', 'c' > >() == "abc" ) ); 19 | 20 | TAO_PEGTL_TEST_ASSERT( to_string< TAO_PEGTL_STRING( "" ) >().empty() ); 21 | TAO_PEGTL_TEST_ASSERT( to_string< TAO_PEGTL_STRING( "abc" ) >() == "abc" ); 22 | TAO_PEGTL_TEST_ASSERT( to_string< TAO_PEGTL_STRING( "AbC" ) >() == "AbC" ); 23 | TAO_PEGTL_TEST_ASSERT( to_string< TAO_PEGTL_STRING( "abc" ) >() != "AbC" ); 24 | TAO_PEGTL_TEST_ASSERT( to_string< TAO_PEGTL_ISTRING( "abc" ) >() == "abc" ); 25 | TAO_PEGTL_TEST_ASSERT( to_string< TAO_PEGTL_ISTRING( "AbC" ) >() == "AbC" ); 26 | TAO_PEGTL_TEST_ASSERT( to_string< TAO_PEGTL_ISTRING( "abc" ) >() != "AbC" ); 27 | 28 | // to_string does *not* care about the outer class template 29 | TAO_PEGTL_TEST_ASSERT( ( to_string< one< 'a', 'b', 'c' > >() == "abc" ) ); 30 | } 31 | 32 | } // namespace TAO_PEGTL_NAMESPACE 33 | 34 | #include "main.hpp" 35 | -------------------------------------------------------------------------------- /src/test/pegtl/test_setup.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | #ifdef __GNUC__ 11 | std::cout << "__GNUC__: " << __GNUC__ << std::endl; 12 | std::cout << "__GNUC_MINOR__: " << __GNUC_MINOR__ << std::endl; 13 | std::cout << "__GNUC_PATCHLEVEL__: " << __GNUC_PATCHLEVEL__ << std::endl; 14 | #endif 15 | #ifdef __GLIBCPP__ 16 | std::cout << "__GLIBCPP__: " << __GLIBCPP__ << std::endl; 17 | #endif 18 | #ifdef __GLIBCXX__ 19 | std::cout << "__GLIBCXX__: " << __GLIBCXX__ << std::endl; 20 | #endif 21 | 22 | #ifdef __clang__ 23 | std::cout << "__clang__: " << __clang__ << std::endl; 24 | std::cout << "__clang_major__: " << __clang_major__ << std::endl; 25 | std::cout << "__clang_minor__: " << __clang_minor__ << std::endl; 26 | std::cout << "__clang_patchlevel__: " << __clang_patchlevel__ << std::endl; 27 | std::cout << "__clang_version__: " << __clang_version__ << std::endl; 28 | #endif 29 | #ifdef __apple_build_version__ 30 | std::cout << "__apple_build_version__: " << __apple_build_version__ << std::endl; 31 | #endif 32 | #ifdef _LIBCPP_VERSION 33 | std::cout << "_LIBCPP_VERSION: " << _LIBCPP_VERSION << std::endl; 34 | #endif 35 | 36 | #ifdef _MSC_VER 37 | std::cout << "_MSC_VER: " << _MSC_VER << std::endl; 38 | std::cout << "_MSC_FULL_VER: " << _MSC_FULL_VER << std::endl; 39 | #endif 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /include/tao/pegtl/argv_input.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_ARGV_INPUT_HPP 6 | #define TAO_PEGTL_ARGV_INPUT_HPP 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "config.hpp" 14 | #include "eol.hpp" 15 | #include "memory_input.hpp" 16 | #include "tracking_mode.hpp" 17 | 18 | namespace TAO_PEGTL_NAMESPACE 19 | { 20 | namespace internal 21 | { 22 | [[nodiscard]] inline std::string make_argv_source( const std::size_t argn ) 23 | { 24 | std::ostringstream oss; 25 | oss << "argv[" << argn << ']'; 26 | return std::move( oss ).str(); 27 | } 28 | 29 | } // namespace internal 30 | 31 | template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > 32 | struct argv_input 33 | : memory_input< P, Eol > 34 | { 35 | template< typename T > 36 | argv_input( char** argv, const std::size_t argn, T&& in_source ) 37 | : memory_input< P, Eol >( static_cast< const char* >( argv[ argn ] ), std::forward< T >( in_source ) ) 38 | {} 39 | 40 | argv_input( char** argv, const std::size_t argn ) 41 | : argv_input( argv, argn, internal::make_argv_source( argn ) ) 42 | {} 43 | }; 44 | 45 | template< typename... Ts > 46 | argv_input( Ts&&... ) -> argv_input<>; 47 | 48 | } // namespace TAO_PEGTL_NAMESPACE 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/internal/peek_uint.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UINT_HPP 6 | #define TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UINT_HPP 7 | 8 | #include 9 | #include 10 | 11 | #include "../../internal/data_and_size.hpp" 12 | 13 | #include "read_uint.hpp" 14 | 15 | namespace TAO_PEGTL_NAMESPACE::internal 16 | { 17 | template< typename R > 18 | struct peek_uint_impl 19 | { 20 | using data_t = typename R::type; 21 | using pair_t = data_and_size< data_t >; 22 | 23 | template< typename ParseInput > 24 | [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.size( sizeof( data_t ) ) ) ) 25 | { 26 | if( in.size( sizeof( data_t ) ) < sizeof( data_t ) ) { 27 | return { 0, 0 }; 28 | } 29 | const data_t data = R::read( in.current() ); 30 | return { data, sizeof( data_t ) }; 31 | } 32 | }; 33 | 34 | using peek_uint16_be = peek_uint_impl< read_uint16_be >; 35 | using peek_uint16_le = peek_uint_impl< read_uint16_le >; 36 | 37 | using peek_uint32_be = peek_uint_impl< read_uint32_be >; 38 | using peek_uint32_le = peek_uint_impl< read_uint32_le >; 39 | 40 | using peek_uint64_be = peek_uint_impl< read_uint64_be >; 41 | using peek_uint64_le = peek_uint_impl< read_uint64_le >; 42 | 43 | } // namespace TAO_PEGTL_NAMESPACE::internal 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/tao/pegtl/utf8.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_UTF8_HPP 6 | #define TAO_PEGTL_UTF8_HPP 7 | 8 | #include "config.hpp" 9 | 10 | #include "internal/peek_utf8.hpp" 11 | #include "internal/result_on_found.hpp" 12 | #include "internal/rules.hpp" 13 | 14 | namespace TAO_PEGTL_NAMESPACE::utf8 15 | { 16 | // clang-format off 17 | struct any : internal::any< internal::peek_utf8 > {}; 18 | struct bom : internal::one< internal::result_on_found::success, internal::peek_utf8, 0xfeff > {}; // Lemon curry? 19 | template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf8, Cs... > {}; 20 | template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf8, Lo, Hi > {}; 21 | template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf8, Cs... > {}; 22 | template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_utf8, Lo, Hi > {}; 23 | template< char32_t... Cs > struct ranges : internal::ranges< internal::peek_utf8, Cs... > {}; 24 | template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_utf8, Cs >... > {}; 25 | // clang-format on 26 | 27 | } // namespace TAO_PEGTL_NAMESPACE::utf8 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/test/pegtl/error_message.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) 6 | #include 7 | int main() 8 | { 9 | std::cout << "Exception support disabled, skipping test..." << std::endl; 10 | } 11 | #else 12 | 13 | #include "test.hpp" 14 | 15 | namespace test1 16 | { 17 | using namespace TAO_PEGTL_NAMESPACE; 18 | 19 | // clang-format off 20 | struct a : one< 'a' > {}; 21 | struct b : one< 'b' > {}; 22 | struct grammar : sor< a, b > {}; 23 | 24 | template< typename > inline constexpr const char* error_message = nullptr; 25 | template<> inline constexpr auto error_message< b > = "test123"; 26 | // clang-format on 27 | 28 | struct error 29 | { 30 | template< typename Rule > 31 | static constexpr auto message = error_message< Rule >; 32 | }; 33 | 34 | template< typename Rule > 35 | using control = must_if< error >::control< Rule >; 36 | 37 | } // namespace test1 38 | 39 | namespace TAO_PEGTL_NAMESPACE 40 | { 41 | void unit_test() 42 | { 43 | try { 44 | parse< test1::grammar, nothing, test1::control >( memory_input( "c", __FUNCTION__ ) ); 45 | TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE 46 | } 47 | catch( const parse_error& e ) { 48 | TAO_PEGTL_TEST_ASSERT( e.message() == "test123" ); 49 | } 50 | } 51 | 52 | } // namespace TAO_PEGTL_NAMESPACE 53 | 54 | #include "main.hpp" 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/tao/pegtl/mmap_input.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_MMAP_INPUT_HPP 6 | #define TAO_PEGTL_MMAP_INPUT_HPP 7 | 8 | #include 9 | #include 10 | 11 | #include "config.hpp" 12 | #include "eol.hpp" 13 | #include "memory_input.hpp" 14 | #include "tracking_mode.hpp" 15 | 16 | #include "internal/mmap_file.hpp" 17 | #include "internal/path_to_string.hpp" 18 | 19 | namespace TAO_PEGTL_NAMESPACE 20 | { 21 | template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > 22 | struct mmap_input 23 | : private internal::mmap_file, 24 | public memory_input< P, Eol > 25 | { 26 | mmap_input( const std::filesystem::path& path, const std::string& source ) 27 | : internal::mmap_file( path ), 28 | memory_input< P, Eol >( data.begin(), data.end(), source ) 29 | {} 30 | 31 | explicit mmap_input( const std::filesystem::path& path ) 32 | : mmap_input( path, internal::path_to_string( path ) ) 33 | {} 34 | 35 | mmap_input( const mmap_input& ) = delete; 36 | mmap_input( mmap_input&& ) = delete; 37 | 38 | ~mmap_input() = default; 39 | 40 | mmap_input& operator=( const mmap_input& ) = delete; 41 | mmap_input& operator=( mmap_input&& ) = delete; 42 | }; 43 | 44 | template< typename... Ts > 45 | explicit mmap_input( Ts&&... ) -> mmap_input<>; 46 | 47 | } // namespace TAO_PEGTL_NAMESPACE 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/apply0.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_APPLY0_HPP 6 | #define TAO_PEGTL_INTERNAL_APPLY0_HPP 7 | 8 | #include "apply0_single.hpp" 9 | #include "enable_control.hpp" 10 | 11 | #include "../apply_mode.hpp" 12 | #include "../config.hpp" 13 | #include "../rewind_mode.hpp" 14 | #include "../type_list.hpp" 15 | 16 | namespace TAO_PEGTL_NAMESPACE::internal 17 | { 18 | template< typename... Actions > 19 | struct apply0 20 | { 21 | using rule_t = apply0; 22 | using subs_t = empty_list; 23 | 24 | template< apply_mode A, 25 | rewind_mode M, 26 | template< typename... > 27 | class Action, 28 | template< typename... > 29 | class Control, 30 | typename ParseInput, 31 | typename... States > 32 | [[nodiscard]] static bool match( ParseInput& /*unused*/, [[maybe_unused]] States&&... st ) 33 | { 34 | if constexpr( A == apply_mode::action ) { 35 | return ( apply0_single< Actions >::match( st... ) && ... ); 36 | } 37 | else { 38 | #if defined( _MSC_VER ) 39 | ( (void)st, ... ); 40 | #endif 41 | return true; 42 | } 43 | } 44 | }; 45 | 46 | template< typename... Actions > 47 | inline constexpr bool enable_control< apply0< Actions... > > = false; 48 | 49 | } // namespace TAO_PEGTL_NAMESPACE::internal 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/enable.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_ENABLE_HPP 6 | #define TAO_PEGTL_INTERNAL_ENABLE_HPP 7 | 8 | #include "enable_control.hpp" 9 | #include "seq.hpp" 10 | #include "success.hpp" 11 | 12 | #include "../apply_mode.hpp" 13 | #include "../config.hpp" 14 | #include "../rewind_mode.hpp" 15 | #include "../type_list.hpp" 16 | 17 | namespace TAO_PEGTL_NAMESPACE::internal 18 | { 19 | template< typename... Rules > 20 | struct enable 21 | : enable< seq< Rules... > > 22 | {}; 23 | 24 | template<> 25 | struct enable<> 26 | : success 27 | {}; 28 | 29 | template< typename Rule > 30 | struct enable< Rule > 31 | { 32 | using rule_t = enable; 33 | using subs_t = type_list< Rule >; 34 | 35 | template< apply_mode, 36 | rewind_mode M, 37 | template< typename... > 38 | class Action, 39 | template< typename... > 40 | class Control, 41 | typename ParseInput, 42 | typename... States > 43 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 44 | { 45 | return Control< Rule >::template match< apply_mode::action, M, Action, Control >( in, st... ); 46 | } 47 | }; 48 | 49 | template< typename... Rules > 50 | inline constexpr bool enable_control< enable< Rules... > > = false; 51 | 52 | } // namespace TAO_PEGTL_NAMESPACE::internal 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/test/pegtl/rule_try_catch_raise_nested.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #if !defined( __cpp_exceptions ) || !defined( __cpp_rtti ) 6 | #include 7 | int main() 8 | { 9 | std::cout << "Exception and/or RTTI support disabled, skipping test..." << std::endl; 10 | } 11 | #else 12 | 13 | #include "test.hpp" 14 | #include "verify_seqs.hpp" 15 | 16 | #include 17 | 18 | namespace TAO_PEGTL_NAMESPACE 19 | { 20 | template< typename... Rules > 21 | using test_try_catch_rule = try_catch_raise_nested< must< Rules... > >; 22 | 23 | template< typename... Rules > 24 | using test_try_catch_any_rule = try_catch_any_raise_nested< must< Rules... > >; 25 | 26 | template< template< typename... > class Rule > 27 | void verify_nested() 28 | { 29 | try { 30 | memory_input in( "0", __FUNCTION__ ); 31 | parse< Rule< alpha > >( in ); 32 | TAO_PEGTL_TEST_UNREACHABLE; 33 | } 34 | catch( ... ) { 35 | const std::vector< parse_error > e = nested::flatten(); 36 | TAO_PEGTL_TEST_ASSERT( e.size() == 2 ); 37 | } 38 | } 39 | 40 | void unit_test() 41 | { 42 | verify_seqs< try_catch_raise_nested >(); 43 | verify_seqs< try_catch_any_raise_nested >(); 44 | 45 | verify_nested< test_try_catch_rule >(); 46 | verify_nested< test_try_catch_any_rule >(); 47 | } 48 | 49 | } // namespace TAO_PEGTL_NAMESPACE 50 | 51 | #include "main.hpp" 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/disable.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_DISABLE_HPP 6 | #define TAO_PEGTL_INTERNAL_DISABLE_HPP 7 | 8 | #include "enable_control.hpp" 9 | #include "seq.hpp" 10 | #include "success.hpp" 11 | 12 | #include "../apply_mode.hpp" 13 | #include "../config.hpp" 14 | #include "../rewind_mode.hpp" 15 | #include "../type_list.hpp" 16 | 17 | namespace TAO_PEGTL_NAMESPACE::internal 18 | { 19 | template< typename... Rules > 20 | struct disable 21 | : disable< seq< Rules... > > 22 | {}; 23 | 24 | template<> 25 | struct disable<> 26 | : success 27 | {}; 28 | 29 | template< typename Rule > 30 | struct disable< Rule > 31 | { 32 | using rule_t = disable; 33 | using subs_t = type_list< Rule >; 34 | 35 | template< apply_mode, 36 | rewind_mode M, 37 | template< typename... > 38 | class Action, 39 | template< typename... > 40 | class Control, 41 | typename ParseInput, 42 | typename... States > 43 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 44 | { 45 | return Control< Rule >::template match< apply_mode::nothing, M, Action, Control >( in, st... ); 46 | } 47 | }; 48 | 49 | template< typename... Rules > 50 | inline constexpr bool enable_control< disable< Rules... > > = false; 51 | 52 | } // namespace TAO_PEGTL_NAMESPACE::internal 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/example/pegtl/json_trace.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "json_errors.hpp" 13 | 14 | namespace pegtl = TAO_PEGTL_NAMESPACE; 15 | 16 | namespace example 17 | { 18 | using grammar = pegtl::seq< pegtl::json::text, pegtl::eof >; 19 | 20 | } // namespace example 21 | 22 | int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) 23 | { 24 | if( argc != 2 ) { 25 | std::cerr << "Usage: " << argv[ 0 ] << " JSON\n" 26 | << "Trace parsing a JSON text.\n\n" 27 | << "Example: " << argv[ 0 ] << " '{\"foo\":[42,null]}'" << std::endl; 28 | return 1; 29 | } 30 | 31 | pegtl::argv_input in( argv, 1 ); 32 | #if defined( __cpp_exceptions ) 33 | try { 34 | pegtl::standard_trace< example::grammar, pegtl::nothing, example::control >( in ); 35 | } 36 | catch( const pegtl::parse_error& e ) { 37 | const auto& p = e.position_object(); 38 | std::cerr << e.what() << '\n' 39 | << in.line_at( p ) << '\n' 40 | << std::setw( int( p.column ) ) << '^' << std::endl; 41 | return 1; 42 | } 43 | #else 44 | if( !pegtl::standard_trace< example::grammar, pegtl::nothing, example::control >( in ) ) { 45 | std::cerr << "error occurred" << std::endl; 46 | return 1; 47 | } 48 | #endif 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /src/test/pegtl/action_enable.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include "test.hpp" 6 | 7 | namespace TAO_PEGTL_NAMESPACE 8 | { 9 | // clang-format off 10 | struct A : one< 'a' > {}; 11 | struct B : one< 'b' > {}; 12 | struct C : one< 'c' > {}; 13 | struct BCB : seq< B, C, B > {}; 14 | struct ABCBA : seq< A, BCB, A > {}; 15 | // clang-format on 16 | 17 | template< typename > 18 | struct my_action 19 | {}; 20 | 21 | template<> 22 | struct my_action< A > 23 | { 24 | static void apply0( int& a, int& /*b*/, int& /*c*/ ) 25 | { 26 | ++a; 27 | } 28 | }; 29 | 30 | template<> 31 | struct my_action< B > 32 | : disable_action 33 | { 34 | static void apply0( int& /*a*/, int& b, int& /*c*/ ) 35 | { 36 | ++b; 37 | } 38 | }; 39 | 40 | template<> 41 | struct my_action< C > 42 | : enable_action 43 | { 44 | static void apply0( int& /*a*/, int& /*b*/, int& c ) 45 | { 46 | ++c; 47 | } 48 | }; 49 | 50 | void unit_test() 51 | { 52 | memory_input<> in( "abcba", "" ); 53 | int a = 0; 54 | int b = 0; 55 | int c = 0; 56 | const auto result = parse< ABCBA, my_action >( in, a, b, c ); 57 | TAO_PEGTL_TEST_ASSERT( result ); 58 | TAO_PEGTL_TEST_ASSERT( a == 2 ); 59 | TAO_PEGTL_TEST_ASSERT( b == 0 ); 60 | TAO_PEGTL_TEST_ASSERT( c == 1 ); 61 | } 62 | 63 | } // namespace TAO_PEGTL_NAMESPACE 64 | 65 | #include "main.hpp" 66 | -------------------------------------------------------------------------------- /src/test/pegtl/data/pass1.json: -------------------------------------------------------------------------------- 1 | [ 2 | "JSON Test Pattern pass1", 3 | {"object with 1 member":["array with 1 element"]}, 4 | {}, 5 | [], 6 | -42, 7 | true, 8 | false, 9 | null, 10 | { 11 | "integer": 1234567890, 12 | "real": -9876.543210, 13 | "e": 0.123456789e-12, 14 | "E": 1.234567890E+34, 15 | "": 23456789012E66, 16 | "zero": 0, 17 | "one": 1, 18 | "space": " ", 19 | "quote": "\"", 20 | "backslash": "\\", 21 | "controls": "\b\f\n\r\t", 22 | "slash": "/ & \/", 23 | "alpha": "abcdefghijklmnopqrstuvwyz", 24 | "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", 25 | "digit": "0123456789", 26 | "0123456789": "digit", 27 | "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", 28 | "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", 29 | "true": true, 30 | "false": false, 31 | "null": null, 32 | "array":[ ], 33 | "object":{ }, 34 | "address": "50 St. James Street", 35 | "url": "http://www.JSON.org/", 36 | "comment": "// /* */": " ", 38 | " s p a c e d " :[1,2 , 3 39 | 40 | , 41 | 42 | 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], 43 | "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", 44 | "quotes": "" \u0022 %22 0x22 034 "", 45 | "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" 46 | : "A key can be any string" 47 | }, 48 | 0.5 ,98.6 49 | , 50 | 99.44 51 | , 52 | 53 | 1066, 54 | 1e1, 55 | 0.1e1, 56 | 1e-1, 57 | 1e00,2e+00,2e-00 58 | ,"rosebud"] -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/internal/set_stack_guard.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_INTERNAL_SET_STACK_GUARD_HPP 6 | #define TAO_PEGTL_CONTRIB_INTERNAL_SET_STACK_GUARD_HPP 7 | 8 | #include 9 | #include 10 | 11 | namespace TAO_PEGTL_NAMESPACE::internal 12 | { 13 | template< typename... Cs > 14 | class [[nodiscard]] set_stack_guard 15 | { 16 | public: 17 | template< typename... Ts > 18 | set_stack_guard( std::set< Cs... >& set, Ts&&... ts ) 19 | : m_i( set.emplace( std::forward< Ts >( ts )... ) ), 20 | m_s( set ) 21 | {} 22 | 23 | set_stack_guard( set_stack_guard&& ) = delete; 24 | set_stack_guard( const set_stack_guard& ) = delete; 25 | 26 | set_stack_guard& operator=( set_stack_guard&& ) = delete; 27 | set_stack_guard& operator=( const set_stack_guard& ) = delete; 28 | 29 | ~set_stack_guard() 30 | { 31 | if( m_i.second ) { 32 | m_s.erase( m_i.first ); 33 | } 34 | } 35 | 36 | [[nodiscard]] explicit operator bool() const noexcept 37 | { 38 | return m_i.second; 39 | } 40 | 41 | private: 42 | const std::pair< typename std::set< Cs... >::iterator, bool > m_i; 43 | std::set< Cs... >& m_s; 44 | }; 45 | 46 | template< typename... Cs > 47 | set_stack_guard( std::set< Cs... >&, const typename std::set< Cs... >::value_type& ) -> set_stack_guard< Cs... >; 48 | 49 | } // namespace TAO_PEGTL_NAMESPACE::internal 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/tao/pegtl/contrib/function.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_CONTRIB_FUNCTION_HPP 6 | #define TAO_PEGTL_CONTRIB_FUNCTION_HPP 7 | 8 | #include "../apply_mode.hpp" 9 | #include "../config.hpp" 10 | #include "../rewind_mode.hpp" 11 | #include "../type_list.hpp" 12 | 13 | #include "../internal/enable_control.hpp" 14 | 15 | namespace TAO_PEGTL_NAMESPACE 16 | { 17 | namespace internal 18 | { 19 | template< typename F, F U > 20 | struct function; 21 | 22 | template< typename ParseInput, typename... States, bool ( *U )( ParseInput&, States... ) > 23 | struct function< bool ( * )( ParseInput&, States... ), U > 24 | { 25 | using rule_t = function; 26 | using subs_t = empty_list; 27 | 28 | template< apply_mode A, 29 | rewind_mode M, 30 | template< typename... > 31 | class Action, 32 | template< typename... > 33 | class Control > 34 | [[nodiscard]] static bool match( ParseInput& in, States... st ) noexcept( noexcept( U( in, st... ) ) ) 35 | { 36 | return U( in, st... ); 37 | } 38 | }; 39 | 40 | template< typename F, F U > 41 | inline constexpr bool enable_control< function< F, U > > = false; 42 | 43 | } // namespace internal 44 | 45 | template< auto F > 46 | struct function 47 | : internal::function< decltype( F ), F > 48 | {}; 49 | 50 | } // namespace TAO_PEGTL_NAMESPACE 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/test/pegtl/contrib_limit_depth.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | #include 7 | 8 | #include "test.hpp" 9 | 10 | namespace TAO_PEGTL_NAMESPACE 11 | { 12 | struct test_recursive 13 | : seq< alpha, opt< test_recursive > > 14 | {}; 15 | 16 | struct test_grammar 17 | : seq< test_recursive, eof > 18 | {}; 19 | 20 | template< typename Rule > 21 | struct test_action 22 | : nothing< Rule > 23 | {}; 24 | 25 | template<> 26 | struct test_action< test_recursive > 27 | : limit_depth< 5 > 28 | {}; 29 | 30 | void unit_test() 31 | { 32 | using memory_input_with_depth = input_with_depth< memory_input<> >; 33 | 34 | memory_input_with_depth i1( "aaa", __FUNCTION__ ); 35 | const auto r1 = parse< test_grammar >( i1 ); 36 | TAO_PEGTL_TEST_ASSERT( r1 ); 37 | 38 | memory_input_with_depth i2( "aaaaaaaaaaa", __FUNCTION__ ); 39 | const auto r2 = parse< test_grammar >( i2 ); 40 | TAO_PEGTL_TEST_ASSERT( r2 ); 41 | 42 | memory_input_with_depth i3( "aaa", __FUNCTION__ ); 43 | const auto r3 = parse< test_grammar, test_action >( i3 ); 44 | TAO_PEGTL_TEST_ASSERT( r3 ); 45 | 46 | #if defined( __cpp_exceptions ) 47 | memory_input_with_depth i4( "aaaaaaaaaaa", __FUNCTION__ ); 48 | TAO_PEGTL_TEST_THROWS( parse< test_grammar, test_action >( i4 ) ); 49 | #endif 50 | } 51 | 52 | } // namespace TAO_PEGTL_NAMESPACE 53 | 54 | #include "main.hpp" 55 | -------------------------------------------------------------------------------- /include/tao/pegtl/internal/at.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #ifndef TAO_PEGTL_INTERNAL_AT_HPP 6 | #define TAO_PEGTL_INTERNAL_AT_HPP 7 | 8 | #include "enable_control.hpp" 9 | #include "seq.hpp" 10 | #include "success.hpp" 11 | 12 | #include "../apply_mode.hpp" 13 | #include "../config.hpp" 14 | #include "../rewind_mode.hpp" 15 | #include "../type_list.hpp" 16 | 17 | namespace TAO_PEGTL_NAMESPACE::internal 18 | { 19 | template< typename... Rules > 20 | struct at 21 | : at< seq< Rules... > > 22 | {}; 23 | 24 | template<> 25 | struct at<> 26 | : success 27 | {}; 28 | 29 | template< typename Rule > 30 | struct at< Rule > 31 | { 32 | using rule_t = at; 33 | using subs_t = type_list< Rule >; 34 | 35 | template< apply_mode, 36 | rewind_mode, 37 | template< typename... > 38 | class Action, 39 | template< typename... > 40 | class Control, 41 | typename ParseInput, 42 | typename... States > 43 | [[nodiscard]] static bool match( ParseInput& in, States&&... st ) 44 | { 45 | const auto m = in.template auto_rewind< rewind_mode::required >(); 46 | return Control< Rule >::template match< apply_mode::nothing, rewind_mode::optional, Action, Control >( in, st... ); 47 | } 48 | }; 49 | 50 | template< typename... Rules > 51 | inline constexpr bool enable_control< at< Rules... > > = false; 52 | 53 | } // namespace TAO_PEGTL_NAMESPACE::internal 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/example/pegtl/json_coverage.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "json_errors.hpp" 14 | 15 | namespace pegtl = TAO_PEGTL_NAMESPACE; 16 | 17 | namespace example 18 | { 19 | using grammar = pegtl::seq< pegtl::json::text, pegtl::eof >; 20 | 21 | } // namespace example 22 | 23 | int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) 24 | { 25 | if( argc != 2 ) { 26 | std::cerr << "Usage: " << argv[ 0 ] << " FILE\n" 27 | << "Print coverage of parsing FILE as JSON." << std::endl; 28 | return 1; 29 | } 30 | 31 | pegtl::file_input in( argv[ 1 ] ); 32 | pegtl::coverage_result result; 33 | #if defined( __cpp_exceptions ) 34 | try { 35 | pegtl::coverage< example::grammar, pegtl::nothing, example::control >( in, result ); 36 | } 37 | catch( const pegtl::parse_error& e ) { 38 | const auto& p = e.position_object(); 39 | std::cerr << e.what() << '\n' 40 | << in.line_at( p ) << '\n' 41 | << std::setw( int( p.column ) ) << '^' << std::endl; 42 | return 1; 43 | } 44 | #else 45 | if( !pegtl::coverage< example::grammar, pegtl::nothing, example::control >( in, result ) ) { 46 | std::cerr << "error occurred" << std::endl; 47 | return 1; 48 | } 49 | #endif 50 | 51 | std::cout << result; 52 | return 0; 53 | } 54 | --------------------------------------------------------------------------------