From e1e77d5013227a63244be289e6af43f91a6b0d3f Mon Sep 17 00:00:00 2001 From: gitamohr Date: Mon, 15 Apr 2024 15:27:49 -0700 Subject: [PATCH] Upgrade PEGTL to latest version 3.2.7. In upcoming version 4+, they have removed support for the amalgamated header. In anticipation of this, we add a new pxr/base/pegtl library rather than embedding it in pxr/base/tf. (Internal change: 2324194) --- LICENSE.txt | 4 +- pxr/base/CMakeLists.txt | 1 + pxr/base/pegtl/CMakeLists.txt | 206 + pxr/base/pegtl/README.md | 47 + pxr/base/pegtl/build-workaround.cpp | 8 + pxr/base/pegtl/pegtl.hpp | 48 + pxr/base/pegtl/pegtl/apply_mode.hpp | 19 + pxr/base/pegtl/pegtl/argv_input.hpp | 49 + pxr/base/pegtl/pegtl/ascii.hpp | 54 + pxr/base/pegtl/pegtl/buffer_input.hpp | 226 + pxr/base/pegtl/pegtl/change_action.hpp | 38 + .../pegtl/pegtl/change_action_and_state.hpp | 71 + .../pegtl/pegtl/change_action_and_states.hpp | 62 + pxr/base/pegtl/pegtl/change_control.hpp | 36 + pxr/base/pegtl/pegtl/change_state.hpp | 69 + pxr/base/pegtl/pegtl/change_states.hpp | 61 + pxr/base/pegtl/pegtl/config.hpp | 17 + pxr/base/pegtl/pegtl/contrib/abnf.hpp | 35 + pxr/base/pegtl/pegtl/contrib/add_state.hpp | 69 + pxr/base/pegtl/pegtl/contrib/alphabet.hpp | 67 + pxr/base/pegtl/pegtl/contrib/analyze.hpp | 189 + .../pegtl/pegtl/contrib/analyze_traits.hpp | 277 + pxr/base/pegtl/pegtl/contrib/check_bytes.hpp | 55 + .../pegtl/pegtl/contrib/control_action.hpp | 93 + pxr/base/pegtl/pegtl/contrib/coverage.hpp | 151 + pxr/base/pegtl/pegtl/contrib/forward.hpp | 16 + pxr/base/pegtl/pegtl/contrib/function.hpp | 52 + pxr/base/pegtl/pegtl/contrib/http.hpp | 277 + pxr/base/pegtl/pegtl/contrib/icu/internal.hpp | 98 + pxr/base/pegtl/pegtl/contrib/icu/utf16.hpp | 196 + pxr/base/pegtl/pegtl/contrib/icu/utf32.hpp | 196 + pxr/base/pegtl/pegtl/contrib/icu/utf8.hpp | 103 + pxr/base/pegtl/pegtl/contrib/if_then.hpp | 56 + pxr/base/pegtl/pegtl/contrib/instantiate.hpp | 38 + pxr/base/pegtl/pegtl/contrib/integer.hpp | 468 + .../pegtl/pegtl/contrib/internal/endian.hpp | 77 + .../pegtl/contrib/internal/endian_gcc.hpp | 198 + .../pegtl/contrib/internal/endian_win.hpp | 102 + .../pegtl/contrib/internal/peek_mask_uint.hpp | 54 + .../contrib/internal/peek_mask_uint8.hpp | 33 + .../pegtl/contrib/internal/peek_uint.hpp | 45 + .../pegtl/contrib/internal/peek_uint8.hpp | 32 + .../pegtl/contrib/internal/peek_utf16.hpp | 54 + .../pegtl/contrib/internal/peek_utf32.hpp | 43 + .../pegtl/contrib/internal/read_uint.hpp | 77 + .../contrib/internal/set_stack_guard.hpp | 52 + .../contrib/internal/vector_stack_guard.hpp | 45 + pxr/base/pegtl/pegtl/contrib/iri.hpp | 106 + pxr/base/pegtl/pegtl/contrib/json.hpp | 91 + pxr/base/pegtl/pegtl/contrib/json_pointer.hpp | 33 + pxr/base/pegtl/pegtl/contrib/limit_bytes.hpp | 88 + pxr/base/pegtl/pegtl/contrib/limit_depth.hpp | 83 + pxr/base/pegtl/pegtl/contrib/parse_tree.hpp | 456 + .../pegtl/pegtl/contrib/parse_tree_to_dot.hpp | 111 + pxr/base/pegtl/pegtl/contrib/peg.hpp | 121 + pxr/base/pegtl/pegtl/contrib/predicates.hpp | 126 + pxr/base/pegtl/pegtl/contrib/print.hpp | 75 + .../pegtl/pegtl/contrib/print_coverage.hpp | 53 + pxr/base/pegtl/pegtl/contrib/proto3.hpp | 142 + pxr/base/pegtl/pegtl/contrib/raw_string.hpp | 232 + .../pegtl/contrib/remove_first_state.hpp | 72 + .../pegtl/contrib/remove_last_states.hpp | 121 + .../pegtl/pegtl/contrib/rep_one_min_max.hpp | 100 + pxr/base/pegtl/pegtl/contrib/rep_string.hpp | 43 + .../pegtl/pegtl/contrib/separated_seq.hpp | 45 + .../pegtl/pegtl/contrib/shuffle_states.hpp | 193 + .../pegtl/pegtl/contrib/state_control.hpp | 122 + pxr/base/pegtl/pegtl/contrib/to_string.hpp | 38 + pxr/base/pegtl/pegtl/contrib/trace.hpp | 227 + pxr/base/pegtl/pegtl/contrib/uint16.hpp | 62 + pxr/base/pegtl/pegtl/contrib/uint32.hpp | 62 + pxr/base/pegtl/pegtl/contrib/uint64.hpp | 63 + pxr/base/pegtl/pegtl/contrib/uint8.hpp | 36 + pxr/base/pegtl/pegtl/contrib/unescape.hpp | 214 + pxr/base/pegtl/pegtl/contrib/uri.hpp | 111 + pxr/base/pegtl/pegtl/contrib/utf16.hpp | 57 + pxr/base/pegtl/pegtl/contrib/utf32.hpp | 57 + pxr/base/pegtl/pegtl/cstream_input.hpp | 32 + pxr/base/pegtl/pegtl/demangle.hpp | 182 + pxr/base/pegtl/pegtl/disable_action.hpp | 35 + pxr/base/pegtl/pegtl/discard_input.hpp | 37 + .../pegtl/pegtl/discard_input_on_failure.hpp | 39 + .../pegtl/pegtl/discard_input_on_success.hpp | 39 + pxr/base/pegtl/pegtl/enable_action.hpp | 35 + pxr/base/pegtl/pegtl/eol.hpp | 37 + pxr/base/pegtl/pegtl/eol_pair.hpp | 18 + pxr/base/pegtl/pegtl/file_input.hpp | 44 + pxr/base/pegtl/pegtl/internal/action.hpp | 54 + .../pegtl/pegtl/internal/action_input.hpp | 106 + pxr/base/pegtl/pegtl/internal/any.hpp | 77 + pxr/base/pegtl/pegtl/internal/apply.hpp | 53 + pxr/base/pegtl/pegtl/internal/apply0.hpp | 51 + .../pegtl/pegtl/internal/apply0_single.hpp | 34 + .../pegtl/pegtl/internal/apply_single.hpp | 34 + pxr/base/pegtl/pegtl/internal/at.hpp | 55 + pxr/base/pegtl/pegtl/internal/bof.hpp | 32 + pxr/base/pegtl/pegtl/internal/bol.hpp | 31 + pxr/base/pegtl/pegtl/internal/bump.hpp | 45 + pxr/base/pegtl/pegtl/internal/bump_help.hpp | 26 + pxr/base/pegtl/pegtl/internal/bytes.hpp | 43 + pxr/base/pegtl/pegtl/internal/control.hpp | 54 + pxr/base/pegtl/pegtl/internal/cr_crlf_eol.hpp | 32 + pxr/base/pegtl/pegtl/internal/cr_eol.hpp | 32 + pxr/base/pegtl/pegtl/internal/crlf_eol.hpp | 32 + .../pegtl/pegtl/internal/cstream_reader.hpp | 58 + .../pegtl/pegtl/internal/cstring_reader.hpp | 40 + .../pegtl/pegtl/internal/dependent_false.hpp | 16 + pxr/base/pegtl/pegtl/internal/disable.hpp | 54 + pxr/base/pegtl/pegtl/internal/discard.hpp | 34 + pxr/base/pegtl/pegtl/internal/enable.hpp | 54 + .../pegtl/pegtl/internal/enable_control.hpp | 25 + pxr/base/pegtl/pegtl/internal/eof.hpp | 32 + pxr/base/pegtl/pegtl/internal/eol.hpp | 32 + pxr/base/pegtl/pegtl/internal/eolf.hpp | 33 + pxr/base/pegtl/pegtl/internal/failure.hpp | 32 + .../pegtl/internal/file_mapper_posix.hpp | 159 + .../pegtl/internal/file_mapper_win32.hpp | 243 + pxr/base/pegtl/pegtl/internal/file_reader.hpp | 152 + pxr/base/pegtl/pegtl/internal/filesystem.hpp | 64 + pxr/base/pegtl/pegtl/internal/has_apply.hpp | 21 + pxr/base/pegtl/pegtl/internal/has_apply0.hpp | 21 + pxr/base/pegtl/pegtl/internal/has_match.hpp | 40 + pxr/base/pegtl/pegtl/internal/has_unwind.hpp | 21 + pxr/base/pegtl/pegtl/internal/identifier.hpp | 22 + pxr/base/pegtl/pegtl/internal/if_apply.hpp | 54 + pxr/base/pegtl/pegtl/internal/if_must.hpp | 52 + .../pegtl/pegtl/internal/if_must_else.hpp | 26 + .../pegtl/pegtl/internal/if_then_else.hpp | 51 + pxr/base/pegtl/pegtl/internal/input_pair.hpp | 29 + .../pegtl/pegtl/internal/istream_reader.hpp | 50 + pxr/base/pegtl/pegtl/internal/istring.hpp | 81 + pxr/base/pegtl/pegtl/internal/iterator.hpp | 49 + pxr/base/pegtl/pegtl/internal/lf_crlf_eol.hpp | 37 + pxr/base/pegtl/pegtl/internal/lf_eol.hpp | 32 + pxr/base/pegtl/pegtl/internal/list.hpp | 19 + pxr/base/pegtl/pegtl/internal/list_must.hpp | 25 + pxr/base/pegtl/pegtl/internal/list_tail.hpp | 22 + .../pegtl/pegtl/internal/list_tail_pad.hpp | 22 + pxr/base/pegtl/pegtl/internal/marker.hpp | 80 + pxr/base/pegtl/pegtl/internal/minus.hpp | 21 + .../pegtl/pegtl/internal/missing_apply.hpp | 28 + .../pegtl/pegtl/internal/missing_apply0.hpp | 26 + pxr/base/pegtl/pegtl/internal/must.hpp | 69 + pxr/base/pegtl/pegtl/internal/not_at.hpp | 55 + pxr/base/pegtl/pegtl/internal/one.hpp | 66 + pxr/base/pegtl/pegtl/internal/opt.hpp | 57 + pxr/base/pegtl/pegtl/internal/pad.hpp | 19 + pxr/base/pegtl/pegtl/internal/pad_opt.hpp | 20 + .../pegtl/pegtl/internal/path_to_string.hpp | 28 + pxr/base/pegtl/pegtl/internal/peek_char.hpp | 32 + pxr/base/pegtl/pegtl/internal/peek_utf8.hpp | 89 + .../pegtl/pegtl/internal/pegtl_string.hpp | 90 + pxr/base/pegtl/pegtl/internal/plus.hpp | 60 + pxr/base/pegtl/pegtl/internal/raise.hpp | 49 + pxr/base/pegtl/pegtl/internal/range.hpp | 60 + pxr/base/pegtl/pegtl/internal/ranges.hpp | 90 + pxr/base/pegtl/pegtl/internal/rematch.hpp | 72 + pxr/base/pegtl/pegtl/internal/rep.hpp | 67 + pxr/base/pegtl/pegtl/internal/rep_min.hpp | 20 + pxr/base/pegtl/pegtl/internal/rep_min_max.hpp | 81 + pxr/base/pegtl/pegtl/internal/rep_opt.hpp | 61 + pxr/base/pegtl/pegtl/internal/require.hpp | 42 + .../pegtl/pegtl/internal/result_on_found.hpp | 19 + pxr/base/pegtl/pegtl/internal/rules.hpp | 64 + pxr/base/pegtl/pegtl/internal/seq.hpp | 58 + pxr/base/pegtl/pegtl/internal/sor.hpp | 67 + pxr/base/pegtl/pegtl/internal/star.hpp | 52 + pxr/base/pegtl/pegtl/internal/star_must.hpp | 24 + pxr/base/pegtl/pegtl/internal/state.hpp | 75 + pxr/base/pegtl/pegtl/internal/string.hpp | 67 + pxr/base/pegtl/pegtl/internal/success.hpp | 32 + .../pegtl/pegtl/internal/try_catch_type.hpp | 69 + pxr/base/pegtl/pegtl/internal/until.hpp | 88 + .../pegtl/pegtl/internal/unwind_guard.hpp | 39 + pxr/base/pegtl/pegtl/istream_input.hpp | 32 + pxr/base/pegtl/pegtl/match.hpp | 173 + pxr/base/pegtl/pegtl/memory_input.hpp | 378 + pxr/base/pegtl/pegtl/mmap_input.hpp | 79 + pxr/base/pegtl/pegtl/must_if.hpp | 69 + pxr/base/pegtl/pegtl/normal.hpp | 99 + pxr/base/pegtl/pegtl/nothing.hpp | 19 + pxr/base/pegtl/pegtl/parse.hpp | 72 + pxr/base/pegtl/pegtl/parse_error.hpp | 119 + pxr/base/pegtl/pegtl/position.hpp | 98 + pxr/base/pegtl/pegtl/read_input.hpp | 54 + pxr/base/pegtl/pegtl/require_apply.hpp | 16 + pxr/base/pegtl/pegtl/require_apply0.hpp | 16 + pxr/base/pegtl/pegtl/rewind_mode.hpp | 20 + pxr/base/pegtl/pegtl/rules.hpp | 71 + pxr/base/pegtl/pegtl/string_input.hpp | 64 + pxr/base/pegtl/pegtl/tracking_mode.hpp | 19 + pxr/base/pegtl/pegtl/type_list.hpp | 46 + pxr/base/pegtl/pegtl/utf8.hpp | 28 + pxr/base/pegtl/pegtl/version.hpp | 13 + pxr/base/pegtl/pegtl/visit.hpp | 80 + pxr/base/tf/CMakeLists.txt | 1 - pxr/base/tf/pxrPEGTL/README.md | 20 - pxr/base/tf/pxrPEGTL/pegtl.h | 12483 ---------------- pxr/base/tf/pxrPEGTL/pxr-pegtl.patch | 36 - pxr/usd/sdf/CMakeLists.txt | 1 + pxr/usd/sdf/moduleDeps.cpp | 1 + pxr/usd/sdf/pathExpression.cpp | 4 +- pxr/usd/sdf/pathParser.cpp | 2 +- pxr/usd/sdf/pathParser.h | 14 +- pxr/usd/sdf/predicateExpression.cpp | 5 +- pxr/usd/sdf/predicateExpressionParser.h | 13 +- pxr/usd/sdf/variableExpressionParser.cpp | 36 +- 207 files changed, 14128 insertions(+), 12584 deletions(-) create mode 100644 pxr/base/pegtl/CMakeLists.txt create mode 100644 pxr/base/pegtl/README.md create mode 100644 pxr/base/pegtl/build-workaround.cpp create mode 100644 pxr/base/pegtl/pegtl.hpp create mode 100644 pxr/base/pegtl/pegtl/apply_mode.hpp create mode 100644 pxr/base/pegtl/pegtl/argv_input.hpp create mode 100644 pxr/base/pegtl/pegtl/ascii.hpp create mode 100644 pxr/base/pegtl/pegtl/buffer_input.hpp create mode 100644 pxr/base/pegtl/pegtl/change_action.hpp create mode 100644 pxr/base/pegtl/pegtl/change_action_and_state.hpp create mode 100644 pxr/base/pegtl/pegtl/change_action_and_states.hpp create mode 100644 pxr/base/pegtl/pegtl/change_control.hpp create mode 100644 pxr/base/pegtl/pegtl/change_state.hpp create mode 100644 pxr/base/pegtl/pegtl/change_states.hpp create mode 100644 pxr/base/pegtl/pegtl/config.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/abnf.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/add_state.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/alphabet.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/analyze.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/analyze_traits.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/check_bytes.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/control_action.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/coverage.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/forward.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/function.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/http.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/icu/internal.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/icu/utf16.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/icu/utf32.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/icu/utf8.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/if_then.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/instantiate.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/integer.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/endian.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/endian_gcc.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/endian_win.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/peek_mask_uint.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/peek_mask_uint8.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/peek_uint.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/peek_uint8.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/peek_utf16.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/peek_utf32.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/read_uint.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/set_stack_guard.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/internal/vector_stack_guard.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/iri.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/json.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/json_pointer.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/limit_bytes.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/limit_depth.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/parse_tree.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/parse_tree_to_dot.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/peg.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/predicates.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/print.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/print_coverage.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/proto3.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/raw_string.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/remove_first_state.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/remove_last_states.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/rep_one_min_max.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/rep_string.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/separated_seq.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/shuffle_states.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/state_control.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/to_string.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/trace.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/uint16.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/uint32.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/uint64.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/uint8.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/unescape.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/uri.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/utf16.hpp create mode 100644 pxr/base/pegtl/pegtl/contrib/utf32.hpp create mode 100644 pxr/base/pegtl/pegtl/cstream_input.hpp create mode 100644 pxr/base/pegtl/pegtl/demangle.hpp create mode 100644 pxr/base/pegtl/pegtl/disable_action.hpp create mode 100644 pxr/base/pegtl/pegtl/discard_input.hpp create mode 100644 pxr/base/pegtl/pegtl/discard_input_on_failure.hpp create mode 100644 pxr/base/pegtl/pegtl/discard_input_on_success.hpp create mode 100644 pxr/base/pegtl/pegtl/enable_action.hpp create mode 100644 pxr/base/pegtl/pegtl/eol.hpp create mode 100644 pxr/base/pegtl/pegtl/eol_pair.hpp create mode 100644 pxr/base/pegtl/pegtl/file_input.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/action.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/action_input.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/any.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/apply.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/apply0.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/apply0_single.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/apply_single.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/at.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/bof.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/bol.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/bump.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/bump_help.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/bytes.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/control.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/cr_crlf_eol.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/cr_eol.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/crlf_eol.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/cstream_reader.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/cstring_reader.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/dependent_false.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/disable.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/discard.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/enable.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/enable_control.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/eof.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/eol.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/eolf.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/failure.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/file_mapper_posix.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/file_mapper_win32.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/file_reader.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/filesystem.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/has_apply.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/has_apply0.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/has_match.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/has_unwind.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/identifier.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/if_apply.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/if_must.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/if_must_else.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/if_then_else.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/input_pair.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/istream_reader.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/istring.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/iterator.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/lf_crlf_eol.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/lf_eol.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/list.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/list_must.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/list_tail.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/list_tail_pad.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/marker.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/minus.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/missing_apply.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/missing_apply0.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/must.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/not_at.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/one.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/opt.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/pad.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/pad_opt.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/path_to_string.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/peek_char.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/peek_utf8.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/pegtl_string.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/plus.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/raise.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/range.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/ranges.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/rematch.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/rep.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/rep_min.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/rep_min_max.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/rep_opt.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/require.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/result_on_found.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/rules.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/seq.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/sor.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/star.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/star_must.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/state.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/string.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/success.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/try_catch_type.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/until.hpp create mode 100644 pxr/base/pegtl/pegtl/internal/unwind_guard.hpp create mode 100644 pxr/base/pegtl/pegtl/istream_input.hpp create mode 100644 pxr/base/pegtl/pegtl/match.hpp create mode 100644 pxr/base/pegtl/pegtl/memory_input.hpp create mode 100644 pxr/base/pegtl/pegtl/mmap_input.hpp create mode 100644 pxr/base/pegtl/pegtl/must_if.hpp create mode 100644 pxr/base/pegtl/pegtl/normal.hpp create mode 100644 pxr/base/pegtl/pegtl/nothing.hpp create mode 100644 pxr/base/pegtl/pegtl/parse.hpp create mode 100644 pxr/base/pegtl/pegtl/parse_error.hpp create mode 100644 pxr/base/pegtl/pegtl/position.hpp create mode 100644 pxr/base/pegtl/pegtl/read_input.hpp create mode 100644 pxr/base/pegtl/pegtl/require_apply.hpp create mode 100644 pxr/base/pegtl/pegtl/require_apply0.hpp create mode 100644 pxr/base/pegtl/pegtl/rewind_mode.hpp create mode 100644 pxr/base/pegtl/pegtl/rules.hpp create mode 100644 pxr/base/pegtl/pegtl/string_input.hpp create mode 100644 pxr/base/pegtl/pegtl/tracking_mode.hpp create mode 100644 pxr/base/pegtl/pegtl/type_list.hpp create mode 100644 pxr/base/pegtl/pegtl/utf8.hpp create mode 100644 pxr/base/pegtl/pegtl/version.hpp create mode 100644 pxr/base/pegtl/pegtl/visit.hpp delete mode 100644 pxr/base/tf/pxrPEGTL/README.md delete mode 100644 pxr/base/tf/pxrPEGTL/pegtl.h delete mode 100644 pxr/base/tf/pxrPEGTL/pxr-pegtl.patch diff --git a/LICENSE.txt b/LICENSE.txt index 2341d8e8bc..a7b53ac0f4 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -679,7 +679,7 @@ The Art of C++ : PEGTL (Parsing Expression Grammar Template Library) The MIT License (MIT) -Copyright (c) 2007-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2007-2022 Dr. Colin Hirsch and Daniel Frey Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -748,4 +748,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/pxr/base/CMakeLists.txt b/pxr/base/CMakeLists.txt index 1f0303f6f4..f5c8318ae0 100644 --- a/pxr/base/CMakeLists.txt +++ b/pxr/base/CMakeLists.txt @@ -2,6 +2,7 @@ set(DIRS arch tf gf + pegtl js trace work diff --git a/pxr/base/pegtl/CMakeLists.txt b/pxr/base/pegtl/CMakeLists.txt new file mode 100644 index 0000000000..649d3d26ca --- /dev/null +++ b/pxr/base/pegtl/CMakeLists.txt @@ -0,0 +1,206 @@ +set(PXR_PREFIX pxr/base) +set(PXR_PACKAGE pegtl) + +pxr_library(pegtl + # Workaround lack of build support for header-only libs. + LIBRARIES + arch + + PUBLIC_HEADERS + pegtl.hpp + pegtl/apply_mode.hpp + pegtl/argv_input.hpp + pegtl/ascii.hpp + pegtl/buffer_input.hpp + pegtl/change_action.hpp + pegtl/change_action_and_state.hpp + pegtl/change_action_and_states.hpp + pegtl/change_control.hpp + pegtl/change_state.hpp + pegtl/change_states.hpp + pegtl/config.hpp + pegtl/contrib/abnf.hpp + pegtl/contrib/add_state.hpp + pegtl/contrib/alphabet.hpp + pegtl/contrib/analyze.hpp + pegtl/contrib/analyze_traits.hpp + pegtl/contrib/check_bytes.hpp + pegtl/contrib/control_action.hpp + pegtl/contrib/coverage.hpp + pegtl/contrib/forward.hpp + pegtl/contrib/function.hpp + pegtl/contrib/http.hpp + pegtl/contrib/icu/internal.hpp + pegtl/contrib/icu/utf16.hpp + pegtl/contrib/icu/utf32.hpp + pegtl/contrib/icu/utf8.hpp + pegtl/contrib/if_then.hpp + pegtl/contrib/instantiate.hpp + pegtl/contrib/integer.hpp + pegtl/contrib/internal/endian.hpp + pegtl/contrib/internal/endian_gcc.hpp + pegtl/contrib/internal/endian_win.hpp + pegtl/contrib/internal/peek_mask_uint.hpp + pegtl/contrib/internal/peek_mask_uint8.hpp + pegtl/contrib/internal/peek_uint.hpp + pegtl/contrib/internal/peek_uint8.hpp + pegtl/contrib/internal/peek_utf16.hpp + pegtl/contrib/internal/peek_utf32.hpp + pegtl/contrib/internal/read_uint.hpp + pegtl/contrib/internal/set_stack_guard.hpp + pegtl/contrib/internal/vector_stack_guard.hpp + pegtl/contrib/iri.hpp + pegtl/contrib/json.hpp + pegtl/contrib/json_pointer.hpp + pegtl/contrib/limit_bytes.hpp + pegtl/contrib/limit_depth.hpp + pegtl/contrib/parse_tree.hpp + pegtl/contrib/parse_tree_to_dot.hpp + pegtl/contrib/peg.hpp + pegtl/contrib/predicates.hpp + pegtl/contrib/print.hpp + pegtl/contrib/print_coverage.hpp + pegtl/contrib/proto3.hpp + pegtl/contrib/raw_string.hpp + pegtl/contrib/remove_first_state.hpp + pegtl/contrib/remove_last_states.hpp + pegtl/contrib/rep_one_min_max.hpp + pegtl/contrib/rep_string.hpp + pegtl/contrib/separated_seq.hpp + pegtl/contrib/shuffle_states.hpp + pegtl/contrib/state_control.hpp + pegtl/contrib/to_string.hpp + pegtl/contrib/trace.hpp + pegtl/contrib/uint16.hpp + pegtl/contrib/uint32.hpp + pegtl/contrib/uint64.hpp + pegtl/contrib/uint8.hpp + pegtl/contrib/unescape.hpp + pegtl/contrib/uri.hpp + pegtl/contrib/utf16.hpp + pegtl/contrib/utf32.hpp + pegtl/cstream_input.hpp + pegtl/demangle.hpp + pegtl/disable_action.hpp + pegtl/discard_input.hpp + pegtl/discard_input_on_failure.hpp + pegtl/discard_input_on_success.hpp + pegtl/enable_action.hpp + pegtl/eol.hpp + pegtl/eol_pair.hpp + pegtl/file_input.hpp + pegtl/internal/action.hpp + pegtl/internal/action_input.hpp + pegtl/internal/any.hpp + pegtl/internal/apply.hpp + pegtl/internal/apply0.hpp + pegtl/internal/apply0_single.hpp + pegtl/internal/apply_single.hpp + pegtl/internal/at.hpp + pegtl/internal/bof.hpp + pegtl/internal/bol.hpp + pegtl/internal/bump.hpp + pegtl/internal/bump_help.hpp + pegtl/internal/bytes.hpp + pegtl/internal/control.hpp + pegtl/internal/cr_crlf_eol.hpp + pegtl/internal/cr_eol.hpp + pegtl/internal/crlf_eol.hpp + pegtl/internal/cstream_reader.hpp + pegtl/internal/cstring_reader.hpp + pegtl/internal/dependent_false.hpp + pegtl/internal/disable.hpp + pegtl/internal/discard.hpp + pegtl/internal/enable.hpp + pegtl/internal/enable_control.hpp + pegtl/internal/eof.hpp + pegtl/internal/eol.hpp + pegtl/internal/eolf.hpp + pegtl/internal/failure.hpp + pegtl/internal/file_mapper_posix.hpp + pegtl/internal/file_mapper_win32.hpp + pegtl/internal/file_reader.hpp + pegtl/internal/filesystem.hpp + pegtl/internal/has_apply.hpp + pegtl/internal/has_apply0.hpp + pegtl/internal/has_match.hpp + pegtl/internal/has_unwind.hpp + pegtl/internal/identifier.hpp + pegtl/internal/if_apply.hpp + pegtl/internal/if_must.hpp + pegtl/internal/if_must_else.hpp + pegtl/internal/if_then_else.hpp + pegtl/internal/input_pair.hpp + pegtl/internal/istream_reader.hpp + pegtl/internal/istring.hpp + pegtl/internal/iterator.hpp + pegtl/internal/lf_crlf_eol.hpp + pegtl/internal/lf_eol.hpp + pegtl/internal/list.hpp + pegtl/internal/list_must.hpp + pegtl/internal/list_tail.hpp + pegtl/internal/list_tail_pad.hpp + pegtl/internal/marker.hpp + pegtl/internal/minus.hpp + pegtl/internal/missing_apply.hpp + pegtl/internal/missing_apply0.hpp + pegtl/internal/must.hpp + pegtl/internal/not_at.hpp + pegtl/internal/one.hpp + pegtl/internal/opt.hpp + pegtl/internal/pad.hpp + pegtl/internal/pad_opt.hpp + pegtl/internal/path_to_string.hpp + pegtl/internal/peek_char.hpp + pegtl/internal/peek_utf8.hpp + pegtl/internal/pegtl_string.hpp + pegtl/internal/plus.hpp + pegtl/internal/raise.hpp + pegtl/internal/range.hpp + pegtl/internal/ranges.hpp + pegtl/internal/rematch.hpp + pegtl/internal/rep.hpp + pegtl/internal/rep_min.hpp + pegtl/internal/rep_min_max.hpp + pegtl/internal/rep_opt.hpp + pegtl/internal/require.hpp + pegtl/internal/result_on_found.hpp + pegtl/internal/rules.hpp + pegtl/internal/seq.hpp + pegtl/internal/sor.hpp + pegtl/internal/star.hpp + pegtl/internal/star_must.hpp + pegtl/internal/state.hpp + pegtl/internal/string.hpp + pegtl/internal/success.hpp + pegtl/internal/try_catch_type.hpp + pegtl/internal/until.hpp + pegtl/internal/unwind_guard.hpp + pegtl/istream_input.hpp + pegtl/match.hpp + pegtl/memory_input.hpp + pegtl/mmap_input.hpp + pegtl/must_if.hpp + pegtl/normal.hpp + pegtl/nothing.hpp + pegtl/parse.hpp + pegtl/parse_error.hpp + pegtl/position.hpp + pegtl/read_input.hpp + pegtl/require_apply.hpp + pegtl/require_apply0.hpp + pegtl/rewind_mode.hpp + pegtl/rules.hpp + pegtl/string_input.hpp + pegtl/tracking_mode.hpp + pegtl/type_list.hpp + pegtl/utf8.hpp + pegtl/version.hpp + pegtl/visit.hpp + + CPPFILES + # Workaround lack of build support for header-only libs. + build-workaround.cpp + + DISABLE_PRECOMPILED_HEADERS +) diff --git a/pxr/base/pegtl/README.md b/pxr/base/pegtl/README.md new file mode 100644 index 0000000000..3a3a74320e --- /dev/null +++ b/pxr/base/pegtl/README.md @@ -0,0 +1,47 @@ +# The Art of C++ : PEGTL (Parsing Expression Grammar Template Library) + +[PEGTL](https://github.com/taocpp/PEGTL) is a library for creating +parsers according to a Parsing Expression Grammar. + +## Version + +v3.2.7 + +## Setup + +Refer to the [Installing and Using](https://github.com/taocpp/PEGTL/blob/3.x/doc/Installing-and-Using.md) +documentation + +## Copy headers + +1. Copy PEGTL-3.2.7/include/tao/... to pxr/base/pegtl/... + +2. Replace Macro Names + +Change macro names from TAO_PEGTL_ to PXR_PEGTL_. You can do this in a +bash-like shell with the following: + +`sed -i 's/TAO_PEGTL_/PXR_PEGTL_/g' $(find -name '[^.]*.[hc]pp')` + +3. Update CMakeLists.txt and any other build configuration files. + +You can get a full list of the header files by running: + +`find -type f` + +4. Update pxr/base/pegtl/pegtl/config.hpp + +This file defines the namespace name that PEGTL uses: + +``` +// Define PXR_PEGTL_NAMESPACE based on the internal namespace to isolate +// it from other versions of USD/PEGTL in client code. +#include "pxr/pxr.h" + +#if PXR_USE_NAMESPACES +#define PXR_PEGTL_NAMESPACE PXR_INTERNAL_NS ## _pegtl +#else +#define PXR_PEGTL_NAMESPACE pxr_pegtl +#endif +``` + diff --git a/pxr/base/pegtl/build-workaround.cpp b/pxr/base/pegtl/build-workaround.cpp new file mode 100644 index 0000000000..87c2758e5e --- /dev/null +++ b/pxr/base/pegtl/build-workaround.cpp @@ -0,0 +1,8 @@ +// This is required since our build does not currently support header-only +// libraries. Without this the headers install okay, but other libs that try to +// use this library will fail to link, like: `ld: cannot find -lpegtl`. By +// adding this, an "empty" .so gets built and other libs can link it. + +#include "pxr/base/arch/export.h" + +ARCH_EXPORT int __pxr_pegtl_workaround__; diff --git a/pxr/base/pegtl/pegtl.hpp b/pxr/base/pegtl/pegtl.hpp new file mode 100644 index 0000000000..94b5a52074 --- /dev/null +++ b/pxr/base/pegtl/pegtl.hpp @@ -0,0 +1,48 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_HPP +#define PXR_PEGTL_HPP + +#include "pegtl/config.hpp" +#include "pegtl/demangle.hpp" +#include "pegtl/parse.hpp" +#include "pegtl/version.hpp" + +#include "pegtl/ascii.hpp" +#include "pegtl/rules.hpp" +#include "pegtl/utf8.hpp" + +#include "pegtl/argv_input.hpp" +#include "pegtl/buffer_input.hpp" +#include "pegtl/cstream_input.hpp" +#include "pegtl/istream_input.hpp" +#include "pegtl/memory_input.hpp" +#include "pegtl/read_input.hpp" +#include "pegtl/string_input.hpp" + +// This has to be included *after* the above inputs, +// otherwise the amalgamated header will not work! +#include "pegtl/file_input.hpp" + +#include "pegtl/change_action.hpp" +#include "pegtl/change_action_and_state.hpp" +#include "pegtl/change_action_and_states.hpp" +#include "pegtl/change_control.hpp" +#include "pegtl/change_state.hpp" +#include "pegtl/change_states.hpp" + +#include "pegtl/disable_action.hpp" +#include "pegtl/enable_action.hpp" + +#include "pegtl/discard_input.hpp" +#include "pegtl/discard_input_on_failure.hpp" +#include "pegtl/discard_input_on_success.hpp" + +#include "pegtl/visit.hpp" + +#if defined( __cpp_exceptions ) +#include "pegtl/must_if.hpp" +#endif + +#endif diff --git a/pxr/base/pegtl/pegtl/apply_mode.hpp b/pxr/base/pegtl/pegtl/apply_mode.hpp new file mode 100644 index 0000000000..4b9f6564cc --- /dev/null +++ b/pxr/base/pegtl/pegtl/apply_mode.hpp @@ -0,0 +1,19 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_APPLY_MODE_HPP +#define PXR_PEGTL_APPLY_MODE_HPP + +#include "config.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + enum class apply_mode : bool + { + action = true, + nothing = false + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/argv_input.hpp b/pxr/base/pegtl/pegtl/argv_input.hpp new file mode 100644 index 0000000000..3fc5e189a5 --- /dev/null +++ b/pxr/base/pegtl/pegtl/argv_input.hpp @@ -0,0 +1,49 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_ARGV_INPUT_HPP +#define PXR_PEGTL_ARGV_INPUT_HPP + +#include +#include +#include +#include + +#include "config.hpp" +#include "eol.hpp" +#include "memory_input.hpp" +#include "tracking_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + [[nodiscard]] inline std::string make_argv_source( const std::size_t argn ) + { + std::ostringstream oss; + oss << "argv[" << argn << ']'; + return std::move( oss ).str(); + } + + } // namespace internal + + template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > + struct argv_input + : memory_input< P, Eol > + { + template< typename T > + argv_input( char** argv, const std::size_t argn, T&& in_source ) + : memory_input< P, Eol >( static_cast< const char* >( argv[ argn ] ), std::forward< T >( in_source ) ) + {} + + argv_input( char** argv, const std::size_t argn ) + : argv_input( argv, argn, internal::make_argv_source( argn ) ) + {} + }; + + template< typename... Ts > + argv_input( Ts&&... ) -> argv_input<>; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/ascii.hpp b/pxr/base/pegtl/pegtl/ascii.hpp new file mode 100644 index 0000000000..5084d8675a --- /dev/null +++ b/pxr/base/pegtl/pegtl/ascii.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_ASCII_HPP +#define PXR_PEGTL_ASCII_HPP + +#include "config.hpp" + +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + inline namespace ascii + { + // clang-format off + struct alnum : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z', '0', '9' > {}; + struct alpha : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z' > {}; + struct any : internal::any< internal::peek_char > {}; + struct blank : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > {}; + struct digit : internal::range< internal::result_on_found::success, internal::peek_char, '0', '9' > {}; + struct ellipsis : internal::string< '.', '.', '.' > {}; + template< char... Cs > struct forty_two : internal::rep< 42, internal::one< internal::result_on_found::success, internal::peek_char, Cs... > > {}; + struct identifier_first : internal::identifier_first {}; + struct identifier_other : internal::identifier_other {}; + struct identifier : internal::identifier {}; + template< char... Cs > struct istring : internal::istring< Cs... > {}; + template< char... Cs > struct keyword : internal::seq< internal::string< Cs... >, internal::not_at< internal::identifier_other > > { static_assert( sizeof...( Cs ) > 0 ); }; + struct lower : internal::range< internal::result_on_found::success, internal::peek_char, 'a', 'z' > {}; + template< char... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_char, Cs... > {}; + template< char Lo, char Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_char, Lo, Hi > {}; + struct nul : internal::one< internal::result_on_found::success, internal::peek_char, char( 0 ) > {}; + struct odigit : internal::range< internal::result_on_found::success, internal::peek_char, '0', '7' > {}; + template< char... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_char, Cs... > {}; + struct print : internal::range< internal::result_on_found::success, internal::peek_char, char( 32 ), char( 126 ) > {}; + template< char Lo, char Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_char, Lo, Hi > {}; + template< char... Cs > struct ranges : internal::ranges< internal::peek_char, Cs... > {}; + struct seven : internal::range< internal::result_on_found::success, internal::peek_char, char( 0 ), char( 127 ) > {}; + struct shebang : internal::seq< internal::string< '#', '!' >, internal::until< internal::eolf > > {}; + struct space : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\n', '\r', '\t', '\v', '\f' > {}; + template< char... Cs > struct string : internal::string< Cs... > {}; + template< char C > struct three : internal::string< C, C, C > {}; + template< char C > struct two : internal::string< C, C > {}; + struct upper : internal::range< internal::result_on_found::success, internal::peek_char, 'A', 'Z' > {}; + struct xdigit : internal::ranges< internal::peek_char, '0', '9', 'a', 'f', 'A', 'F' > {}; + // clang-format on + + } // namespace ascii + +} // namespace PXR_PEGTL_NAMESPACE + +#include "internal/pegtl_string.hpp" + +#endif diff --git a/pxr/base/pegtl/pegtl/buffer_input.hpp b/pxr/base/pegtl/pegtl/buffer_input.hpp new file mode 100644 index 0000000000..f2d980e83a --- /dev/null +++ b/pxr/base/pegtl/pegtl/buffer_input.hpp @@ -0,0 +1,226 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_BUFFER_INPUT_HPP +#define PXR_PEGTL_BUFFER_INPUT_HPP + +#include +#include +#include +#include +#include +#include +#include + +#if defined( __cpp_exceptions ) +#include +#else +#include +#include +#endif + +#include "config.hpp" +#include "eol.hpp" +#include "memory_input.hpp" +#include "position.hpp" +#include "tracking_mode.hpp" + +#include "internal/action_input.hpp" +#include "internal/bump.hpp" +#include "internal/iterator.hpp" +#include "internal/marker.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< typename Reader, typename Eol = eol::lf_crlf, typename Source = std::string, std::size_t Chunk = 64 > + class buffer_input + { + public: + using reader_t = Reader; + + using eol_t = Eol; + using source_t = Source; + + using iterator_t = internal::iterator; + + using action_t = internal::action_input< buffer_input >; + + static constexpr std::size_t chunk_size = Chunk; + static constexpr tracking_mode tracking_mode_v = tracking_mode::eager; + + template< typename T, typename... As > + buffer_input( T&& in_source, const std::size_t maximum, As&&... as ) + : m_reader( std::forward< As >( as )... ), + m_maximum( maximum + Chunk ), + m_buffer( new char[ maximum + Chunk ] ), + m_current( m_buffer.get() ), + m_end( m_buffer.get() ), + m_source( std::forward< T >( in_source ) ) + { + static_assert( Chunk != 0, "zero chunk size not implemented" ); + assert( m_maximum > maximum ); // Catches overflow; change to >= when zero chunk size is implemented. + } + + buffer_input( const buffer_input& ) = delete; + buffer_input( buffer_input&& ) = delete; + + ~buffer_input() = default; + + buffer_input& operator=( const buffer_input& ) = delete; + buffer_input& operator=( buffer_input&& ) = delete; + + [[nodiscard]] bool empty() + { + require( 1 ); + return m_current.data == m_end; + } + + [[nodiscard]] std::size_t size( const std::size_t amount ) + { + require( amount ); + return buffer_occupied(); + } + + [[nodiscard]] const char* current() const noexcept + { + return m_current.data; + } + + [[nodiscard]] const char* end( const std::size_t amount ) + { + require( amount ); + return m_end; + } + + [[nodiscard]] std::size_t byte() const noexcept + { + return m_current.byte; + } + + [[nodiscard]] std::size_t line() const noexcept + { + return m_current.line; + } + + [[nodiscard]] std::size_t column() const noexcept + { + return m_current.column; + } + + [[nodiscard]] const Source& source() const noexcept + { + return m_source; + } + + [[nodiscard]] char peek_char( const std::size_t offset = 0 ) const noexcept + { + return m_current.data[ offset ]; + } + + [[nodiscard]] std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept + { + return static_cast< std::uint8_t >( peek_char( offset ) ); + } + + void bump( const std::size_t in_count = 1 ) noexcept + { + internal::bump( m_current, in_count, Eol::ch ); + } + + void bump_in_this_line( const std::size_t in_count = 1 ) noexcept + { + internal::bump_in_this_line( m_current, in_count ); + } + + void bump_to_next_line( const std::size_t in_count = 1 ) noexcept + { + internal::bump_to_next_line( m_current, in_count ); + } + + void discard() noexcept + { + if( m_current.data > m_buffer.get() + Chunk ) { + const auto s = m_end - m_current.data; + std::memmove( m_buffer.get(), m_current.data, s ); + m_current.data = m_buffer.get(); + m_end = m_buffer.get() + s; + } + } + + void require( const std::size_t amount ) + { + if( m_current.data + amount <= m_end ) { + return; + } + if( m_current.data + amount > m_buffer.get() + m_maximum ) { +#if defined( __cpp_exceptions ) + throw std::overflow_error( "require() beyond end of buffer" ); +#else + std::fputs( "overflow error: require() beyond end of buffer\n", stderr ); + std::terminate(); +#endif + } + if( const auto r = m_reader( m_end, ( std::min )( buffer_free_after_end(), ( std::max )( amount - buffer_occupied(), Chunk ) ) ) ) { + m_end += r; + } + } + + template< rewind_mode M > + [[nodiscard]] internal::marker< iterator_t, M > mark() noexcept + { + return internal::marker< iterator_t, M >( m_current ); + } + + [[nodiscard]] PXR_PEGTL_NAMESPACE::position position( const iterator_t& it ) const + { + return PXR_PEGTL_NAMESPACE::position( it, m_source ); + } + + [[nodiscard]] PXR_PEGTL_NAMESPACE::position position() const + { + return position( m_current ); + } + + [[nodiscard]] const iterator_t& iterator() const noexcept + { + return m_current; + } + + [[nodiscard]] std::size_t buffer_capacity() const noexcept + { + return m_maximum; + } + + [[nodiscard]] std::size_t buffer_occupied() const noexcept + { + assert( m_end >= m_current.data ); + return std::size_t( m_end - m_current.data ); + } + + [[nodiscard]] std::size_t buffer_free_before_current() const noexcept + { + assert( m_current.data >= m_buffer.get() ); + return std::size_t( m_current.data - m_buffer.get() ); + } + + [[nodiscard]] std::size_t buffer_free_after_end() const noexcept + { + assert( m_buffer.get() + m_maximum >= m_end ); + return std::size_t( m_buffer.get() + m_maximum - m_end ); + } + + private: + Reader m_reader; + std::size_t m_maximum; + std::unique_ptr< char[] > m_buffer; + iterator_t m_current; + char* m_end; + const Source m_source; + + public: + std::size_t private_depth = 0; + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/change_action.hpp b/pxr/base/pegtl/pegtl/change_action.hpp new file mode 100644 index 0000000000..f56e5aa8cc --- /dev/null +++ b/pxr/base/pegtl/pegtl/change_action.hpp @@ -0,0 +1,38 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CHANGE_ACTION_HPP +#define PXR_PEGTL_CHANGE_ACTION_HPP + +#include + +#include "apply_mode.hpp" +#include "config.hpp" +#include "nothing.hpp" +#include "rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< template< typename... > class NewAction > + struct change_action + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + static_assert( !std::is_same_v< Action< void >, NewAction< void > >, "old and new action class templates are identical" ); + return Control< Rule >::template match< A, M, NewAction, Control >( in, st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/change_action_and_state.hpp b/pxr/base/pegtl/pegtl/change_action_and_state.hpp new file mode 100644 index 0000000000..6e4037acfc --- /dev/null +++ b/pxr/base/pegtl/pegtl/change_action_and_state.hpp @@ -0,0 +1,71 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CHANGE_ACTION_AND_STATE_HPP +#define PXR_PEGTL_CHANGE_ACTION_AND_STATE_HPP + +#include + +#include "apply_mode.hpp" +#include "config.hpp" +#include "match.hpp" +#include "nothing.hpp" +#include "rewind_mode.hpp" + +#include "internal/dependent_false.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< template< typename... > class NewAction, typename NewState > + struct change_action_and_state + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + static_assert( !std::is_same_v< Action< void >, NewAction< void > >, "old and new action class templates are identical" ); + + if constexpr( std::is_constructible_v< NewState, const ParseInput&, States... > ) { + NewState s( static_cast< const ParseInput& >( in ), st... ); + if( Control< Rule >::template match< A, M, NewAction, Control >( in, s ) ) { + if constexpr( A == apply_mode::action ) { + Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... ); + } + return true; + } + return false; + } + else if constexpr( std::is_default_constructible_v< NewState > ) { + NewState s; + if( Control< Rule >::template match< A, M, NewAction, Control >( in, s ) ) { + if constexpr( A == apply_mode::action ) { + Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... ); + } + return true; + } + return false; + } + else { + static_assert( internal::dependent_false< NewState >, "unable to instantiate new state" ); + } + } + + template< typename ParseInput, + typename... States > + static void success( const ParseInput& in, NewState& s, States&&... st ) noexcept( noexcept( s.success( in, st... ) ) ) + { + s.success( in, st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/change_action_and_states.hpp b/pxr/base/pegtl/pegtl/change_action_and_states.hpp new file mode 100644 index 0000000000..2da0319e0e --- /dev/null +++ b/pxr/base/pegtl/pegtl/change_action_and_states.hpp @@ -0,0 +1,62 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CHANGE_ACTION_AND_STATES_HPP +#define PXR_PEGTL_CHANGE_ACTION_AND_STATES_HPP + +#include +#include + +#include "apply_mode.hpp" +#include "config.hpp" +#include "match.hpp" +#include "nothing.hpp" +#include "rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< template< typename... > class NewAction, typename... NewStates > + struct change_action_and_states + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + std::size_t... Ns, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( std::index_sequence< Ns... > /*unused*/, ParseInput& in, States&&... st ) + { + auto t = std::tie( st... ); + if( Control< Rule >::template match< A, M, NewAction, Control >( in, std::get< Ns >( t )... ) ) { + if constexpr( A == apply_mode::action ) { + Action< Rule >::success( static_cast< const ParseInput& >( in ), st... ); + } + return true; + } + return false; + } + + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + static_assert( !std::is_same_v< Action< void >, NewAction< void > >, "old and new action class templates are identical" ); + return match< Rule, A, M, Action, Control >( std::index_sequence_for< NewStates... >(), in, NewStates()..., st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/change_control.hpp b/pxr/base/pegtl/pegtl/change_control.hpp new file mode 100644 index 0000000000..9657b6dd8a --- /dev/null +++ b/pxr/base/pegtl/pegtl/change_control.hpp @@ -0,0 +1,36 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CHANGE_CONTROL_HPP +#define PXR_PEGTL_CHANGE_CONTROL_HPP + +#include "apply_mode.hpp" +#include "config.hpp" +#include "match.hpp" +#include "nothing.hpp" +#include "rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< template< typename... > class NewControl > + struct change_control + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + return PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, NewControl >( in, st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/change_state.hpp b/pxr/base/pegtl/pegtl/change_state.hpp new file mode 100644 index 0000000000..0941856eab --- /dev/null +++ b/pxr/base/pegtl/pegtl/change_state.hpp @@ -0,0 +1,69 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CHANGE_STATE_HPP +#define PXR_PEGTL_CHANGE_STATE_HPP + +#include + +#include "apply_mode.hpp" +#include "config.hpp" +#include "match.hpp" +#include "nothing.hpp" +#include "rewind_mode.hpp" + +#include "internal/dependent_false.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< typename NewState > + struct change_state + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + if constexpr( std::is_constructible_v< NewState, const ParseInput&, States... > ) { + NewState s( static_cast< const ParseInput& >( in ), st... ); + if( PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s ) ) { + if constexpr( A == apply_mode::action ) { + Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... ); + } + return true; + } + return false; + } + else if constexpr( std::is_default_constructible_v< NewState > ) { + NewState s; + if( PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s ) ) { + if constexpr( A == apply_mode::action ) { + Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... ); + } + return true; + } + return false; + } + else { + static_assert( internal::dependent_false< NewState >, "unable to instantiate new state" ); + } + } + + template< typename ParseInput, + typename... States > + static void success( const ParseInput& in, NewState& s, States&&... st ) noexcept( noexcept( s.success( in, st... ) ) ) + { + s.success( in, st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/change_states.hpp b/pxr/base/pegtl/pegtl/change_states.hpp new file mode 100644 index 0000000000..2b40deb428 --- /dev/null +++ b/pxr/base/pegtl/pegtl/change_states.hpp @@ -0,0 +1,61 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CHANGE_STATES_HPP +#define PXR_PEGTL_CHANGE_STATES_HPP + +#include +#include + +#include "apply_mode.hpp" +#include "config.hpp" +#include "match.hpp" +#include "nothing.hpp" +#include "rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< typename... NewStates > + struct change_states + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + std::size_t... Ns, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( std::index_sequence< Ns... > /*unused*/, ParseInput& in, States&&... st ) + { + auto t = std::tie( st... ); + if( PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, std::get< Ns >( t )... ) ) { + if constexpr( A == apply_mode::action ) { + Action< Rule >::success( static_cast< const ParseInput& >( in ), st... ); + } + return true; + } + return false; + } + + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + return match< Rule, A, M, Action, Control >( std::index_sequence_for< NewStates... >(), in, NewStates()..., st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/config.hpp b/pxr/base/pegtl/pegtl/config.hpp new file mode 100644 index 0000000000..0894f76e34 --- /dev/null +++ b/pxr/base/pegtl/pegtl/config.hpp @@ -0,0 +1,17 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONFIG_HPP +#define PXR_PEGTL_CONFIG_HPP + +// Define PXR_PEGTL_NAMESPACE based on internal namespace to isolate +// it from other versions of USD/PEGTL in client code. +#include "pxr/pxr.h" + +#if PXR_USE_NAMESPACES +#define PXR_PEGTL_NAMESPACE PXR_INTERNAL_NS ## _pegtl +#else +#define PXR_PEGTL_NAMESPACE pxr_pegtl +#endif + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/abnf.hpp b/pxr/base/pegtl/pegtl/contrib/abnf.hpp new file mode 100644 index 0000000000..e42b800f5b --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/abnf.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_ABNF_HPP +#define PXR_PEGTL_CONTRIB_ABNF_HPP + +#include "../config.hpp" +#include "../internal/rules.hpp" + +namespace PXR_PEGTL_NAMESPACE::abnf +{ + // Core ABNF rules according to RFC 5234, Appendix B + + // clang-format off + struct ALPHA : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z' > {}; + struct BIT : internal::one< internal::result_on_found::success, internal::peek_char, '0', '1' > {}; + struct CHAR : internal::range< internal::result_on_found::success, internal::peek_char, char( 1 ), char( 127 ) > {}; + struct CR : internal::one< internal::result_on_found::success, internal::peek_char, '\r' > {}; + struct CRLF : internal::string< '\r', '\n' > {}; + struct CTL : internal::ranges< internal::peek_char, char( 0 ), char( 31 ), char( 127 ) > {}; + struct DIGIT : internal::range< internal::result_on_found::success, internal::peek_char, '0', '9' > {}; + struct DQUOTE : internal::one< internal::result_on_found::success, internal::peek_char, '"' > {}; + struct HEXDIG : internal::ranges< internal::peek_char, '0', '9', 'a', 'f', 'A', 'F' > {}; + struct HTAB : internal::one< internal::result_on_found::success, internal::peek_char, '\t' > {}; + struct LF : internal::one< internal::result_on_found::success, internal::peek_char, '\n' > {}; + struct LWSP : internal::star< internal::sor< internal::string< '\r', '\n' >, internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > >, internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > > {}; + struct OCTET : internal::any< internal::peek_char > {}; + struct SP : internal::one< internal::result_on_found::success, internal::peek_char, ' ' > {}; + struct VCHAR : internal::range< internal::result_on_found::success, internal::peek_char, char( 33 ), char( 126 ) > {}; + struct WSP : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > {}; + // clang-format on + +} // namespace PXR_PEGTL_NAMESPACE::abnf + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/add_state.hpp b/pxr/base/pegtl/pegtl/contrib/add_state.hpp new file mode 100644 index 0000000000..edf18c3f2d --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/add_state.hpp @@ -0,0 +1,69 @@ +// Copyright (c) 2021-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_ADD_STATE_HPP +#define PXR_PEGTL_CONTRIB_ADD_STATE_HPP + +#include + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../match.hpp" +#include "../nothing.hpp" +#include "../rewind_mode.hpp" + +#include "../internal/dependent_false.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< typename AddState > + struct add_state + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + if constexpr( std::is_constructible_v< AddState, const ParseInput&, States... > ) { + AddState s( static_cast< const ParseInput& >( in ), st... ); + if( PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s, st... ) ) { + if constexpr( A == apply_mode::action ) { + Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... ); + } + return true; + } + return false; + } + else if constexpr( std::is_default_constructible_v< AddState > ) { + AddState s; + if( PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s, st... ) ) { + if constexpr( A == apply_mode::action ) { + Action< Rule >::success( static_cast< const ParseInput& >( in ), s, st... ); + } + return true; + } + return false; + } + else { + static_assert( internal::dependent_false< AddState >, "unable to instantiate new state" ); + } + } + + template< typename ParseInput, + typename... States > + static void success( const ParseInput& in, AddState& s, States&&... st ) noexcept( noexcept( s.success( in, st... ) ) ) + { + s.success( in, st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/alphabet.hpp b/pxr/base/pegtl/pegtl/contrib/alphabet.hpp new file mode 100644 index 0000000000..cdb66f1478 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/alphabet.hpp @@ -0,0 +1,67 @@ +// Copyright (c) 2015-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_ALPHABET_HPP +#define PXR_PEGTL_CONTRIB_ALPHABET_HPP + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::alphabet +{ + static const char a = 'a'; + static const char b = 'b'; + static const char c = 'c'; + static const char d = 'd'; + static const char e = 'e'; + static const char f = 'f'; + static const char g = 'g'; + static const char h = 'h'; + static const char i = 'i'; + static const char j = 'j'; + static const char k = 'k'; + static const char l = 'l'; + static const char m = 'm'; + static const char n = 'n'; + static const char o = 'o'; + static const char p = 'p'; + static const char q = 'q'; + static const char r = 'r'; + static const char s = 's'; + static const char t = 't'; + static const char u = 'u'; + static const char v = 'v'; + static const char w = 'w'; + static const char x = 'x'; + static const char y = 'y'; + static const char z = 'z'; + + static const char A = 'A'; // NOLINT(readability-identifier-naming) + static const char B = 'B'; // NOLINT(readability-identifier-naming) + static const char C = 'C'; // NOLINT(readability-identifier-naming) + static const char D = 'D'; // NOLINT(readability-identifier-naming) + static const char E = 'E'; // NOLINT(readability-identifier-naming) + static const char F = 'F'; // NOLINT(readability-identifier-naming) + static const char G = 'G'; // NOLINT(readability-identifier-naming) + static const char H = 'H'; // NOLINT(readability-identifier-naming) + static const char I = 'I'; // NOLINT(readability-identifier-naming) + static const char J = 'J'; // NOLINT(readability-identifier-naming) + static const char K = 'K'; // NOLINT(readability-identifier-naming) + static const char L = 'L'; // NOLINT(readability-identifier-naming) + static const char M = 'M'; // NOLINT(readability-identifier-naming) + static const char N = 'N'; // NOLINT(readability-identifier-naming) + static const char O = 'O'; // NOLINT(readability-identifier-naming) + static const char P = 'P'; // NOLINT(readability-identifier-naming) + static const char Q = 'Q'; // NOLINT(readability-identifier-naming) + static const char R = 'R'; // NOLINT(readability-identifier-naming) + static const char S = 'S'; // NOLINT(readability-identifier-naming) + static const char T = 'T'; // NOLINT(readability-identifier-naming) + static const char U = 'U'; // NOLINT(readability-identifier-naming) + static const char V = 'V'; // NOLINT(readability-identifier-naming) + static const char W = 'W'; // NOLINT(readability-identifier-naming) + static const char X = 'X'; // NOLINT(readability-identifier-naming) + static const char Y = 'Y'; // NOLINT(readability-identifier-naming) + static const char Z = 'Z'; // NOLINT(readability-identifier-naming) + +} // namespace PXR_PEGTL_NAMESPACE::alphabet + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/analyze.hpp b/pxr/base/pegtl/pegtl/contrib/analyze.hpp new file mode 100644 index 0000000000..6db48422fe --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/analyze.hpp @@ -0,0 +1,189 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_ANALYZE_HPP +#define PXR_PEGTL_CONTRIB_ANALYZE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../config.hpp" +#include "../demangle.hpp" + +#include "analyze_traits.hpp" + +#include "internal/set_stack_guard.hpp" +#include "internal/vector_stack_guard.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + struct analyze_entry + { + explicit analyze_entry( const analyze_type in_type ) noexcept + : type( in_type ) + {} + + const analyze_type type; + std::vector< std::string_view > subs; + }; + + class analyze_cycles_impl + { + public: + analyze_cycles_impl( analyze_cycles_impl&& ) = delete; + analyze_cycles_impl( const analyze_cycles_impl& ) = delete; + + ~analyze_cycles_impl() = default; + + analyze_cycles_impl& operator=( analyze_cycles_impl&& ) = delete; + analyze_cycles_impl& operator=( const analyze_cycles_impl& ) = delete; + + [[nodiscard]] std::size_t problems() + { + for( auto& i : m_entries ) { + assert( m_trace.empty() ); + assert( m_stack.empty() ); + m_results[ i.first ] = work( i, false ); + } + // The number of problems returned is not very informative as some problems will be found multiple times. + return m_problems; + } + + template< typename Rule > + [[nodiscard]] bool consumes() const + { + // The name "consumes" is a shortcut for "the analyze cycles algorithm could prove that this rule always consumes when it succeeds". + return m_results.at( demangle< Rule >() ); + } + + protected: + explicit analyze_cycles_impl( const int verbose ) noexcept + : m_verbose( verbose ), + m_problems( 0 ) + {} + + [[nodiscard]] const std::pair< const std::string_view, analyze_entry >& find( const std::string_view name ) const noexcept + { + const auto iter = m_entries.find( name ); + assert( iter != m_entries.end() ); + return *iter; + } + + [[nodiscard]] bool work( const std::pair< const std::string_view, analyze_entry >& entry, const bool accum ) + { + if( const auto g = set_stack_guard( m_stack, entry.first ) ) { + const auto v = vector_stack_guard( m_trace, entry.first ); + switch( entry.second.type ) { + case analyze_type::any: { + bool a = false; + for( const auto& r : entry.second.subs ) { + a = a || work( find( r ), accum || a ); + } + return true; + } + case analyze_type::opt: { + bool a = false; + for( const auto& r : entry.second.subs ) { + a = a || work( find( r ), accum || a ); + } + return false; + } + case analyze_type::seq: { + bool a = false; + for( const auto& r : entry.second.subs ) { + a = a || work( find( r ), accum || a ); + } + return a; + } + case analyze_type::sor: { + bool a = true; + for( const auto& r : entry.second.subs ) { + a = a && work( find( r ), accum ); + } + return a; + } + } + assert( false ); // LCOV_EXCL_LINE + } + assert( !m_trace.empty() ); + + if( !accum ) { + ++m_problems; + // LCOV_EXCL_START + if( ( m_verbose >= 0 ) && ( m_trace.front() == entry.first ) ) { + for( const auto& r : m_trace ) { + if( r < entry.first ) { + return accum; + } + } + std::cerr << "WARNING: Possible cycle without progress at rule " << entry.first << std::endl; + if( m_verbose > 0 ) { + for( const auto& r : m_trace ) { + std::cerr << "- involved (transformed) rule: " << r << std::endl; + } + } + } + // LCOV_EXCL_STOP + } + return accum; + } + + const int m_verbose; + + std::size_t m_problems; + + std::set< std::string_view > m_stack; + std::vector< std::string_view > m_trace; + std::map< std::string_view, bool > m_results; + std::map< std::string_view, analyze_entry > m_entries; + }; + + template< typename Name > + std::string_view analyze_insert( std::map< std::string_view, analyze_entry >& entry ) + { + using Traits = analyze_traits< Name, typename Name::rule_t >; + + const auto [ i, b ] = entry.try_emplace( demangle< Name >(), Traits::type_v ); + if( b ) { + analyze_insert_impl( typename Traits::subs_t(), i->second.subs, entry ); + } + return i->first; + } + + template< typename... Subs > + void analyze_insert_impl( type_list< Subs... > /*unused*/, std::vector< std::string_view >& subs, std::map< std::string_view, analyze_entry >& entry ) + { + ( subs.emplace_back( analyze_insert< Subs >( entry ) ), ... ); + } + + template< typename Grammar > + struct analyze_cycles + : analyze_cycles_impl + { + explicit analyze_cycles( const int verbose ) + : analyze_cycles_impl( verbose ) + { + analyze_insert< Grammar >( m_entries ); + } + }; + + } // namespace internal + + template< typename Grammar > + [[nodiscard]] std::size_t analyze( const int verbose = 1 ) + { + return internal::analyze_cycles< Grammar >( verbose ).problems(); + } + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/analyze_traits.hpp b/pxr/base/pegtl/pegtl/contrib/analyze_traits.hpp new file mode 100644 index 0000000000..bfbb5f64b6 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/analyze_traits.hpp @@ -0,0 +1,277 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_ANALYZE_TRAITS_HPP +#define PXR_PEGTL_CONTRIB_ANALYZE_TRAITS_HPP + +#include + +#include "../ascii.hpp" +#include "../config.hpp" +#include "../rules.hpp" +#include "../type_list.hpp" + +#include "forward.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + enum class analyze_type + { + any, // Consumption-on-success is always true; assumes bounded repetition of conjunction of sub-rules. + opt, // Consumption-on-success not necessarily true; assumes bounded repetition of conjunction of sub-rules. + seq, // Consumption-on-success depends on consumption of (non-zero bounded repetition of) conjunction of sub-rules. + sor // Consumption-on-success depends on consumption of (non-zero bounded repetition of) disjunction of sub-rules. + }; + + } // namespace internal + + template< typename... Rules > + struct analyze_any_traits + { + static constexpr internal::analyze_type type_v = internal::analyze_type::any; + using subs_t = type_list< Rules... >; + }; + + template< typename... Rules > + struct analyze_opt_traits + { + static constexpr internal::analyze_type type_v = internal::analyze_type::opt; + using subs_t = type_list< Rules... >; + }; + + template< typename... Rules > + struct analyze_seq_traits + { + static constexpr internal::analyze_type type_v = internal::analyze_type::seq; + using subs_t = type_list< Rules... >; + }; + + template< typename... Rules > + struct analyze_sor_traits + { + static constexpr internal::analyze_type type_v = internal::analyze_type::sor; + using subs_t = type_list< Rules... >; + }; + + template< typename Name, template< typename... > class Action, typename... Rules > + struct analyze_traits< Name, internal::action< Action, Rules... > > + : analyze_traits< Name, typename seq< Rules... >::rule_t > + {}; + + template< typename Name, typename Peek > + struct analyze_traits< Name, internal::any< Peek > > + : analyze_any_traits<> + {}; + + template< typename Name, typename... Actions > + struct analyze_traits< Name, internal::apply< Actions... > > + : analyze_opt_traits<> + {}; + + template< typename Name, typename... Actions > + struct analyze_traits< Name, internal::apply0< Actions... > > + : analyze_opt_traits<> + {}; + + template< typename Name, typename... Rules > + struct analyze_traits< Name, internal::at< Rules... > > + : analyze_traits< Name, typename opt< Rules... >::rule_t > + {}; + + template< typename Name > + struct analyze_traits< Name, internal::bof > + : analyze_opt_traits<> + {}; + + template< typename Name > + struct analyze_traits< Name, internal::bol > + : analyze_opt_traits<> + {}; + + template< typename Name, unsigned Cnt > + struct analyze_traits< Name, internal::bytes< Cnt > > + : std::conditional_t< ( Cnt != 0 ), analyze_any_traits<>, analyze_opt_traits<> > + {}; + + template< typename Name, template< typename... > class Control, typename... Rules > + struct analyze_traits< Name, internal::control< Control, Rules... > > + : analyze_traits< Name, typename seq< Rules... >::rule_t > + {}; + + template< typename Name, typename... Rules > + struct analyze_traits< Name, internal::disable< Rules... > > + : analyze_traits< Name, typename seq< Rules... >::rule_t > + {}; + + template< typename Name > + struct analyze_traits< Name, internal::discard > + : analyze_opt_traits<> + {}; + + template< typename Name, typename... Rules > + struct analyze_traits< Name, internal::enable< Rules... > > + : analyze_traits< Name, typename seq< Rules... >::rule_t > + {}; + + template< typename Name > + struct analyze_traits< Name, internal::eof > + : analyze_opt_traits<> + {}; + + template< typename Name > + struct analyze_traits< Name, internal::eol > + : analyze_any_traits<> + {}; + + template< typename Name > + struct analyze_traits< Name, internal::eolf > + : analyze_opt_traits<> + {}; + + template< typename Name > + struct analyze_traits< Name, internal::failure > + : analyze_any_traits<> + {}; + + template< typename Name, typename Rule, typename... Actions > + struct analyze_traits< Name, internal::if_apply< Rule, Actions... > > + : analyze_traits< Name, typename Rule::rule_t > + {}; + + template< typename Name, typename Cond, typename Then, typename Else > + struct analyze_traits< Name, internal::if_then_else< Cond, Then, Else > > + : analyze_traits< Name, typename sor< seq< Cond, Then >, Else >::rule_t > + {}; + + template< typename Name, char... Cs > + struct analyze_traits< Name, internal::istring< Cs... > > + : std::conditional_t< ( sizeof...( Cs ) != 0 ), analyze_any_traits<>, analyze_opt_traits<> > + {}; + + template< typename Name, typename... Rules > + struct analyze_traits< Name, internal::not_at< Rules... > > + : analyze_traits< Name, typename opt< Rules... >::rule_t > + {}; + + template< typename Name, internal::result_on_found R, typename Peek, typename Peek::data_t... Cs > + struct analyze_traits< Name, internal::one< R, Peek, Cs... > > + : analyze_any_traits<> + {}; + + template< typename Name, typename Rule, typename... Rules > + struct analyze_traits< Name, internal::opt< Rule, Rules... > > + : analyze_opt_traits< Rule, Rules... > + {}; + + template< typename Name, typename... Rules > + struct analyze_traits< Name, internal::plus< Rules... > > + : analyze_traits< Name, typename seq< Rules..., opt< Name > >::rule_t > + {}; + + template< typename Name, internal::result_on_found R, typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > + struct analyze_traits< Name, internal::range< R, Peek, Lo, Hi > > + : analyze_any_traits<> + {}; + + template< typename Name, typename Peek, typename Peek::data_t... Cs > + struct analyze_traits< Name, internal::ranges< Peek, Cs... > > + : analyze_any_traits<> + {}; + + template< typename Name, typename Head, typename... Rules > + struct analyze_traits< Name, internal::rematch< Head, Rules... > > + : analyze_traits< Name, typename sor< Head, sor< seq< Rules, any >... > >::rule_t > // TODO: Correct (enough)? + {}; + + template< typename Name, unsigned Cnt, typename... Rules > + struct analyze_traits< Name, internal::rep< Cnt, Rules... > > + : analyze_traits< Name, std::conditional_t< ( Cnt != 0 ), typename seq< Rules... >::rule_t, typename opt< Rules... >::rule_t > > + {}; + + template< typename Name, unsigned Min, unsigned Max, typename... Rules > + struct analyze_traits< Name, internal::rep_min_max< Min, Max, Rules... > > + : analyze_traits< Name, std::conditional_t< ( Min != 0 ), typename seq< Rules... >::rule_t, typename opt< Rules... >::rule_t > > + {}; + + template< typename Name, unsigned Max, typename... Rules > + struct analyze_traits< Name, internal::rep_opt< Max, Rules... > > + : analyze_traits< Name, typename opt< Rules... >::rule_t > + {}; + + template< typename Name, unsigned Amount > + struct analyze_traits< Name, internal::require< Amount > > + : analyze_opt_traits<> + {}; + + template< typename Name, typename Rule, typename... Rules > + struct analyze_traits< Name, internal::seq< Rule, Rules... > > + : analyze_seq_traits< Rule, Rules... > + {}; + + template< typename Name, typename Rule, typename... Rules > + struct analyze_traits< Name, internal::sor< Rule, Rules... > > + : analyze_sor_traits< Rule, Rules... > + {}; + + template< typename Name, typename... Rules > + struct analyze_traits< Name, internal::star< Rules... > > + : analyze_traits< Name, typename opt< Rules..., Name >::rule_t > + {}; + + template< typename Name, typename State, typename... Rules > + struct analyze_traits< Name, internal::state< State, Rules... > > + : analyze_traits< Name, typename seq< Rules... >::rule_t > + {}; + + template< typename Name, char... Cs > + struct analyze_traits< Name, internal::string< Cs... > > + : std::conditional_t< ( sizeof...( Cs ) != 0 ), analyze_any_traits<>, analyze_opt_traits<> > + {}; + + template< typename Name > + struct analyze_traits< Name, internal::success > + : analyze_opt_traits<> + {}; + + template< typename Name, typename Cond > + struct analyze_traits< Name, internal::until< Cond > > + : analyze_traits< Name, typename Cond::rule_t > + {}; + + template< typename Name, typename Cond, typename... Rules > + struct analyze_traits< Name, internal::until< Cond, Rules... > > + : analyze_traits< Name, typename seq< star< Rules... >, Cond >::rule_t > + {}; + +#if defined( __cpp_exceptions ) + template< typename Name, typename Cond, typename... Rules > + struct analyze_traits< Name, internal::if_must< true, Cond, Rules... > > + : analyze_traits< Name, typename opt< Cond, Rules... >::rule_t > + {}; + + template< typename Name, typename Cond, typename... Rules > + struct analyze_traits< Name, internal::if_must< false, Cond, Rules... > > + : analyze_traits< Name, typename seq< Cond, Rules... >::rule_t > + {}; + + template< typename Name, typename... Rules > + struct analyze_traits< Name, internal::must< Rules... > > + : analyze_traits< Name, typename seq< Rules... >::rule_t > + {}; + + template< typename Name, typename T > + struct analyze_traits< Name, internal::raise< T > > + : analyze_any_traits<> + {}; + + template< typename Name, typename Exception, typename... Rules > + struct analyze_traits< Name, internal::try_catch_type< Exception, Rules... > > + : analyze_traits< Name, typename seq< Rules... >::rule_t > + {}; +#endif + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/check_bytes.hpp b/pxr/base/pegtl/pegtl/contrib/check_bytes.hpp new file mode 100644 index 0000000000..a4c8ed9970 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/check_bytes.hpp @@ -0,0 +1,55 @@ +// Copyright (c) 2021-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_CHECK_BYTES_HPP +#define PXR_PEGTL_CONTRIB_CHECK_BYTES_HPP + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../match.hpp" +#include "../nothing.hpp" +#include "../rewind_mode.hpp" + +#if defined( __cpp_exceptions ) +#include "../parse_error.hpp" +#else +#include +#include +#endif + +namespace PXR_PEGTL_NAMESPACE +{ + template< std::size_t Maximum > + struct check_bytes + : maybe_nothing + { + template< typename Rule, + pegtl::apply_mode A, + pegtl::rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + static bool match( ParseInput& in, States&&... st ) + { + const auto* start = in.current(); + if( PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ) ) { + if( std::size_t( in.current() - start ) > Maximum ) { +#if defined( __cpp_exceptions ) + throw PXR_PEGTL_NAMESPACE::parse_error( "maximum allowed rule consumption exceeded", in ); +#else + std::fputs( "maximum allowed rule consumption exceeded\n", stderr ); + std::terminate(); +#endif + } + return true; + } + return false; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/control_action.hpp b/pxr/base/pegtl/pegtl/contrib/control_action.hpp new file mode 100644 index 0000000000..42edf0c4db --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/control_action.hpp @@ -0,0 +1,93 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_CONTROL_ACTION_HPP +#define PXR_PEGTL_CONTRIB_CONTROL_ACTION_HPP + +#include + +#include "../config.hpp" +#include "../match.hpp" +#include "../nothing.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename, typename Rule, template< typename... > class Action, typename ParseInput, typename... States > + inline constexpr bool action_has_unwind = false; + + template< typename Rule, template< typename... > class Action, typename ParseInput, typename... States > + inline constexpr bool action_has_unwind< decltype( (void)Action< Rule >::unwind( std::declval< const ParseInput& >(), std::declval< States&& >()... ) ), Rule, Action, ParseInput, States... > = true; + + } // namespace internal + + struct control_action + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { +#if defined( __cpp_exceptions ) + if constexpr( internal::action_has_unwind< void, Rule, Action, ParseInput, States... > ) { + try { + return control_action::match_impl< Rule, A, M, Action, Control >( in, st... ); + } + catch( ... ) { + Action< Rule >::unwind( const_cast< const ParseInput& >( in ), st... ); + throw; + } + } + else { + return control_action::match_impl< Rule, A, M, Action, Control >( in, st... ); + } +#else + return control_action::match_impl< Rule, A, M, Action, Control >( in, st... ); +#endif + } + + template< typename ParseInput, typename... States > + static void start( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept + {} + + template< typename ParseInput, typename... States > + static void success( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept + {} + + template< typename ParseInput, typename... States > + static void failure( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept + {} + + private: + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match_impl( ParseInput& in, States&&... st ) + { + Action< Rule >::start( const_cast< const ParseInput& >( in ), st... ); + if( PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ) ) { + Action< Rule >::success( const_cast< const ParseInput& >( in ), st... ); + return true; + } + Action< Rule >::failure( const_cast< const ParseInput& >( in ), st... ); + return false; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/coverage.hpp b/pxr/base/pegtl/pegtl/contrib/coverage.hpp new file mode 100644 index 0000000000..d01ea507d9 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/coverage.hpp @@ -0,0 +1,151 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_COVERAGE_HPP +#define PXR_PEGTL_CONTRIB_COVERAGE_HPP + +#include +#include +#include +#include + +#include "state_control.hpp" + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../demangle.hpp" +#include "../normal.hpp" +#include "../nothing.hpp" +#include "../parse.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" +#include "../visit.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + struct coverage_info + { + std::size_t start = 0; + std::size_t success = 0; + std::size_t failure = 0; + std::size_t unwind = 0; + std::size_t raise = 0; + }; + + struct coverage_entry + : coverage_info + { + std::map< std::string_view, coverage_info > branches; + }; + + using coverage_result = std::map< std::string_view, coverage_entry >; + + namespace internal + { + template< typename Rule > + struct coverage_insert + { + static void visit( std::map< std::string_view, coverage_entry >& map ) + { + visit_branches( map.try_emplace( demangle< Rule >() ).first->second.branches, typename Rule::subs_t() ); + } + + template< typename... Ts > + static void visit_branches( std::map< std::string_view, coverage_info >& branches, type_list< Ts... > /*unused*/ ) + { + ( branches.try_emplace( demangle< Ts >() ), ... ); + } + }; + + struct coverage_state + { + template< typename Rule > + static constexpr bool enable = true; + + explicit coverage_state( coverage_result& in_result ) + : result( in_result ) + {} + + coverage_result& result; + std::vector< std::string_view > stack; + + template< typename Rule, typename ParseInput, typename... States > + void start( const ParseInput& /*unused*/, States&&... /*unused*/ ) + { + const auto name = demangle< Rule >(); + ++result.at( name ).start; + if( !stack.empty() ) { + ++result.at( stack.back() ).branches.at( name ).start; + } + stack.push_back( name ); + } + + template< typename Rule, typename ParseInput, typename... States > + void success( const ParseInput& /*unused*/, States&&... /*unused*/ ) + { + stack.pop_back(); + const auto name = demangle< Rule >(); + ++result.at( name ).success; + if( !stack.empty() ) { + ++result.at( stack.back() ).branches.at( name ).success; + } + } + + template< typename Rule, typename ParseInput, typename... States > + void failure( const ParseInput& /*unused*/, States&&... /*unused*/ ) + { + stack.pop_back(); + const auto name = demangle< Rule >(); + ++result.at( name ).failure; + if( !stack.empty() ) { + ++result.at( stack.back() ).branches.at( name ).failure; + } + } + + template< typename Rule, typename ParseInput, typename... States > + void raise( const ParseInput& /*unused*/, States&&... /*unused*/ ) + { + const auto name = demangle< Rule >(); + ++result.at( name ).raise; + if( !stack.empty() ) { + ++result.at( stack.back() ).branches.at( name ).raise; + } + } + + template< typename Rule, typename ParseInput, typename... States > + void unwind( const ParseInput& /*unused*/, States&&... /*unused*/ ) + { + stack.pop_back(); + const auto name = demangle< Rule >(); + ++result.at( name ).unwind; + if( !stack.empty() ) { + ++result.at( stack.back() ).branches.at( name ).unwind; + } + } + + template< typename Rule, typename ParseInput, typename... States > + void apply( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept + {} + + template< typename Rule, typename ParseInput, typename... States > + void apply0( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept + {} + }; + + } // namespace internal + + template< typename Rule, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + typename ParseInput, + typename... States > + bool coverage( ParseInput&& in, coverage_result& result, States&&... st ) + { + internal::coverage_state state( result ); + visit< Rule, internal::coverage_insert >( state.result ); // Fill map with all sub-rules of the grammar. + return parse< Rule, Action, state_control< Control >::template type >( in, st..., state ); + } + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/forward.hpp b/pxr/base/pegtl/pegtl/contrib/forward.hpp new file mode 100644 index 0000000000..54c39f7bfb --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/forward.hpp @@ -0,0 +1,16 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_FORWARD_HPP +#define PXR_PEGTL_CONTRIB_FORWARD_HPP + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< typename Name, typename Rule, typename = void > + struct analyze_traits; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/function.hpp b/pxr/base/pegtl/pegtl/contrib/function.hpp new file mode 100644 index 0000000000..6fcad083a9 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/function.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_FUNCTION_HPP +#define PXR_PEGTL_CONTRIB_FUNCTION_HPP + +#include "../config.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +#include "../internal/enable_control.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename F, F U > + struct function; + + template< typename ParseInput, typename... States, bool ( *U )( ParseInput&, States... ) > + struct function< bool ( * )( ParseInput&, States... ), U > + { + using rule_t = function; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control > + [[nodiscard]] static bool match( ParseInput& in, States... st ) noexcept( noexcept( U( in, st... ) ) ) + { + return U( in, st... ); + } + }; + + template< typename F, F U > + inline constexpr bool enable_control< function< F, U > > = false; + + } // namespace internal + + template< auto F > + struct function + : internal::function< decltype( F ), F > + {}; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/http.hpp b/pxr/base/pegtl/pegtl/contrib/http.hpp new file mode 100644 index 0000000000..4845b5ffb2 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/http.hpp @@ -0,0 +1,277 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_HTTP_HPP +#define PXR_PEGTL_CONTRIB_HTTP_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/contrib/http.hpp" +#else + +#include "../ascii.hpp" +#include "../config.hpp" +#include "../nothing.hpp" +#include "../rules.hpp" +#include "../utf8.hpp" + +#include "abnf.hpp" +#include "forward.hpp" +#include "remove_first_state.hpp" +#include "uri.hpp" + +namespace PXR_PEGTL_NAMESPACE::http +{ + // HTTP 1.1 grammar according to RFC 7230. + + // This grammar is a direct PEG translation of the original HTTP grammar. + // It should be considered experimental -- in case of any issues, in particular + // missing rules for attached actions, please contact the developers. + + using OWS = star< abnf::WSP >; // optional whitespace + using RWS = plus< abnf::WSP >; // required whitespace + using BWS = OWS; // "bad" whitespace + + using obs_text = not_range< 0x00, 0x7F >; + using obs_fold = seq< abnf::CRLF, plus< abnf::WSP > >; + + // clang-format off + struct tchar : sor< abnf::ALPHA, abnf::DIGIT, one< '!', '#', '$', '%', '&', '\'', '*', '+', '-', '.', '^', '_', '`', '|', '~' > > {}; + struct token : plus< tchar > {}; + + struct field_name : token {}; + + struct field_vchar : sor< abnf::VCHAR, obs_text > {}; + struct field_content : list< field_vchar, plus< abnf::WSP > > {}; + struct field_value : star< sor< field_content, obs_fold > > {}; + + struct header_field : seq< field_name, one< ':' >, OWS, field_value, OWS > {}; + + struct method : token {}; + + struct absolute_path : plus< one< '/' >, uri::segment > {}; + + struct origin_form : seq< absolute_path, uri::opt_query > {}; + struct absolute_form : uri::absolute_URI {}; + struct authority_form : uri::authority {}; + struct asterisk_form : one< '*' > {}; + + struct request_target : sor< origin_form, absolute_form, authority_form, asterisk_form > {}; + + struct status_code : rep< 3, abnf::DIGIT > {}; + struct reason_phrase : star< sor< abnf::VCHAR, obs_text, abnf::WSP > > {}; + + struct HTTP_version : if_must< string< 'H', 'T', 'T', 'P', '/' >, abnf::DIGIT, one< '.' >, abnf::DIGIT > {}; + + struct request_line : if_must< method, abnf::SP, request_target, abnf::SP, HTTP_version, abnf::CRLF > {}; + struct status_line : if_must< HTTP_version, abnf::SP, status_code, abnf::SP, reason_phrase, abnf::CRLF > {}; + struct start_line : sor< status_line, request_line > {}; + + struct message_body : star< abnf::OCTET > {}; + struct HTTP_message : seq< start_line, star< header_field, abnf::CRLF >, abnf::CRLF, opt< message_body > > {}; + + struct Content_Length : plus< abnf::DIGIT > {}; + + struct uri_host : uri::host {}; + struct port : uri::port {}; + + struct Host : seq< uri_host, opt< one< ':' >, port > > {}; + + // PEG are different from CFGs! (this replaces ctext and qdtext) + using text = sor< abnf::HTAB, range< 0x20, 0x7E >, obs_text >; + + struct quoted_pair : if_must< one< '\\' >, sor< abnf::VCHAR, obs_text, abnf::WSP > > {}; + struct quoted_string : if_must< abnf::DQUOTE, until< abnf::DQUOTE, sor< quoted_pair, text > > > {}; + + struct transfer_parameter : seq< token, BWS, one< '=' >, BWS, sor< token, quoted_string > > {}; + struct transfer_extension : seq< token, star< OWS, one< ';' >, OWS, transfer_parameter > > {}; + struct transfer_coding : sor< istring< 'c', 'h', 'u', 'n', 'k', 'e', 'd' >, + istring< 'c', 'o', 'm', 'p', 'r', 'e', 's', 's' >, + istring< 'd', 'e', 'f', 'l', 'a', 't', 'e' >, + istring< 'g', 'z', 'i', 'p' >, + transfer_extension > {}; + + struct rank : sor< seq< one< '0' >, opt< one< '.' >, rep_opt< 3, abnf::DIGIT > > >, + seq< one< '1' >, opt< one< '.' >, rep_opt< 3, one< '0' > > > > > {}; + + struct t_ranking : seq< OWS, one< ';' >, OWS, one< 'q', 'Q' >, one< '=' >, rank > {}; + struct t_codings : sor< istring< 't', 'r', 'a', 'i', 'l', 'e', 'r', 's' >, seq< transfer_coding, opt< t_ranking > > > {}; + + struct TE : opt< sor< one< ',' >, t_codings >, star< OWS, one< ',' >, opt< OWS, t_codings > > > {}; + + template< typename T > + using make_comma_list = seq< star< one< ',' >, OWS >, T, star< OWS, one< ',' >, opt< OWS, T > > >; + + struct connection_option : token {}; + struct Connection : make_comma_list< connection_option > {}; + + struct Trailer : make_comma_list< field_name > {}; + + struct Transfer_Encoding : make_comma_list< transfer_coding > {}; + + struct protocol_name : token {}; + struct protocol_version : token {}; + struct protocol : seq< protocol_name, opt< one< '/' >, protocol_version > > {}; + struct Upgrade : make_comma_list< protocol > {}; + + struct pseudonym : token {}; + + struct received_protocol : seq< opt< protocol_name, one< '/' > >, protocol_version > {}; + struct received_by : sor< seq< uri_host, opt< one< ':' >, port > >, pseudonym > {}; + + struct comment : if_must< one< '(' >, until< one< ')' >, sor< comment, quoted_pair, text > > > {}; + + struct Via : make_comma_list< seq< received_protocol, RWS, received_by, opt< RWS, comment > > > {}; + + struct http_URI : if_must< istring< 'h', 't', 't', 'p', ':', '/', '/' >, uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {}; + struct https_URI : if_must< istring< 'h', 't', 't', 'p', 's', ':', '/', '/' >, uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {}; + + struct partial_URI : seq< uri::relative_part, uri::opt_query > {}; + // clang-format on + + struct chunk_size + { + using rule_t = plus< abnf::HEXDIG >::rule_t; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, std::size_t& size, States&&... /*unused*/ ) + { + size = 0; + std::size_t i = 0; + while( in.size( i + 1 ) >= i + 1 ) { + const auto c = in.peek_char( i ); + if( ( '0' <= c ) && ( c <= '9' ) ) { + size <<= 4; + size |= std::size_t( c - '0' ); + ++i; + continue; + } + if( ( 'a' <= c ) && ( c <= 'f' ) ) { + size <<= 4; + size |= std::size_t( c - 'a' + 10 ); + ++i; + continue; + } + if( ( 'A' <= c ) && ( c <= 'F' ) ) { + size <<= 4; + size |= std::size_t( c - 'A' + 10 ); + ++i; + continue; + } + break; + } + in.bump_in_this_line( i ); + return i > 0; + } + }; + + // clang-format off + struct chunk_ext_name : token {}; + struct chunk_ext_val : sor< quoted_string, token > {}; + struct chunk_ext : star_must< one< ';' >, chunk_ext_name, if_must< one< '=' >, chunk_ext_val > > {}; + // clang-format on + + struct chunk_data + { + using rule_t = star< abnf::OCTET >::rule_t; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, const std::size_t size, States&&... /*unused*/ ) + { + if( in.size( size ) >= size ) { + in.bump( size ); + return true; + } + return false; + } + }; + + namespace internal::chunk_helper + { + template< typename Base > + struct control; + + template< template< typename... > class Control, typename Rule > + struct control< Control< Rule > > + : Control< Rule > + { + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class, + typename ParseInput, + typename State, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, State&& /*unused*/, States&&... st ) + { + return Control< Rule >::template match< A, M, Action, Control >( in, st... ); + } + }; + + template< template< typename... > class Control > + struct control< Control< chunk_size > > + : remove_first_state< Control< chunk_size > > + {}; + + template< template< typename... > class Control > + struct control< Control< chunk_data > > + : remove_first_state< Control< chunk_data > > + {}; + + template< template< typename... > class Control > + struct bind + { + template< typename Rule > + using type = control< Control< Rule > >; + }; + + } // namespace internal::chunk_helper + + struct chunk + { + using impl = seq< chunk_size, chunk_ext, abnf::CRLF, chunk_data, abnf::CRLF >; + + using rule_t = impl::rule_t; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + std::size_t size{}; + return impl::template match< A, M, Action, internal::chunk_helper::bind< Control >::template type >( in, size, st... ); + } + }; + + // clang-format off + struct last_chunk : seq< plus< one< '0' > >, not_at< digit >, chunk_ext, abnf::CRLF > {}; + + struct trailer_part : star< header_field, abnf::CRLF > {}; + + struct chunked_body : seq< until< last_chunk, chunk >, trailer_part, abnf::CRLF > {}; + // clang-format on + +} // namespace PXR_PEGTL_NAMESPACE::http + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/icu/internal.hpp b/pxr/base/pegtl/pegtl/contrib/icu/internal.hpp new file mode 100644 index 0000000000..52185b458a --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/icu/internal.hpp @@ -0,0 +1,98 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_ICU_INTERNAL_HPP +#define PXR_PEGTL_CONTRIB_ICU_INTERNAL_HPP + +#include + +#include "../analyze_traits.hpp" + +#include "../../config.hpp" +#include "../../type_list.hpp" + +#include "../../internal/enable_control.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + namespace icu + { + template< typename Peek, UProperty P, bool V = true > + struct binary_property + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + using rule_t = binary_property; + using subs_t = empty_list; + + [[nodiscard]] static bool test( const data_t c ) noexcept + { + return u_hasBinaryProperty( c, P ) == V; + } + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + { + if( const auto t = Peek::peek( in ) ) { + if( test( t.data ) ) { + in.bump( t.size ); + return true; + } + } + return false; + } + }; + + template< typename Peek, UProperty P, int V > + struct property_value + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + using rule_t = property_value; + using subs_t = empty_list; + + [[nodiscard]] static bool test( const data_t c ) noexcept + { + return u_getIntPropertyValue( c, P ) == V; + } + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + { + if( const auto t = Peek::peek( in ) ) { + if( test( t.data ) ) { + in.bump( t.size ); + return true; + } + } + return false; + } + }; + + } // namespace icu + + template< typename Peek, UProperty P, bool V > + inline constexpr bool enable_control< icu::binary_property< Peek, P, V > > = false; + + template< typename Peek, UProperty P, int V > + inline constexpr bool enable_control< icu::property_value< Peek, P, V > > = false; + + } // namespace internal + + template< typename Name, typename Peek, UProperty P, bool V > + struct analyze_traits< Name, internal::icu::binary_property< Peek, P, V > > + : analyze_any_traits<> + {}; + + template< typename Name, typename Peek, UProperty P, int V > + struct analyze_traits< Name, internal::icu::property_value< Peek, P, V > > + : analyze_any_traits<> + {}; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/icu/utf16.hpp b/pxr/base/pegtl/pegtl/contrib/icu/utf16.hpp new file mode 100644 index 0000000000..932696b1d6 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/icu/utf16.hpp @@ -0,0 +1,196 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_ICU_UTF16_HPP +#define PXR_PEGTL_CONTRIB_ICU_UTF16_HPP + +#include "internal.hpp" + +#include "../../config.hpp" +#include "../utf16.hpp" + +#include "../internal/peek_utf16.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace utf16_be::icu + { + template< UProperty P, bool V = true > + struct binary_property + : internal::icu::binary_property< internal::peek_utf16_be, P, V > + {}; + + template< UProperty P, int V > + struct property_value + : internal::icu::property_value< internal::peek_utf16_be, P, V > + {}; + + // clang-format off + struct alphabetic : binary_property< UCHAR_ALPHABETIC > {}; + struct ascii_hex_digit : binary_property< UCHAR_ASCII_HEX_DIGIT > {}; + struct bidi_control : binary_property< UCHAR_BIDI_CONTROL > {}; + struct bidi_mirrored : binary_property< UCHAR_BIDI_MIRRORED > {}; + struct case_sensitive : binary_property< UCHAR_CASE_SENSITIVE > {}; + struct dash : binary_property< UCHAR_DASH > {}; + struct default_ignorable_code_point : binary_property< UCHAR_DEFAULT_IGNORABLE_CODE_POINT > {}; + struct deprecated : binary_property< UCHAR_DEPRECATED > {}; + struct diacritic : binary_property< UCHAR_DIACRITIC > {}; + struct extender : binary_property< UCHAR_EXTENDER > {}; + struct full_composition_exclusion : binary_property< UCHAR_FULL_COMPOSITION_EXCLUSION > {}; + struct grapheme_base : binary_property< UCHAR_GRAPHEME_BASE > {}; + struct grapheme_extend : binary_property< UCHAR_GRAPHEME_EXTEND > {}; + struct grapheme_link : binary_property< UCHAR_GRAPHEME_LINK > {}; + struct hex_digit : binary_property< UCHAR_HEX_DIGIT > {}; + struct hyphen : binary_property< UCHAR_HYPHEN > {}; + struct id_continue : binary_property< UCHAR_ID_CONTINUE > {}; + struct id_start : binary_property< UCHAR_ID_START > {}; + struct ideographic : binary_property< UCHAR_IDEOGRAPHIC > {}; + struct ids_binary_operator : binary_property< UCHAR_IDS_BINARY_OPERATOR > {}; + struct ids_trinary_operator : binary_property< UCHAR_IDS_TRINARY_OPERATOR > {}; + struct join_control : binary_property< UCHAR_JOIN_CONTROL > {}; + struct logical_order_exception : binary_property< UCHAR_LOGICAL_ORDER_EXCEPTION > {}; + struct lowercase : binary_property< UCHAR_LOWERCASE > {}; + struct math : binary_property< UCHAR_MATH > {}; + struct nfc_inert : binary_property< UCHAR_NFC_INERT > {}; + struct nfd_inert : binary_property< UCHAR_NFD_INERT > {}; + struct nfkc_inert : binary_property< UCHAR_NFKC_INERT > {}; + struct nfkd_inert : binary_property< UCHAR_NFKD_INERT > {}; + struct noncharacter_code_point : binary_property< UCHAR_NONCHARACTER_CODE_POINT > {}; + struct pattern_syntax : binary_property< UCHAR_PATTERN_SYNTAX > {}; + struct pattern_white_space : binary_property< UCHAR_PATTERN_WHITE_SPACE > {}; + struct posix_alnum : binary_property< UCHAR_POSIX_ALNUM > {}; + struct posix_blank : binary_property< UCHAR_POSIX_BLANK > {}; + struct posix_graph : binary_property< UCHAR_POSIX_GRAPH > {}; + struct posix_print : binary_property< UCHAR_POSIX_PRINT > {}; + struct posix_xdigit : binary_property< UCHAR_POSIX_XDIGIT > {}; + struct quotation_mark : binary_property< UCHAR_QUOTATION_MARK > {}; + struct radical : binary_property< UCHAR_RADICAL > {}; + struct s_term : binary_property< UCHAR_S_TERM > {}; + struct segment_starter : binary_property< UCHAR_SEGMENT_STARTER > {}; + struct soft_dotted : binary_property< UCHAR_SOFT_DOTTED > {}; + struct terminal_punctuation : binary_property< UCHAR_TERMINAL_PUNCTUATION > {}; + struct unified_ideograph : binary_property< UCHAR_UNIFIED_IDEOGRAPH > {}; + struct uppercase : binary_property< UCHAR_UPPERCASE > {}; + struct variation_selector : binary_property< UCHAR_VARIATION_SELECTOR > {}; + struct white_space : binary_property< UCHAR_WHITE_SPACE > {}; + struct xid_continue : binary_property< UCHAR_XID_CONTINUE > {}; + struct xid_start : binary_property< UCHAR_XID_START > {}; + + template< UCharDirection V > struct bidi_class : property_value< UCHAR_BIDI_CLASS, V > {}; + template< UBlockCode V > struct block : property_value< UCHAR_BLOCK, V > {}; + template< UDecompositionType V > struct decomposition_type : property_value< UCHAR_DECOMPOSITION_TYPE, V > {}; + template< UEastAsianWidth V > struct east_asian_width : property_value< UCHAR_EAST_ASIAN_WIDTH, V > {}; + template< UCharCategory V > struct general_category : property_value< UCHAR_GENERAL_CATEGORY, V > {}; + template< UGraphemeClusterBreak V > struct grapheme_cluster_break : property_value< UCHAR_GRAPHEME_CLUSTER_BREAK, V > {}; + template< UHangulSyllableType V > struct hangul_syllable_type : property_value< UCHAR_HANGUL_SYLLABLE_TYPE, V > {}; + template< UJoiningGroup V > struct joining_group : property_value< UCHAR_JOINING_GROUP, V > {}; + template< UJoiningType V > struct joining_type : property_value< UCHAR_JOINING_TYPE, V > {}; + template< ULineBreak V > struct line_break : property_value< UCHAR_LINE_BREAK, V > {}; + // UNormalizationCheckResult requires an additional header : + // template< UNormalizationCheckResult V > struct nfc_quick_check : property_value< UCHAR_NFC_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfd_quick_check : property_value< UCHAR_NFD_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfkc_quick_check : property_value< UCHAR_NFKC_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfkd_quick_check : property_value< UCHAR_NFKD_QUICK_CHECK, V > {}; + template< UNumericType V > struct numeric_type : property_value< UCHAR_NUMERIC_TYPE, V > {}; + template< USentenceBreak V > struct sentence_break : property_value< UCHAR_SENTENCE_BREAK, V > {}; + template< UWordBreakValues V > struct word_break : property_value< UCHAR_WORD_BREAK, V > {}; + + template< std::uint8_t V > struct canonical_combining_class : property_value< UCHAR_CANONICAL_COMBINING_CLASS, V > {}; + template< std::uint8_t V > struct lead_canonical_combining_class : property_value< UCHAR_LEAD_CANONICAL_COMBINING_CLASS, V > {}; + template< std::uint8_t V > struct trail_canonical_combining_class : property_value< UCHAR_TRAIL_CANONICAL_COMBINING_CLASS, V > {}; + // clang-format on + + } // namespace utf16_be::icu + + namespace utf16_le::icu + { + template< UProperty P, bool V = true > + struct binary_property + : internal::icu::binary_property< internal::peek_utf16_le, P, V > + {}; + + template< UProperty P, int V > + struct property_value + : internal::icu::property_value< internal::peek_utf16_le, P, V > + {}; + + // clang-format off + struct alphabetic : binary_property< UCHAR_ALPHABETIC > {}; + struct ascii_hex_digit : binary_property< UCHAR_ASCII_HEX_DIGIT > {}; + struct bidi_control : binary_property< UCHAR_BIDI_CONTROL > {}; + struct bidi_mirrored : binary_property< UCHAR_BIDI_MIRRORED > {}; + struct case_sensitive : binary_property< UCHAR_CASE_SENSITIVE > {}; + struct dash : binary_property< UCHAR_DASH > {}; + struct default_ignorable_code_point : binary_property< UCHAR_DEFAULT_IGNORABLE_CODE_POINT > {}; + struct deprecated : binary_property< UCHAR_DEPRECATED > {}; + struct diacritic : binary_property< UCHAR_DIACRITIC > {}; + struct extender : binary_property< UCHAR_EXTENDER > {}; + struct full_composition_exclusion : binary_property< UCHAR_FULL_COMPOSITION_EXCLUSION > {}; + struct grapheme_base : binary_property< UCHAR_GRAPHEME_BASE > {}; + struct grapheme_extend : binary_property< UCHAR_GRAPHEME_EXTEND > {}; + struct grapheme_link : binary_property< UCHAR_GRAPHEME_LINK > {}; + struct hex_digit : binary_property< UCHAR_HEX_DIGIT > {}; + struct hyphen : binary_property< UCHAR_HYPHEN > {}; + struct id_continue : binary_property< UCHAR_ID_CONTINUE > {}; + struct id_start : binary_property< UCHAR_ID_START > {}; + struct ideographic : binary_property< UCHAR_IDEOGRAPHIC > {}; + struct ids_binary_operator : binary_property< UCHAR_IDS_BINARY_OPERATOR > {}; + struct ids_trinary_operator : binary_property< UCHAR_IDS_TRINARY_OPERATOR > {}; + struct join_control : binary_property< UCHAR_JOIN_CONTROL > {}; + struct logical_order_exception : binary_property< UCHAR_LOGICAL_ORDER_EXCEPTION > {}; + struct lowercase : binary_property< UCHAR_LOWERCASE > {}; + struct math : binary_property< UCHAR_MATH > {}; + struct nfc_inert : binary_property< UCHAR_NFC_INERT > {}; + struct nfd_inert : binary_property< UCHAR_NFD_INERT > {}; + struct nfkc_inert : binary_property< UCHAR_NFKC_INERT > {}; + struct nfkd_inert : binary_property< UCHAR_NFKD_INERT > {}; + struct noncharacter_code_point : binary_property< UCHAR_NONCHARACTER_CODE_POINT > {}; + struct pattern_syntax : binary_property< UCHAR_PATTERN_SYNTAX > {}; + struct pattern_white_space : binary_property< UCHAR_PATTERN_WHITE_SPACE > {}; + struct posix_alnum : binary_property< UCHAR_POSIX_ALNUM > {}; + struct posix_blank : binary_property< UCHAR_POSIX_BLANK > {}; + struct posix_graph : binary_property< UCHAR_POSIX_GRAPH > {}; + struct posix_print : binary_property< UCHAR_POSIX_PRINT > {}; + struct posix_xdigit : binary_property< UCHAR_POSIX_XDIGIT > {}; + struct quotation_mark : binary_property< UCHAR_QUOTATION_MARK > {}; + struct radical : binary_property< UCHAR_RADICAL > {}; + struct s_term : binary_property< UCHAR_S_TERM > {}; + struct segment_starter : binary_property< UCHAR_SEGMENT_STARTER > {}; + struct soft_dotted : binary_property< UCHAR_SOFT_DOTTED > {}; + struct terminal_punctuation : binary_property< UCHAR_TERMINAL_PUNCTUATION > {}; + struct unified_ideograph : binary_property< UCHAR_UNIFIED_IDEOGRAPH > {}; + struct uppercase : binary_property< UCHAR_UPPERCASE > {}; + struct variation_selector : binary_property< UCHAR_VARIATION_SELECTOR > {}; + struct white_space : binary_property< UCHAR_WHITE_SPACE > {}; + struct xid_continue : binary_property< UCHAR_XID_CONTINUE > {}; + struct xid_start : binary_property< UCHAR_XID_START > {}; + + template< UCharDirection V > struct bidi_class : property_value< UCHAR_BIDI_CLASS, V > {}; + template< UBlockCode V > struct block : property_value< UCHAR_BLOCK, V > {}; + template< UDecompositionType V > struct decomposition_type : property_value< UCHAR_DECOMPOSITION_TYPE, V > {}; + template< UEastAsianWidth V > struct east_asian_width : property_value< UCHAR_EAST_ASIAN_WIDTH, V > {}; + template< UCharCategory V > struct general_category : property_value< UCHAR_GENERAL_CATEGORY, V > {}; + template< UGraphemeClusterBreak V > struct grapheme_cluster_break : property_value< UCHAR_GRAPHEME_CLUSTER_BREAK, V > {}; + template< UHangulSyllableType V > struct hangul_syllable_type : property_value< UCHAR_HANGUL_SYLLABLE_TYPE, V > {}; + template< UJoiningGroup V > struct joining_group : property_value< UCHAR_JOINING_GROUP, V > {}; + template< UJoiningType V > struct joining_type : property_value< UCHAR_JOINING_TYPE, V > {}; + template< ULineBreak V > struct line_break : property_value< UCHAR_LINE_BREAK, V > {}; + // UNormalizationCheckResult requires an additional header : + // template< UNormalizationCheckResult V > struct nfc_quick_check : property_value< UCHAR_NFC_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfd_quick_check : property_value< UCHAR_NFD_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfkc_quick_check : property_value< UCHAR_NFKC_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfkd_quick_check : property_value< UCHAR_NFKD_QUICK_CHECK, V > {}; + template< UNumericType V > struct numeric_type : property_value< UCHAR_NUMERIC_TYPE, V > {}; + template< USentenceBreak V > struct sentence_break : property_value< UCHAR_SENTENCE_BREAK, V > {}; + template< UWordBreakValues V > struct word_break : property_value< UCHAR_WORD_BREAK, V > {}; + + template< std::uint8_t V > struct canonical_combining_class : property_value< UCHAR_CANONICAL_COMBINING_CLASS, V > {}; + template< std::uint8_t V > struct lead_canonical_combining_class : property_value< UCHAR_LEAD_CANONICAL_COMBINING_CLASS, V > {}; + template< std::uint8_t V > struct trail_canonical_combining_class : property_value< UCHAR_TRAIL_CANONICAL_COMBINING_CLASS, V > {}; + // clang-format on + + } // namespace utf16_le::icu + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/icu/utf32.hpp b/pxr/base/pegtl/pegtl/contrib/icu/utf32.hpp new file mode 100644 index 0000000000..cb800cbf41 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/icu/utf32.hpp @@ -0,0 +1,196 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_ICU_UTF32_HPP +#define PXR_PEGTL_CONTRIB_ICU_UTF32_HPP + +#include "internal.hpp" + +#include "../../config.hpp" +#include "../utf32.hpp" + +#include "../internal/peek_utf32.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace utf32_be::icu + { + template< UProperty P, bool V = true > + struct binary_property + : internal::icu::binary_property< internal::peek_utf32_be, P, V > + {}; + + template< UProperty P, int V > + struct property_value + : internal::icu::property_value< internal::peek_utf32_be, P, V > + {}; + + // clang-format off + struct alphabetic : binary_property< UCHAR_ALPHABETIC > {}; + struct ascii_hex_digit : binary_property< UCHAR_ASCII_HEX_DIGIT > {}; + struct bidi_control : binary_property< UCHAR_BIDI_CONTROL > {}; + struct bidi_mirrored : binary_property< UCHAR_BIDI_MIRRORED > {}; + struct case_sensitive : binary_property< UCHAR_CASE_SENSITIVE > {}; + struct dash : binary_property< UCHAR_DASH > {}; + struct default_ignorable_code_point : binary_property< UCHAR_DEFAULT_IGNORABLE_CODE_POINT > {}; + struct deprecated : binary_property< UCHAR_DEPRECATED > {}; + struct diacritic : binary_property< UCHAR_DIACRITIC > {}; + struct extender : binary_property< UCHAR_EXTENDER > {}; + struct full_composition_exclusion : binary_property< UCHAR_FULL_COMPOSITION_EXCLUSION > {}; + struct grapheme_base : binary_property< UCHAR_GRAPHEME_BASE > {}; + struct grapheme_extend : binary_property< UCHAR_GRAPHEME_EXTEND > {}; + struct grapheme_link : binary_property< UCHAR_GRAPHEME_LINK > {}; + struct hex_digit : binary_property< UCHAR_HEX_DIGIT > {}; + struct hyphen : binary_property< UCHAR_HYPHEN > {}; + struct id_continue : binary_property< UCHAR_ID_CONTINUE > {}; + struct id_start : binary_property< UCHAR_ID_START > {}; + struct ideographic : binary_property< UCHAR_IDEOGRAPHIC > {}; + struct ids_binary_operator : binary_property< UCHAR_IDS_BINARY_OPERATOR > {}; + struct ids_trinary_operator : binary_property< UCHAR_IDS_TRINARY_OPERATOR > {}; + struct join_control : binary_property< UCHAR_JOIN_CONTROL > {}; + struct logical_order_exception : binary_property< UCHAR_LOGICAL_ORDER_EXCEPTION > {}; + struct lowercase : binary_property< UCHAR_LOWERCASE > {}; + struct math : binary_property< UCHAR_MATH > {}; + struct nfc_inert : binary_property< UCHAR_NFC_INERT > {}; + struct nfd_inert : binary_property< UCHAR_NFD_INERT > {}; + struct nfkc_inert : binary_property< UCHAR_NFKC_INERT > {}; + struct nfkd_inert : binary_property< UCHAR_NFKD_INERT > {}; + struct noncharacter_code_point : binary_property< UCHAR_NONCHARACTER_CODE_POINT > {}; + struct pattern_syntax : binary_property< UCHAR_PATTERN_SYNTAX > {}; + struct pattern_white_space : binary_property< UCHAR_PATTERN_WHITE_SPACE > {}; + struct posix_alnum : binary_property< UCHAR_POSIX_ALNUM > {}; + struct posix_blank : binary_property< UCHAR_POSIX_BLANK > {}; + struct posix_graph : binary_property< UCHAR_POSIX_GRAPH > {}; + struct posix_print : binary_property< UCHAR_POSIX_PRINT > {}; + struct posix_xdigit : binary_property< UCHAR_POSIX_XDIGIT > {}; + struct quotation_mark : binary_property< UCHAR_QUOTATION_MARK > {}; + struct radical : binary_property< UCHAR_RADICAL > {}; + struct s_term : binary_property< UCHAR_S_TERM > {}; + struct segment_starter : binary_property< UCHAR_SEGMENT_STARTER > {}; + struct soft_dotted : binary_property< UCHAR_SOFT_DOTTED > {}; + struct terminal_punctuation : binary_property< UCHAR_TERMINAL_PUNCTUATION > {}; + struct unified_ideograph : binary_property< UCHAR_UNIFIED_IDEOGRAPH > {}; + struct uppercase : binary_property< UCHAR_UPPERCASE > {}; + struct variation_selector : binary_property< UCHAR_VARIATION_SELECTOR > {}; + struct white_space : binary_property< UCHAR_WHITE_SPACE > {}; + struct xid_continue : binary_property< UCHAR_XID_CONTINUE > {}; + struct xid_start : binary_property< UCHAR_XID_START > {}; + + template< UCharDirection V > struct bidi_class : property_value< UCHAR_BIDI_CLASS, V > {}; + template< UBlockCode V > struct block : property_value< UCHAR_BLOCK, V > {}; + template< UDecompositionType V > struct decomposition_type : property_value< UCHAR_DECOMPOSITION_TYPE, V > {}; + template< UEastAsianWidth V > struct east_asian_width : property_value< UCHAR_EAST_ASIAN_WIDTH, V > {}; + template< UCharCategory V > struct general_category : property_value< UCHAR_GENERAL_CATEGORY, V > {}; + template< UGraphemeClusterBreak V > struct grapheme_cluster_break : property_value< UCHAR_GRAPHEME_CLUSTER_BREAK, V > {}; + template< UHangulSyllableType V > struct hangul_syllable_type : property_value< UCHAR_HANGUL_SYLLABLE_TYPE, V > {}; + template< UJoiningGroup V > struct joining_group : property_value< UCHAR_JOINING_GROUP, V > {}; + template< UJoiningType V > struct joining_type : property_value< UCHAR_JOINING_TYPE, V > {}; + template< ULineBreak V > struct line_break : property_value< UCHAR_LINE_BREAK, V > {}; + // UNormalizationCheckResult requires an additional header : + // template< UNormalizationCheckResult V > struct nfc_quick_check : property_value< UCHAR_NFC_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfd_quick_check : property_value< UCHAR_NFD_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfkc_quick_check : property_value< UCHAR_NFKC_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfkd_quick_check : property_value< UCHAR_NFKD_QUICK_CHECK, V > {}; + template< UNumericType V > struct numeric_type : property_value< UCHAR_NUMERIC_TYPE, V > {}; + template< USentenceBreak V > struct sentence_break : property_value< UCHAR_SENTENCE_BREAK, V > {}; + template< UWordBreakValues V > struct word_break : property_value< UCHAR_WORD_BREAK, V > {}; + + template< std::uint8_t V > struct canonical_combining_class : property_value< UCHAR_CANONICAL_COMBINING_CLASS, V > {}; + template< std::uint8_t V > struct lead_canonical_combining_class : property_value< UCHAR_LEAD_CANONICAL_COMBINING_CLASS, V > {}; + template< std::uint8_t V > struct trail_canonical_combining_class : property_value< UCHAR_TRAIL_CANONICAL_COMBINING_CLASS, V > {}; + // clang-format on + + } // namespace utf32_be::icu + + namespace utf32_le::icu + { + template< UProperty P, bool V = true > + struct binary_property + : internal::icu::binary_property< internal::peek_utf32_le, P, V > + {}; + + template< UProperty P, int V > + struct property_value + : internal::icu::property_value< internal::peek_utf32_le, P, V > + {}; + + // clang-format off + struct alphabetic : binary_property< UCHAR_ALPHABETIC > {}; + struct ascii_hex_digit : binary_property< UCHAR_ASCII_HEX_DIGIT > {}; + struct bidi_control : binary_property< UCHAR_BIDI_CONTROL > {}; + struct bidi_mirrored : binary_property< UCHAR_BIDI_MIRRORED > {}; + struct case_sensitive : binary_property< UCHAR_CASE_SENSITIVE > {}; + struct dash : binary_property< UCHAR_DASH > {}; + struct default_ignorable_code_point : binary_property< UCHAR_DEFAULT_IGNORABLE_CODE_POINT > {}; + struct deprecated : binary_property< UCHAR_DEPRECATED > {}; + struct diacritic : binary_property< UCHAR_DIACRITIC > {}; + struct extender : binary_property< UCHAR_EXTENDER > {}; + struct full_composition_exclusion : binary_property< UCHAR_FULL_COMPOSITION_EXCLUSION > {}; + struct grapheme_base : binary_property< UCHAR_GRAPHEME_BASE > {}; + struct grapheme_extend : binary_property< UCHAR_GRAPHEME_EXTEND > {}; + struct grapheme_link : binary_property< UCHAR_GRAPHEME_LINK > {}; + struct hex_digit : binary_property< UCHAR_HEX_DIGIT > {}; + struct hyphen : binary_property< UCHAR_HYPHEN > {}; + struct id_continue : binary_property< UCHAR_ID_CONTINUE > {}; + struct id_start : binary_property< UCHAR_ID_START > {}; + struct ideographic : binary_property< UCHAR_IDEOGRAPHIC > {}; + struct ids_binary_operator : binary_property< UCHAR_IDS_BINARY_OPERATOR > {}; + struct ids_trinary_operator : binary_property< UCHAR_IDS_TRINARY_OPERATOR > {}; + struct join_control : binary_property< UCHAR_JOIN_CONTROL > {}; + struct logical_order_exception : binary_property< UCHAR_LOGICAL_ORDER_EXCEPTION > {}; + struct lowercase : binary_property< UCHAR_LOWERCASE > {}; + struct math : binary_property< UCHAR_MATH > {}; + struct nfc_inert : binary_property< UCHAR_NFC_INERT > {}; + struct nfd_inert : binary_property< UCHAR_NFD_INERT > {}; + struct nfkc_inert : binary_property< UCHAR_NFKC_INERT > {}; + struct nfkd_inert : binary_property< UCHAR_NFKD_INERT > {}; + struct noncharacter_code_point : binary_property< UCHAR_NONCHARACTER_CODE_POINT > {}; + struct pattern_syntax : binary_property< UCHAR_PATTERN_SYNTAX > {}; + struct pattern_white_space : binary_property< UCHAR_PATTERN_WHITE_SPACE > {}; + struct posix_alnum : binary_property< UCHAR_POSIX_ALNUM > {}; + struct posix_blank : binary_property< UCHAR_POSIX_BLANK > {}; + struct posix_graph : binary_property< UCHAR_POSIX_GRAPH > {}; + struct posix_print : binary_property< UCHAR_POSIX_PRINT > {}; + struct posix_xdigit : binary_property< UCHAR_POSIX_XDIGIT > {}; + struct quotation_mark : binary_property< UCHAR_QUOTATION_MARK > {}; + struct radical : binary_property< UCHAR_RADICAL > {}; + struct s_term : binary_property< UCHAR_S_TERM > {}; + struct segment_starter : binary_property< UCHAR_SEGMENT_STARTER > {}; + struct soft_dotted : binary_property< UCHAR_SOFT_DOTTED > {}; + struct terminal_punctuation : binary_property< UCHAR_TERMINAL_PUNCTUATION > {}; + struct unified_ideograph : binary_property< UCHAR_UNIFIED_IDEOGRAPH > {}; + struct uppercase : binary_property< UCHAR_UPPERCASE > {}; + struct variation_selector : binary_property< UCHAR_VARIATION_SELECTOR > {}; + struct white_space : binary_property< UCHAR_WHITE_SPACE > {}; + struct xid_continue : binary_property< UCHAR_XID_CONTINUE > {}; + struct xid_start : binary_property< UCHAR_XID_START > {}; + + template< UCharDirection V > struct bidi_class : property_value< UCHAR_BIDI_CLASS, V > {}; + template< UBlockCode V > struct block : property_value< UCHAR_BLOCK, V > {}; + template< UDecompositionType V > struct decomposition_type : property_value< UCHAR_DECOMPOSITION_TYPE, V > {}; + template< UEastAsianWidth V > struct east_asian_width : property_value< UCHAR_EAST_ASIAN_WIDTH, V > {}; + template< UCharCategory V > struct general_category : property_value< UCHAR_GENERAL_CATEGORY, V > {}; + template< UGraphemeClusterBreak V > struct grapheme_cluster_break : property_value< UCHAR_GRAPHEME_CLUSTER_BREAK, V > {}; + template< UHangulSyllableType V > struct hangul_syllable_type : property_value< UCHAR_HANGUL_SYLLABLE_TYPE, V > {}; + template< UJoiningGroup V > struct joining_group : property_value< UCHAR_JOINING_GROUP, V > {}; + template< UJoiningType V > struct joining_type : property_value< UCHAR_JOINING_TYPE, V > {}; + template< ULineBreak V > struct line_break : property_value< UCHAR_LINE_BREAK, V > {}; + // UNormalizationCheckResult requires an additional header : + // template< UNormalizationCheckResult V > struct nfc_quick_check : property_value< UCHAR_NFC_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfd_quick_check : property_value< UCHAR_NFD_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfkc_quick_check : property_value< UCHAR_NFKC_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfkd_quick_check : property_value< UCHAR_NFKD_QUICK_CHECK, V > {}; + template< UNumericType V > struct numeric_type : property_value< UCHAR_NUMERIC_TYPE, V > {}; + template< USentenceBreak V > struct sentence_break : property_value< UCHAR_SENTENCE_BREAK, V > {}; + template< UWordBreakValues V > struct word_break : property_value< UCHAR_WORD_BREAK, V > {}; + + template< std::uint8_t V > struct canonical_combining_class : property_value< UCHAR_CANONICAL_COMBINING_CLASS, V > {}; + template< std::uint8_t V > struct lead_canonical_combining_class : property_value< UCHAR_LEAD_CANONICAL_COMBINING_CLASS, V > {}; + template< std::uint8_t V > struct trail_canonical_combining_class : property_value< UCHAR_TRAIL_CANONICAL_COMBINING_CLASS, V > {}; + // clang-format on + + } // namespace utf32_le::icu + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/icu/utf8.hpp b/pxr/base/pegtl/pegtl/contrib/icu/utf8.hpp new file mode 100644 index 0000000000..19f3e02051 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/icu/utf8.hpp @@ -0,0 +1,103 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_ICU_UTF8_HPP +#define PXR_PEGTL_CONTRIB_ICU_UTF8_HPP + +#include "internal.hpp" + +#include "../../config.hpp" +#include "../../utf8.hpp" + +#include "../../internal/peek_utf8.hpp" + +namespace PXR_PEGTL_NAMESPACE::utf8::icu +{ + template< UProperty P, bool V = true > + struct binary_property + : internal::icu::binary_property< internal::peek_utf8, P, V > + {}; + + template< UProperty P, int V > + struct property_value + : internal::icu::property_value< internal::peek_utf8, P, V > + {}; + + // clang-format off + struct alphabetic : binary_property< UCHAR_ALPHABETIC > {}; + struct ascii_hex_digit : binary_property< UCHAR_ASCII_HEX_DIGIT > {}; + struct bidi_control : binary_property< UCHAR_BIDI_CONTROL > {}; + struct bidi_mirrored : binary_property< UCHAR_BIDI_MIRRORED > {}; + struct case_sensitive : binary_property< UCHAR_CASE_SENSITIVE > {}; + struct dash : binary_property< UCHAR_DASH > {}; + struct default_ignorable_code_point : binary_property< UCHAR_DEFAULT_IGNORABLE_CODE_POINT > {}; + struct deprecated : binary_property< UCHAR_DEPRECATED > {}; + struct diacritic : binary_property< UCHAR_DIACRITIC > {}; + struct extender : binary_property< UCHAR_EXTENDER > {}; + struct full_composition_exclusion : binary_property< UCHAR_FULL_COMPOSITION_EXCLUSION > {}; + struct grapheme_base : binary_property< UCHAR_GRAPHEME_BASE > {}; + struct grapheme_extend : binary_property< UCHAR_GRAPHEME_EXTEND > {}; + struct grapheme_link : binary_property< UCHAR_GRAPHEME_LINK > {}; + struct hex_digit : binary_property< UCHAR_HEX_DIGIT > {}; + struct hyphen : binary_property< UCHAR_HYPHEN > {}; + struct id_continue : binary_property< UCHAR_ID_CONTINUE > {}; + struct id_start : binary_property< UCHAR_ID_START > {}; + struct ideographic : binary_property< UCHAR_IDEOGRAPHIC > {}; + struct ids_binary_operator : binary_property< UCHAR_IDS_BINARY_OPERATOR > {}; + struct ids_trinary_operator : binary_property< UCHAR_IDS_TRINARY_OPERATOR > {}; + struct join_control : binary_property< UCHAR_JOIN_CONTROL > {}; + struct logical_order_exception : binary_property< UCHAR_LOGICAL_ORDER_EXCEPTION > {}; + struct lowercase : binary_property< UCHAR_LOWERCASE > {}; + struct math : binary_property< UCHAR_MATH > {}; + struct nfc_inert : binary_property< UCHAR_NFC_INERT > {}; + struct nfd_inert : binary_property< UCHAR_NFD_INERT > {}; + struct nfkc_inert : binary_property< UCHAR_NFKC_INERT > {}; + struct nfkd_inert : binary_property< UCHAR_NFKD_INERT > {}; + struct noncharacter_code_point : binary_property< UCHAR_NONCHARACTER_CODE_POINT > {}; + struct pattern_syntax : binary_property< UCHAR_PATTERN_SYNTAX > {}; + struct pattern_white_space : binary_property< UCHAR_PATTERN_WHITE_SPACE > {}; + struct posix_alnum : binary_property< UCHAR_POSIX_ALNUM > {}; + struct posix_blank : binary_property< UCHAR_POSIX_BLANK > {}; + struct posix_graph : binary_property< UCHAR_POSIX_GRAPH > {}; + struct posix_print : binary_property< UCHAR_POSIX_PRINT > {}; + struct posix_xdigit : binary_property< UCHAR_POSIX_XDIGIT > {}; + struct quotation_mark : binary_property< UCHAR_QUOTATION_MARK > {}; + struct radical : binary_property< UCHAR_RADICAL > {}; + struct s_term : binary_property< UCHAR_S_TERM > {}; + struct segment_starter : binary_property< UCHAR_SEGMENT_STARTER > {}; + struct soft_dotted : binary_property< UCHAR_SOFT_DOTTED > {}; + struct terminal_punctuation : binary_property< UCHAR_TERMINAL_PUNCTUATION > {}; + struct unified_ideograph : binary_property< UCHAR_UNIFIED_IDEOGRAPH > {}; + struct uppercase : binary_property< UCHAR_UPPERCASE > {}; + struct variation_selector : binary_property< UCHAR_VARIATION_SELECTOR > {}; + struct white_space : binary_property< UCHAR_WHITE_SPACE > {}; + struct xid_continue : binary_property< UCHAR_XID_CONTINUE > {}; + struct xid_start : binary_property< UCHAR_XID_START > {}; + + template< UCharDirection V > struct bidi_class : property_value< UCHAR_BIDI_CLASS, V > {}; + template< UBlockCode V > struct block : property_value< UCHAR_BLOCK, V > {}; + template< UDecompositionType V > struct decomposition_type : property_value< UCHAR_DECOMPOSITION_TYPE, V > {}; + template< UEastAsianWidth V > struct east_asian_width : property_value< UCHAR_EAST_ASIAN_WIDTH, V > {}; + template< UCharCategory V > struct general_category : property_value< UCHAR_GENERAL_CATEGORY, V > {}; + template< UGraphemeClusterBreak V > struct grapheme_cluster_break : property_value< UCHAR_GRAPHEME_CLUSTER_BREAK, V > {}; + template< UHangulSyllableType V > struct hangul_syllable_type : property_value< UCHAR_HANGUL_SYLLABLE_TYPE, V > {}; + template< UJoiningGroup V > struct joining_group : property_value< UCHAR_JOINING_GROUP, V > {}; + template< UJoiningType V > struct joining_type : property_value< UCHAR_JOINING_TYPE, V > {}; + template< ULineBreak V > struct line_break : property_value< UCHAR_LINE_BREAK, V > {}; + // UNormalizationCheckResult requires an additional header : + // template< UNormalizationCheckResult V > struct nfc_quick_check : property_value< UCHAR_NFC_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfd_quick_check : property_value< UCHAR_NFD_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfkc_quick_check : property_value< UCHAR_NFKC_QUICK_CHECK, V > {}; + // template< UNormalizationCheckResult V > struct nfkd_quick_check : property_value< UCHAR_NFKD_QUICK_CHECK, V > {}; + template< UNumericType V > struct numeric_type : property_value< UCHAR_NUMERIC_TYPE, V > {}; + template< USentenceBreak V > struct sentence_break : property_value< UCHAR_SENTENCE_BREAK, V > {}; + template< UWordBreakValues V > struct word_break : property_value< UCHAR_WORD_BREAK, V > {}; + + template< std::uint8_t V > struct canonical_combining_class : property_value< UCHAR_CANONICAL_COMBINING_CLASS, V > {}; + template< std::uint8_t V > struct lead_canonical_combining_class : property_value< UCHAR_LEAD_CANONICAL_COMBINING_CLASS, V > {}; + template< std::uint8_t V > struct trail_canonical_combining_class : property_value< UCHAR_TRAIL_CANONICAL_COMBINING_CLASS, V > {}; + // clang-format on + +} // namespace PXR_PEGTL_NAMESPACE::utf8::icu + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/if_then.hpp b/pxr/base/pegtl/pegtl/contrib/if_then.hpp new file mode 100644 index 0000000000..aaa33f71e7 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/if_then.hpp @@ -0,0 +1,56 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_IF_THEN_HPP +#define PXR_PEGTL_CONTRIB_IF_THEN_HPP + +#include + +#include "../config.hpp" + +#include "../internal/enable_control.hpp" +#include "../internal/failure.hpp" +#include "../internal/if_then_else.hpp" +#include "../internal/seq.hpp" +#include "../internal/success.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename Cond, typename Then > + struct if_pair + {}; + + template< typename... Pairs > + struct if_then; + + template< typename Cond, typename Then, typename... Pairs > + struct if_then< if_pair< Cond, Then >, Pairs... > + : if_then_else< Cond, Then, if_then< Pairs... > > + { + template< typename ElseCond, typename... Thens > + using else_if_then = if_then< if_pair< Cond, Then >, Pairs..., if_pair< ElseCond, seq< Thens... > > >; + + template< typename... Thens > + using else_then = if_then_else< Cond, Then, if_then< Pairs..., if_pair< success, seq< Thens... > > > >; + }; + + template<> + struct if_then<> + : failure + {}; + + template< typename... Pairs > + inline constexpr bool enable_control< if_then< Pairs... > > = false; + + } // namespace internal + + template< typename Cond, typename... Thens > + struct if_then + : internal::if_then< internal::if_pair< Cond, internal::seq< Thens... > > > + {}; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/instantiate.hpp b/pxr/base/pegtl/pegtl/contrib/instantiate.hpp new file mode 100644 index 0000000000..9b26e25350 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/instantiate.hpp @@ -0,0 +1,38 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INSTANTIATE_HPP +#define PXR_PEGTL_CONTRIB_INSTANTIATE_HPP + +#include "../config.hpp" + +#include "../apply_mode.hpp" +#include "../match.hpp" +#include "../nothing.hpp" +#include "../rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< typename T > + struct instantiate + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + const T t( static_cast< const ParseInput& >( in ), st... ); + return PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/integer.hpp b/pxr/base/pegtl/pegtl/contrib/integer.hpp new file mode 100644 index 0000000000..6df142c5a2 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/integer.hpp @@ -0,0 +1,468 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTEGER_HPP +#define PXR_PEGTL_CONTRIB_INTEGER_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/contrib/integer.hpp" +#else + +#include +#include + +#include +#include +#include + +#include "../ascii.hpp" +#include "../parse.hpp" +#include "../parse_error.hpp" +#include "../rules.hpp" + +#include "analyze_traits.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + struct unsigned_rule_old + : plus< digit > + { + // Pre-3.0 version of this rule. + }; + + struct unsigned_rule_new + : if_then_else< one< '0' >, not_at< digit >, plus< digit > > + { + // New version that does not allow leading zeros. + }; + + struct signed_rule_old + : seq< opt< one< '-', '+' > >, plus< digit > > + { + // Pre-3.0 version of this rule. + }; + + struct signed_rule_new + : seq< opt< one< '-', '+' > >, if_then_else< one< '0' >, not_at< digit >, plus< digit > > > + { + // New version that does not allow leading zeros. + }; + + struct signed_rule_bis + : seq< opt< one< '-' > >, if_then_else< one< '0' >, not_at< digit >, plus< digit > > > + {}; + + struct signed_rule_ter + : seq< one< '-', '+' >, if_then_else< one< '0' >, not_at< digit >, plus< digit > > > + {}; + + namespace internal + { + [[nodiscard]] constexpr bool is_digit( const char c ) noexcept + { + // We don't use std::isdigit() because it might + // return true for other values on MS platforms. + + return ( '0' <= c ) && ( c <= '9' ); + } + + template< typename Integer, Integer Maximum = ( std::numeric_limits< Integer >::max )() > + [[nodiscard]] constexpr bool accumulate_digit( Integer& result, const char digit ) noexcept + { + // Assumes that digit is a digit as per is_digit(); returns false on overflow. + + static_assert( std::is_integral_v< Integer > ); + + constexpr Integer cutoff = Maximum / 10; + constexpr Integer cutlim = Maximum % 10; + + const Integer c = digit - '0'; + + if( ( result > cutoff ) || ( ( result == cutoff ) && ( c > cutlim ) ) ) { + return false; + } + result *= 10; + result += c; + return true; + } + + template< typename Integer, Integer Maximum = ( std::numeric_limits< Integer >::max )() > + [[nodiscard]] constexpr bool accumulate_digits( Integer& result, const std::string_view input ) noexcept + { + // Assumes input is a non-empty sequence of digits; returns false on overflow. + + for( char c : input ) { + if( !accumulate_digit< Integer, Maximum >( result, c ) ) { + return false; + } + } + return true; + } + + template< typename Integer, Integer Maximum = ( std::numeric_limits< Integer >::max )() > + [[nodiscard]] constexpr bool convert_positive( Integer& result, const std::string_view input ) noexcept + { + // Assumes result == 0 and that input is a non-empty sequence of digits; returns false on overflow. + + static_assert( std::is_integral_v< Integer > ); + return accumulate_digits< Integer, Maximum >( result, input ); + } + + template< typename Signed > + [[nodiscard]] constexpr bool convert_negative( Signed& result, const std::string_view input ) noexcept + { + // Assumes result == 0 and that input is a non-empty sequence of digits; returns false on overflow. + + static_assert( std::is_signed_v< Signed > ); + using Unsigned = std::make_unsigned_t< Signed >; + constexpr Unsigned maximum = static_cast< Unsigned >( ( std::numeric_limits< Signed >::max )() ) + 1; + Unsigned temporary = 0; + if( accumulate_digits< Unsigned, maximum >( temporary, input ) ) { + result = static_cast< Signed >( ~temporary ) + 1; + return true; + } + return false; + } + + template< typename Unsigned, Unsigned Maximum = ( std::numeric_limits< Unsigned >::max )() > + [[nodiscard]] constexpr bool convert_unsigned( Unsigned& result, const std::string_view input ) noexcept + { + // Assumes result == 0 and that input is a non-empty sequence of digits; returns false on overflow. + + static_assert( std::is_unsigned_v< Unsigned > ); + return accumulate_digits< Unsigned, Maximum >( result, input ); + } + + template< typename Signed > + [[nodiscard]] constexpr bool convert_signed( Signed& result, const std::string_view input ) noexcept + { + // Assumes result == 0 and that input is an optional sign followed by a non-empty sequence of digits; returns false on overflow. + + static_assert( std::is_signed_v< Signed > ); + if( input[ 0 ] == '-' ) { + return convert_negative< Signed >( result, std::string_view( input.data() + 1, input.size() - 1 ) ); + } + const auto offset = unsigned( input[ 0 ] == '+' ); + return convert_positive< Signed >( result, std::string_view( input.data() + offset, input.size() - offset ) ); + } + + template< typename ParseInput > + [[nodiscard]] bool match_unsigned( ParseInput& in ) noexcept( noexcept( in.empty() ) ) + { + if( !in.empty() ) { + const char c = in.peek_char(); + if( is_digit( c ) ) { + in.bump_in_this_line(); + if( c == '0' ) { + return in.empty() || ( !is_digit( in.peek_char() ) ); + } + while( ( !in.empty() ) && is_digit( in.peek_char() ) ) { + in.bump_in_this_line(); + } + return true; + } + } + return false; + } + + template< typename ParseInput, + typename Unsigned, + Unsigned Maximum = ( std::numeric_limits< Unsigned >::max )() > + [[nodiscard]] bool match_and_convert_unsigned_with_maximum_throws( ParseInput& in, Unsigned& st ) + { + // Assumes st == 0. + + if( !in.empty() ) { + char c = in.peek_char(); + if( is_digit( c ) ) { + if( c == '0' ) { + in.bump_in_this_line(); + return in.empty() || ( !is_digit( in.peek_char() ) ); + } + do { + if( !accumulate_digit< Unsigned, Maximum >( st, c ) ) { + throw PXR_PEGTL_NAMESPACE::parse_error( "integer overflow", in ); + } + in.bump_in_this_line(); + } while( ( !in.empty() ) && is_digit( c = in.peek_char() ) ); + return true; + } + } + return false; + } + + template< typename ParseInput, + typename Unsigned, + Unsigned Maximum = ( std::numeric_limits< Unsigned >::max )() > + [[nodiscard]] bool match_and_convert_unsigned_with_maximum_nothrow( ParseInput& in, Unsigned& st ) + { + // Assumes st == 0. + + if( !in.empty() ) { + char c = in.peek_char(); + if( c == '0' ) { + if( ( in.size( 2 ) < 2 ) || ( !is_digit( in.peek_char( 1 ) ) ) ) { + in.bump_in_this_line(); + return true; + } + return false; + } + if( is_digit( c ) ) { + unsigned b = 0; + + do { + if( !accumulate_digit< Unsigned, Maximum >( st, c ) ) { + return false; + } + ++b; + } while( ( !in.empty() ) && is_digit( c = in.peek_char( b ) ) ); + in.bump_in_this_line( b ); + return true; + } + } + return false; + } + + } // namespace internal + + struct unsigned_action + { + // Assumes that 'in' contains a non-empty sequence of ASCII digits. + + template< typename ActionInput, typename Unsigned > + static void apply( const ActionInput& in, Unsigned& st ) + { + // This function "only" offers basic exception safety. + st = 0; + if( !internal::convert_unsigned( st, in.string_view() ) ) { + throw parse_error( "unsigned integer overflow", in ); + } + } + }; + + struct unsigned_rule + { + using rule_t = unsigned_rule; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.empty() ) ) + { + return internal::match_unsigned( in ); // Does not check for any overflow. + } + }; + + struct unsigned_rule_with_action + { + using rule_t = unsigned_rule_with_action; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static auto match( ParseInput& in, States&&... /*unused*/ ) noexcept( noexcept( in.empty() ) ) -> std::enable_if_t< A == apply_mode::nothing, bool > + { + return internal::match_unsigned( in ); // Does not check for any overflow. + } + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename Unsigned > + [[nodiscard]] static auto match( ParseInput& in, Unsigned& st ) -> std::enable_if_t< ( A == apply_mode::action ) && std::is_unsigned_v< Unsigned >, bool > + { + // This function "only" offers basic exception safety. + st = 0; + return internal::match_and_convert_unsigned_with_maximum_throws( in, st ); // Throws on overflow. + } + }; + + template< typename Unsigned, Unsigned Maximum > + struct maximum_action + { + // Assumes that 'in' contains a non-empty sequence of ASCII digits. + + static_assert( std::is_unsigned_v< Unsigned > ); + + template< typename ActionInput, typename Unsigned2 > + static void apply( const ActionInput& in, Unsigned2& st ) + { + // This function "only" offers basic exception safety. + st = 0; + if( !internal::convert_unsigned< Unsigned, Maximum >( st, in.string_view() ) ) { + throw parse_error( "unsigned integer overflow", in ); + } + } + }; + + template< typename Unsigned, Unsigned Maximum = ( std::numeric_limits< Unsigned >::max )() > + struct maximum_rule + { + using rule_t = maximum_rule; + using subs_t = empty_list; + + static_assert( std::is_unsigned_v< Unsigned > ); + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) + { + Unsigned st = 0; + return internal::match_and_convert_unsigned_with_maximum_nothrow< ParseInput, Unsigned, Maximum >( in, st ); + } + }; + + template< typename Unsigned, Unsigned Maximum = ( std::numeric_limits< Unsigned >::max )() > + struct maximum_rule_with_action + { + using rule_t = maximum_rule_with_action; + using subs_t = empty_list; + + static_assert( std::is_unsigned_v< Unsigned > ); + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static auto match( ParseInput& in, States&&... /*unused*/ ) -> std::enable_if_t< A == apply_mode::nothing, bool > + { + Unsigned st = 0; + return internal::match_and_convert_unsigned_with_maximum_throws< ParseInput, Unsigned, Maximum >( in, st ); + } + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename Unsigned2 > + [[nodiscard]] static auto match( ParseInput& in, Unsigned2& st ) -> std::enable_if_t< ( A == apply_mode::action ) && std::is_same_v< Unsigned, Unsigned2 >, bool > + { + // This function "only" offers basic exception safety. + st = 0; + return internal::match_and_convert_unsigned_with_maximum_throws< ParseInput, Unsigned, Maximum >( in, st ); + } + }; + + struct signed_action + { + // Assumes that 'in' contains a non-empty sequence of ASCII digits, + // with optional leading sign; with sign, in.size() must be >= 2. + + template< typename ActionInput, typename Signed > + static void apply( const ActionInput& in, Signed& st ) + { + // This function "only" offers basic exception safety. + st = 0; + if( !internal::convert_signed( st, in.string_view() ) ) { + throw parse_error( "signed integer overflow", in ); + } + } + }; + + struct signed_rule + { + using rule_t = signed_rule; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.empty() ) ) + { + return PXR_PEGTL_NAMESPACE::parse< signed_rule_new >( in ); // Does not check for any overflow. + } + }; + + namespace internal + { + template< typename Rule > + struct signed_action_action + : nothing< Rule > + {}; + + template<> + struct signed_action_action< signed_rule_new > + : signed_action + {}; + + } // namespace internal + + struct signed_rule_with_action + { + using rule_t = signed_rule_with_action; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static auto match( ParseInput& in, States&&... /*unused*/ ) noexcept( noexcept( in.empty() ) ) -> std::enable_if_t< A == apply_mode::nothing, bool > + { + return PXR_PEGTL_NAMESPACE::parse< signed_rule_new >( in ); // Does not check for any overflow. + } + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename Signed > + [[nodiscard]] static auto match( ParseInput& in, Signed& st ) -> std::enable_if_t< ( A == apply_mode::action ) && std::is_signed_v< Signed >, bool > + { + return PXR_PEGTL_NAMESPACE::parse< signed_rule_new, internal::signed_action_action >( in, st ); // Throws on overflow. + } + }; + + template< typename Name > + struct analyze_traits< Name, unsigned_rule > + : analyze_any_traits<> + {}; + + template< typename Name > + struct analyze_traits< Name, unsigned_rule_with_action > + : analyze_any_traits<> + {}; + + template< typename Name, typename Integer, Integer Maximum > + struct analyze_traits< Name, maximum_rule< Integer, Maximum > > + : analyze_any_traits<> + {}; + + template< typename Name, typename Integer, Integer Maximum > + struct analyze_traits< Name, maximum_rule_with_action< Integer, Maximum > > + : analyze_any_traits<> + {}; + + template< typename Name > + struct analyze_traits< Name, signed_rule > + : analyze_any_traits<> + {}; + + template< typename Name > + struct analyze_traits< Name, signed_rule_with_action > + : analyze_any_traits<> + {}; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/endian.hpp b/pxr/base/pegtl/pegtl/contrib/internal/endian.hpp new file mode 100644 index 0000000000..8f47bf1343 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/endian.hpp @@ -0,0 +1,77 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_ENDIAN_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_ENDIAN_HPP + +#include +#include + +#include "../../config.hpp" + +#if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( __CYGWIN__ ) +#include "endian_win.hpp" +#else +#include "endian_gcc.hpp" +#endif + +namespace PXR_PEGTL_NAMESPACE::internal +{ + enum class endian + { +#if defined( _WIN32 ) + little = 0, + big = 1, + native = little +#elif defined( __BYTE_ORDER__ ) + little = __ORDER_LITTLE_ENDIAN__, + big = __ORDER_BIG_ENDIAN__, + native = __BYTE_ORDER__ +#else +#error Unknown endianness. +#endif + }; + + template< typename N > + [[nodiscard]] N h_to_be( const N n ) noexcept + { + return N( to_and_from_be< sizeof( N ) >::convert( n ) ); + } + + template< typename N > + [[nodiscard]] N be_to_h( const N n ) noexcept + { + return h_to_be( n ); + } + + template< typename N > + [[nodiscard]] N be_to_h( const void* p ) noexcept + { + N n; + std::memcpy( &n, p, sizeof( n ) ); + return internal::be_to_h( n ); + } + + template< typename N > + [[nodiscard]] N h_to_le( const N n ) noexcept + { + return N( to_and_from_le< sizeof( N ) >::convert( n ) ); + } + + template< typename N > + [[nodiscard]] N le_to_h( const N n ) noexcept + { + return h_to_le( n ); + } + + template< typename N > + [[nodiscard]] N le_to_h( const void* p ) noexcept + { + N n; + std::memcpy( &n, p, sizeof( n ) ); + return internal::le_to_h( n ); + } + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/endian_gcc.hpp b/pxr/base/pegtl/pegtl/contrib/internal/endian_gcc.hpp new file mode 100644 index 0000000000..a531dc0e46 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/endian_gcc.hpp @@ -0,0 +1,198 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_ENDIAN_GCC_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_ENDIAN_GCC_HPP + +#include +#include + +namespace PXR_PEGTL_NAMESPACE::internal +{ +#if !defined( __BYTE_ORDER__ ) +#error No byte order defined! +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + + template< std::size_t S > + struct to_and_from_be + { + template< typename T > + [[nodiscard]] static T convert( const T n ) noexcept + { + return n; + } + }; + + template< std::size_t S > + struct to_and_from_le; + + template<> + struct to_and_from_le< 1 > + { + [[nodiscard]] static std::uint8_t convert( const std::uint8_t n ) noexcept + { + return n; + } + + [[nodiscard]] static std::int8_t convert( const std::int8_t n ) noexcept + { + return n; + } + }; + + template<> + struct to_and_from_le< 2 > + { + [[nodiscard]] static std::int16_t convert( const std::int16_t n ) noexcept + { + return static_cast< std::int16_t >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) ); + } + + [[nodiscard]] static std::uint16_t convert( const std::uint16_t n ) noexcept + { + return __builtin_bswap16( n ); + } + }; + + template<> + struct to_and_from_le< 4 > + { + [[nodiscard]] static float convert( float n ) noexcept + { + std::uint32_t u; + std::memcpy( &u, &n, 4 ); + u = convert( u ); + std::memcpy( &n, &u, 4 ); + return n; + } + + [[nodiscard]] static std::int32_t convert( const std::int32_t n ) noexcept + { + return static_cast< std::int32_t >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) ); + } + + [[nodiscard]] static std::uint32_t convert( const std::uint32_t n ) noexcept + { + return __builtin_bswap32( n ); + } + }; + + template<> + struct to_and_from_le< 8 > + { + [[nodiscard]] static double convert( double n ) noexcept + { + std::uint64_t u; + std::memcpy( &u, &n, 8 ); + u = convert( u ); + std::memcpy( &n, &u, 8 ); + return n; + } + + [[nodiscard]] static std::int64_t convert( const std::int64_t n ) noexcept + { + return static_cast< std::int64_t >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) ); + } + + [[nodiscard]] static std::uint64_t convert( const std::uint64_t n ) noexcept + { + return __builtin_bswap64( n ); + } + }; + +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + + template< std::size_t S > + struct to_and_from_le + { + template< typename T > + [[nodiscard]] static T convert( const T n ) noexcept + { + return n; + } + }; + + template< std::size_t S > + struct to_and_from_be; + + template<> + struct to_and_from_be< 1 > + { + [[nodiscard]] static std::int8_t convert( const std::int8_t n ) noexcept + { + return n; + } + + [[nodiscard]] static std::uint8_t convert( const std::uint8_t n ) noexcept + { + return n; + } + }; + + template<> + struct to_and_from_be< 2 > + { + [[nodiscard]] static std::int16_t convert( const std::int16_t n ) noexcept + { + return static_cast< std::int16_t >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) ); + } + + [[nodiscard]] static std::uint16_t convert( const std::uint16_t n ) noexcept + { + return __builtin_bswap16( n ); + } + }; + + template<> + struct to_and_from_be< 4 > + { + [[nodiscard]] static float convert( float n ) noexcept + { + std::uint32_t u; + std::memcpy( &u, &n, 4 ); + u = convert( u ); + std::memcpy( &n, &u, 4 ); + return n; + } + + [[nodiscard]] static std::int32_t convert( const std::int32_t n ) noexcept + { + return static_cast< std::int32_t >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) ); + } + + [[nodiscard]] static std::uint32_t convert( const std::uint32_t n ) noexcept + { + return __builtin_bswap32( n ); + } + }; + + template<> + struct to_and_from_be< 8 > + { + [[nodiscard]] static double convert( double n ) noexcept + { + std::uint64_t u; + std::memcpy( &u, &n, 8 ); + u = convert( u ); + std::memcpy( &n, &u, 8 ); + return n; + } + + [[nodiscard]] static std::int64_t convert( const std::int64_t n ) noexcept + { + return static_cast< std::int64_t >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) ); + } + + [[nodiscard]] static std::uint64_t convert( const std::uint64_t n ) noexcept + { + return __builtin_bswap64( n ); + } + }; + +#else +#error Unknown host byte order! +#endif + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/endian_win.hpp b/pxr/base/pegtl/pegtl/contrib/internal/endian_win.hpp new file mode 100644 index 0000000000..41b706ce23 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/endian_win.hpp @@ -0,0 +1,102 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_ENDIAN_WIN_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_ENDIAN_WIN_HPP + +#include +#include +#include + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< std::size_t S > + struct to_and_from_le + { + template< typename T > + [[nodiscard]] static T convert( const T t ) noexcept + { + return t; + } + }; + + template< std::size_t S > + struct to_and_from_be; + + template<> + struct to_and_from_be< 1 > + { + [[nodiscard]] static std::int8_t convert( const std::int8_t n ) noexcept + { + return n; + } + + [[nodiscard]] static std::uint8_t convert( const std::uint8_t n ) noexcept + { + return n; + } + }; + + template<> + struct to_and_from_be< 2 > + { + [[nodiscard]] static std::int16_t convert( const std::int16_t n ) noexcept + { + return std::int16_t( _byteswap_ushort( std::uint16_t( n ) ) ); + } + + [[nodiscard]] static std::uint16_t convert( const std::uint16_t n ) noexcept + { + return _byteswap_ushort( n ); + } + }; + + template<> + struct to_and_from_be< 4 > + { + [[nodiscard]] static float convert( float n ) noexcept + { + std::uint32_t u; + std::memcpy( &u, &n, 4 ); + u = convert( u ); + std::memcpy( &n, &u, 4 ); + return n; + } + + [[nodiscard]] static std::int32_t convert( const std::int32_t n ) noexcept + { + return std::int32_t( _byteswap_ulong( std::uint32_t( n ) ) ); + } + + [[nodiscard]] static std::uint32_t convert( const std::uint32_t n ) noexcept + { + return _byteswap_ulong( n ); + } + }; + + template<> + struct to_and_from_be< 8 > + { + [[nodiscard]] static double convert( double n ) noexcept + { + std::uint64_t u; + std::memcpy( &u, &n, 8 ); + u = convert( u ); + std::memcpy( &n, &u, 8 ); + return n; + } + + [[nodiscard]] static std::int64_t convert( const std::int64_t n ) noexcept + { + return std::int64_t( _byteswap_uint64( std::uint64_t( n ) ) ); + } + + [[nodiscard]] static std::uint64_t convert( const std::uint64_t n ) noexcept + { + return _byteswap_uint64( n ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/peek_mask_uint.hpp b/pxr/base/pegtl/pegtl/contrib/internal/peek_mask_uint.hpp new file mode 100644 index 0000000000..9e5ba39ede --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/peek_mask_uint.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_PEEK_MASK_UINT_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_PEEK_MASK_UINT_HPP + +#include +#include + +#include "../../config.hpp" +#include "../../internal/input_pair.hpp" + +#include "read_uint.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename R, typename R::type M > + struct peek_mask_uint_impl + { + using data_t = typename R::type; + using pair_t = input_pair< data_t >; + + template< typename ParseInput > + [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.size( sizeof( data_t ) ) ) ) + { + if( in.size( sizeof( data_t ) ) < sizeof( data_t ) ) { + return { 0, 0 }; + } + const data_t data = R::read( in.current() ) & M; + return { data, sizeof( data_t ) }; + } + }; + + template< std::uint16_t M > + using peek_mask_uint16_be = peek_mask_uint_impl< read_uint16_be, M >; + + template< std::uint16_t M > + using peek_mask_uint16_le = peek_mask_uint_impl< read_uint16_le, M >; + + template< std::uint32_t M > + using peek_mask_uint32_be = peek_mask_uint_impl< read_uint32_be, M >; + + template< std::uint32_t M > + using peek_mask_uint32_le = peek_mask_uint_impl< read_uint32_le, M >; + + template< std::uint64_t M > + using peek_mask_uint64_be = peek_mask_uint_impl< read_uint64_be, M >; + + template< std::uint64_t M > + using peek_mask_uint64_le = peek_mask_uint_impl< read_uint64_le, M >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/peek_mask_uint8.hpp b/pxr/base/pegtl/pegtl/contrib/internal/peek_mask_uint8.hpp new file mode 100644 index 0000000000..a2a1a9ee19 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/peek_mask_uint8.hpp @@ -0,0 +1,33 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_PEEK_MASK_UINT8_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_PEEK_MASK_UINT8_HPP + +#include +#include + +#include "../../config.hpp" +#include "../../internal/input_pair.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< std::uint8_t M > + struct peek_mask_uint8 + { + using data_t = std::uint8_t; + using pair_t = input_pair< std::uint8_t >; + + template< typename ParseInput > + [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.empty() ) ) + { + if( in.empty() ) { + return { 0, 0 }; + } + return { std::uint8_t( in.peek_uint8() & M ), 1 }; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/peek_uint.hpp b/pxr/base/pegtl/pegtl/contrib/internal/peek_uint.hpp new file mode 100644 index 0000000000..bda64483bd --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/peek_uint.hpp @@ -0,0 +1,45 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_PEEK_UINT_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_PEEK_UINT_HPP + +#include +#include + +#include "../../config.hpp" +#include "../../internal/input_pair.hpp" + +#include "read_uint.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename R > + struct peek_uint_impl + { + using data_t = typename R::type; + using pair_t = input_pair< data_t >; + + template< typename ParseInput > + [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.size( sizeof( data_t ) ) ) ) + { + if( in.size( sizeof( data_t ) ) < sizeof( data_t ) ) { + return { 0, 0 }; + } + const data_t data = R::read( in.current() ); + return { data, sizeof( data_t ) }; + } + }; + + using peek_uint16_be = peek_uint_impl< read_uint16_be >; + using peek_uint16_le = peek_uint_impl< read_uint16_le >; + + using peek_uint32_be = peek_uint_impl< read_uint32_be >; + using peek_uint32_le = peek_uint_impl< read_uint32_le >; + + using peek_uint64_be = peek_uint_impl< read_uint64_be >; + using peek_uint64_le = peek_uint_impl< read_uint64_le >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/peek_uint8.hpp b/pxr/base/pegtl/pegtl/contrib/internal/peek_uint8.hpp new file mode 100644 index 0000000000..f6e915d552 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/peek_uint8.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_PEEK_UINT8_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_PEEK_UINT8_HPP + +#include +#include + +#include "../../config.hpp" +#include "../../internal/input_pair.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct peek_uint8 + { + using data_t = std::uint8_t; + using pair_t = input_pair< std::uint8_t >; + + template< typename ParseInput > + [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.empty() ) ) + { + if( in.empty() ) { + return { 0, 0 }; + } + return { in.peek_uint8(), 1 }; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/peek_utf16.hpp b/pxr/base/pegtl/pegtl/contrib/internal/peek_utf16.hpp new file mode 100644 index 0000000000..3ecc1b9b0a --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/peek_utf16.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_PEEK_UTF16_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_PEEK_UTF16_HPP + +#include + +#include "../../config.hpp" +#include "../../internal/input_pair.hpp" + +#include "read_uint.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename R > + struct peek_utf16_impl + { + using data_t = char32_t; + using pair_t = input_pair< char32_t >; + + using short_t = std::make_unsigned< char16_t >::type; + + static_assert( sizeof( short_t ) == 2 ); + static_assert( sizeof( char16_t ) == 2 ); + + template< typename ParseInput > + [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.size( 4 ) ) ) + { + if( in.size( 2 ) < 2 ) { + return { 0, 0 }; + } + const char32_t t = R::read( in.current() ); + if( ( t < 0xd800 ) || ( t > 0xdfff ) ) { + return { t, 2 }; + } + if( ( t >= 0xdc00 ) || ( in.size( 4 ) < 4 ) ) { + return { 0, 0 }; + } + const char32_t u = R::read( in.current() + 2 ); + if( ( u >= 0xdc00 ) && ( u <= 0xdfff ) ) { + const auto cp = ( ( ( t & 0x03ff ) << 10 ) | ( u & 0x03ff ) ) + 0x10000; + return { cp, 4 }; + } + return { 0, 0 }; + } + }; + + using peek_utf16_be = peek_utf16_impl< read_uint16_be >; + using peek_utf16_le = peek_utf16_impl< read_uint16_le >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/peek_utf32.hpp b/pxr/base/pegtl/pegtl/contrib/internal/peek_utf32.hpp new file mode 100644 index 0000000000..2965f755b9 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/peek_utf32.hpp @@ -0,0 +1,43 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_PEEK_UTF32_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_PEEK_UTF32_HPP + +#include + +#include "../../config.hpp" +#include "../../internal/input_pair.hpp" + +#include "read_uint.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename R > + struct peek_utf32_impl + { + using data_t = char32_t; + using pair_t = input_pair< char32_t >; + + static_assert( sizeof( char32_t ) == 4 ); + + template< typename ParseInput > + [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.size( 4 ) ) ) + { + if( in.size( 4 ) < 4 ) { + return { 0, 0 }; + } + const char32_t t = R::read( in.current() ); + if( ( t <= 0x10ffff ) && !( t >= 0xd800 && t <= 0xdfff ) ) { + return { t, 4 }; + } + return { 0, 0 }; + } + }; + + using peek_utf32_be = peek_utf32_impl< read_uint32_be >; + using peek_utf32_le = peek_utf32_impl< read_uint32_le >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/read_uint.hpp b/pxr/base/pegtl/pegtl/contrib/internal/read_uint.hpp new file mode 100644 index 0000000000..a2a08a2855 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/read_uint.hpp @@ -0,0 +1,77 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_READ_UINT_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_READ_UINT_HPP + +#include + +#include "../../config.hpp" + +#include "endian.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct read_uint16_be + { + using type = std::uint16_t; + + [[nodiscard]] static std::uint16_t read( const void* d ) noexcept + { + return be_to_h< std::uint16_t >( d ); + } + }; + + struct read_uint16_le + { + using type = std::uint16_t; + + [[nodiscard]] static std::uint16_t read( const void* d ) noexcept + { + return le_to_h< std::uint16_t >( d ); + } + }; + + struct read_uint32_be + { + using type = std::uint32_t; + + [[nodiscard]] static std::uint32_t read( const void* d ) noexcept + { + return be_to_h< std::uint32_t >( d ); + } + }; + + struct read_uint32_le + { + using type = std::uint32_t; + + [[nodiscard]] static std::uint32_t read( const void* d ) noexcept + { + return le_to_h< std::uint32_t >( d ); + } + }; + + struct read_uint64_be + { + using type = std::uint64_t; + + [[nodiscard]] static std::uint64_t read( const void* d ) noexcept + { + return be_to_h< std::uint64_t >( d ); + } + }; + + struct read_uint64_le + { + using type = std::uint64_t; + + [[nodiscard]] static std::uint64_t read( const void* d ) noexcept + { + return le_to_h< std::uint64_t >( d ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/set_stack_guard.hpp b/pxr/base/pegtl/pegtl/contrib/internal/set_stack_guard.hpp new file mode 100644 index 0000000000..21d28d771d --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/set_stack_guard.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_SET_STACK_GUARD_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_SET_STACK_GUARD_HPP + +#include +#include + +#include "../../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... Cs > + class [[nodiscard]] set_stack_guard + { + public: + template< typename... Ts > + set_stack_guard( std::set< Cs... >& set, Ts&&... ts ) + : m_i( set.emplace( std::forward< Ts >( ts )... ) ), + m_s( set ) + {} + + set_stack_guard( set_stack_guard&& ) = delete; + set_stack_guard( const set_stack_guard& ) = delete; + + set_stack_guard& operator=( set_stack_guard&& ) = delete; + set_stack_guard& operator=( const set_stack_guard& ) = delete; + + ~set_stack_guard() + { + if( m_i.second ) { + m_s.erase( m_i.first ); + } + } + + explicit operator bool() const noexcept + { + return m_i.second; + } + + private: + const std::pair< typename std::set< Cs... >::iterator, bool > m_i; + std::set< Cs... >& m_s; + }; + + template< typename... Cs > + set_stack_guard( std::set< Cs... >&, const typename std::set< Cs... >::value_type& ) -> set_stack_guard< Cs... >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/internal/vector_stack_guard.hpp b/pxr/base/pegtl/pegtl/contrib/internal/vector_stack_guard.hpp new file mode 100644 index 0000000000..9377e9b7d9 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/internal/vector_stack_guard.hpp @@ -0,0 +1,45 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_INTERNAL_VECTOR_STACK_GUARD_HPP +#define PXR_PEGTL_CONTRIB_INTERNAL_VECTOR_STACK_GUARD_HPP + +#include +#include + +#include "../../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... Cs > + class [[nodiscard]] vector_stack_guard + { + public: + template< typename... Ts > + vector_stack_guard( std::vector< Cs... >& vector, Ts&&... ts ) + : m_s( vector ) + { + m_s.emplace_back( std::forward< Ts >( ts )... ); + } + + vector_stack_guard( vector_stack_guard&& ) = delete; + vector_stack_guard( const vector_stack_guard& ) = delete; + + vector_stack_guard& operator=( vector_stack_guard&& ) = delete; + vector_stack_guard& operator=( const vector_stack_guard& ) = delete; + + ~vector_stack_guard() + { + m_s.pop_back(); + } + + private: + std::vector< Cs... >& m_s; + }; + + template< typename... Cs > + vector_stack_guard( std::vector< Cs... >&, const typename std::vector< Cs... >::value_type& ) -> vector_stack_guard< Cs... >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/iri.hpp b/pxr/base/pegtl/pegtl/contrib/iri.hpp new file mode 100644 index 0000000000..1cdede75a0 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/iri.hpp @@ -0,0 +1,106 @@ +// Copyright (c) 2021 Kelvin Hammond +// Copyright (c) 2021-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_IRI_HPP +#define PXR_PEGTL_CONTRIB_IRI_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/contrib/iri.hpp" +#else + +#include "../config.hpp" +#include "../rules.hpp" +#include "../utf8.hpp" + +#include "abnf.hpp" +#include "uri.hpp" + +namespace PXR_PEGTL_NAMESPACE::iri +{ + // IRI grammar according to RFC 3987. + + // This grammar is a direct PEG translation of the original URI grammar. + // It should be considered experimental -- in case of any issues, in particular + // missing rules for attached actions, please contact the developers. + + // Note that this grammar has multiple top-level rules. + + using uri::scheme; + using uri::port; + using uri::dslash; + using uri::IP_literal; + using uri::IPv4address; + using uri::pct_encoded; + using uri::sub_delims; + using uri::colon; + + // clang-format off + struct ucschar : utf8::ranges< + 0xA0, 0xD7FF, + 0xF900, 0xFDCF, + 0xFDF0, 0xFFEF, + 0x10000, 0x1FFFD, + 0x20000, 0x2FFFD, + 0x30000, 0x3FFFD, + 0x40000, 0x4FFFD, + 0x50000, 0x5FFFD, + 0x60000, 0x6FFFD, + 0x70000, 0x7FFFD, + 0x80000, 0x8FFFD, + 0x90000, 0x9FFFD, + 0xA0000, 0xAFFFD, + 0xB0000, 0xBFFFD, + 0xC0000, 0xCFFFD, + 0xD0000, 0xDFFFD, + 0xE1000, 0xEFFFD > {}; + + struct iprivate : utf8::ranges< 0xE000, 0xF8FF, 0xF0000, 0xFFFFD, 0x100000, 0x10FFFD > {}; + + struct iunreserved : sor< abnf::ALPHA, abnf::DIGIT, one< '-', '.', '_', '~' >, ucschar > {}; + + struct ipchar : sor< iunreserved, pct_encoded, sub_delims, one< ':', '@' > > {}; + + struct isegment : star< ipchar > {}; + struct isegment_nz : plus< ipchar > {}; + // non-zero-length segment without any colon ":" + struct isegment_nz_nc : plus< sor< iunreserved, pct_encoded, sub_delims, one< '@' > > > {}; + + struct ipath_abempty : star< one< '/' >, isegment > {}; + struct ipath_absolute : seq< one< '/' >, opt< isegment_nz, star< one< '/' >, isegment > > > {}; + struct ipath_noscheme : seq< isegment_nz_nc, star< one< '/' >, isegment > > {}; + struct ipath_rootless : seq< isegment_nz, star< one< '/' >, isegment > > {}; + struct ipath_empty : success {}; + + struct ipath : sor< ipath_noscheme, // begins with a non-colon segment + ipath_rootless, // begins with a segment + ipath_absolute, // begins with "/" but not "//" + ipath_abempty > // begins with "/" or is empty + {}; + + struct ireg_name : star< sor< iunreserved, pct_encoded, sub_delims > > {}; + + struct ihost : sor< IP_literal, IPv4address, ireg_name > {}; + struct iuserinfo : star< sor< iunreserved, pct_encoded, sub_delims, colon > > {}; + struct opt_iuserinfo : opt< iuserinfo, one< '@' > > {}; + struct iauthority : seq< opt_iuserinfo, ihost, opt< colon, port > > {}; + + struct iquery : star< sor< ipchar, iprivate, one< '/', '?' > > > {}; + struct ifragment : star< sor< ipchar, one< '/', '?' > > > {}; + + struct opt_iquery : opt_must< one< '?' >, iquery > {}; + struct opt_ifragment : opt_must< one< '#' >, ifragment > {}; + + struct ihier_part : sor< if_must< dslash, iauthority, ipath_abempty >, ipath_rootless, ipath_absolute, ipath_empty > {}; + struct irelative_part : sor< if_must< dslash, iauthority, ipath_abempty >, ipath_noscheme, ipath_absolute, ipath_empty > {}; + struct irelative_ref : seq< irelative_part, opt_iquery, opt_ifragment > {}; + + struct IRI : seq< scheme, one< ':' >, ihier_part, opt_iquery, opt_ifragment > {}; + struct IRI_reference : sor< IRI, irelative_ref > {}; + struct absolute_IRI : seq< scheme, one< ':' >, ihier_part, opt_iquery > {}; + // clang-format off + +} // namespace PXR_PEGTL_NAMESPACE::iri + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/json.hpp b/pxr/base/pegtl/pegtl/contrib/json.hpp new file mode 100644 index 0000000000..7ce4148d67 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/json.hpp @@ -0,0 +1,91 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_JSON_HPP +#define PXR_PEGTL_CONTRIB_JSON_HPP + +#include "../ascii.hpp" +#include "../config.hpp" +#include "../rules.hpp" +#include "../utf8.hpp" + +namespace PXR_PEGTL_NAMESPACE::json +{ + // JSON grammar according to RFC 8259 + + // clang-format off + struct ws : one< ' ', '\t', '\n', '\r' > {}; + + template< typename R, typename P = ws > + struct padr : seq< R, star< P > > {}; + + struct begin_array : padr< one< '[' > > {}; + struct begin_object : padr< one< '{' > > {}; + struct end_array : one< ']' > {}; + struct end_object : one< '}' > {}; + struct name_separator : pad< one< ':' >, ws > {}; + struct value_separator : padr< one< ',' > > {}; + + struct false_ : string< 'f', 'a', 'l', 's', 'e' > {}; // NOLINT(readability-identifier-naming) + struct null : string< 'n', 'u', 'l', 'l' > {}; + struct true_ : string< 't', 'r', 'u', 'e' > {}; // NOLINT(readability-identifier-naming) + + struct digits : plus< digit > {}; + struct exp : seq< one< 'e', 'E' >, opt< one< '-', '+'> >, digits > {}; + struct frac : seq< one< '.' >, digits > {}; + struct int_ : sor< one< '0' >, plus< digit > > {}; // NOLINT(readability-identifier-naming) + struct number : seq< opt< one< '-' > >, int_, opt< frac >, opt< exp > > {}; + + struct xdigit : pegtl::xdigit {}; + struct unicode : list< seq< one< 'u' >, rep< 4, xdigit > >, one< '\\' > > {}; + struct escaped_char : one< '"', '\\', '/', 'b', 'f', 'n', 'r', 't' > {}; + struct escaped : sor< escaped_char, unicode > {}; + struct unescaped : utf8::range< 0x20, 0x10FFFF > {}; + struct char_ : if_then_else< one< '\\' >, escaped, unescaped > {}; // NOLINT(readability-identifier-naming) + + struct string_content : until< at< one< '"' > >, char_ > {}; + struct string : seq< one< '"' >, string_content, any > + { + using content = string_content; + }; + + struct key_content : until< at< one< '"' > >, char_ > {}; + struct key : seq< one< '"' >, key_content, any > + { + using content = key_content; + }; + + struct value; + + struct array_element; + struct next_array_element : seq< array_element > {}; + struct array_content : opt< array_element, star< value_separator, next_array_element > > {}; + struct array : seq< begin_array, array_content, end_array > + { + using begin = begin_array; + using end = end_array; + using element = array_element; + using content = array_content; + }; + + struct member_value : padr< value > {}; + struct member : seq< key, name_separator, member_value > {}; + struct next_member : seq< member > {}; + struct object_content : opt< member, star< value_separator, next_member > > {}; + struct object : seq< begin_object, object_content, end_object > + { + using begin = begin_object; + using end = end_object; + using element = member; + using content = object_content; + }; + + struct value : sor< string, number, object, array, false_, true_, null > {}; + struct array_element : padr< value > {}; + + struct text : pad< value, ws > {}; + // clang-format on + +} // namespace PXR_PEGTL_NAMESPACE::json + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/json_pointer.hpp b/pxr/base/pegtl/pegtl/contrib/json_pointer.hpp new file mode 100644 index 0000000000..521671dce5 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/json_pointer.hpp @@ -0,0 +1,33 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_JSON_POINTER_HPP +#define PXR_PEGTL_CONTRIB_JSON_POINTER_HPP + +#include "../ascii.hpp" +#include "../config.hpp" +#include "../rules.hpp" +#include "../utf8.hpp" + +namespace PXR_PEGTL_NAMESPACE::json_pointer +{ + // JSON pointer grammar according to RFC 6901 + + // clang-format off + struct unescaped : utf8::ranges< 0x0, 0x2E, 0x30, 0x7D, 0x7F, 0x10FFFF > {}; + struct escaped : seq< one< '~' >, one< '0', '1' > > {}; + + struct reference_token : star< sor< unescaped, escaped > > {}; + struct json_pointer : star< one< '/' >, reference_token > {}; + // clang-format on + + // relative JSON pointer, see ... + + // clang-format off + struct non_negative_integer : sor< one< '0' >, plus< digit > > {}; + struct relative_json_pointer : seq< non_negative_integer, sor< one< '#' >, json_pointer > > {}; + // clang-format on + +} // namespace PXR_PEGTL_NAMESPACE::json_pointer + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/limit_bytes.hpp b/pxr/base/pegtl/pegtl/contrib/limit_bytes.hpp new file mode 100644 index 0000000000..abd81d4dc1 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/limit_bytes.hpp @@ -0,0 +1,88 @@ +// Copyright (c) 2021-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_LIMIT_BYTES_HPP +#define PXR_PEGTL_CONTRIB_LIMIT_BYTES_HPP + +#include + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../match.hpp" +#include "../nothing.hpp" +#include "../rewind_mode.hpp" + +#if defined( __cpp_exceptions ) +#include "../parse_error.hpp" +#else +#include +#include +#endif + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< std::size_t Maximum, typename MemoryInput > + struct [[nodiscard]] bytes_guard + { + MemoryInput& m_in; + const char* m_end; + + explicit bytes_guard( MemoryInput& in_in ) noexcept + : m_in( in_in ), + m_end( in_in.end() ) + { + m_in.private_set_end( m_in.begin() + std::min( m_in.size(), Maximum ) ); + } + + bytes_guard( bytes_guard&& ) = delete; + bytes_guard( const bytes_guard& ) = delete; + + ~bytes_guard() + { + m_in.private_set_end( m_end ); + } + + bytes_guard& operator=( bytes_guard&& ) = delete; + bytes_guard& operator=( const bytes_guard& ) = delete; + }; + + // C++17 does not allow for partial deduction guides. + + } // namespace internal + + template< std::size_t Maximum > + struct limit_bytes + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + internal::bytes_guard< Maximum, ParseInput > bg( in ); + if( PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ) ) { + if( in.empty() && ( bg.m_end != in.current() ) ) { +#if defined( __cpp_exceptions ) + throw PXR_PEGTL_NAMESPACE::parse_error( "maximum allowed rule consumption reached", in ); +#else + std::fputs( "maximum allowed rule consumption reached\n", stderr ); + std::terminate(); +#endif + } + return true; + } + return false; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/limit_depth.hpp b/pxr/base/pegtl/pegtl/contrib/limit_depth.hpp new file mode 100644 index 0000000000..b35bc567cd --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/limit_depth.hpp @@ -0,0 +1,83 @@ +// Copyright (c) 2021-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_LIMIT_DEPTH_HPP +#define PXR_PEGTL_CONTRIB_LIMIT_DEPTH_HPP + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../match.hpp" +#include "../nothing.hpp" +#include "../rewind_mode.hpp" + +#if defined( __cpp_exceptions ) +#include "../parse_error.hpp" +#else +#include +#include +#endif + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + struct [[nodiscard]] depth_guard + { + std::size_t& m_depth; + + explicit depth_guard( std::size_t& depth ) noexcept + : m_depth( depth ) + { + ++m_depth; + } + + depth_guard( depth_guard&& ) = delete; + depth_guard( const depth_guard& ) = delete; + + ~depth_guard() + { + --m_depth; + } + + depth_guard& operator=( depth_guard&& ) = delete; + depth_guard& operator=( const depth_guard& ) = delete; + }; + + } // namespace internal + + template< std::size_t Maximum > + struct limit_depth + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + if constexpr( Control< Rule >::enable ) { + const internal::depth_guard dg( in.private_depth ); + if( in.private_depth > Maximum ) { +#if defined( __cpp_exceptions ) + throw PXR_PEGTL_NAMESPACE::parse_error( "maximum parser rule nesting depth exceeded", in ); +#else + std::fputs( "maximum parser rule nesting depth exceeded\n", stderr ); + std::terminate(); +#endif + } + return PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); + } + else { + return PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); + } + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/parse_tree.hpp b/pxr/base/pegtl/pegtl/contrib/parse_tree.hpp new file mode 100644 index 0000000000..e68b7ff009 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/parse_tree.hpp @@ -0,0 +1,456 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_PARSE_TREE_HPP +#define PXR_PEGTL_CONTRIB_PARSE_TREE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "remove_first_state.hpp" +#include "shuffle_states.hpp" + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../demangle.hpp" +#include "../memory_input.hpp" +#include "../normal.hpp" +#include "../nothing.hpp" +#include "../parse.hpp" +#include "../rewind_mode.hpp" + +#include "../internal/enable_control.hpp" +#include "../internal/has_unwind.hpp" +#include "../internal/iterator.hpp" + +namespace PXR_PEGTL_NAMESPACE::parse_tree +{ + template< typename T, typename Source = std::string_view > + struct basic_node + { + using node_t = T; + using children_t = std::vector< std::unique_ptr< node_t > >; + children_t children; + + std::string_view type; + Source source; + + PXR_PEGTL_NAMESPACE::internal::iterator m_begin; + PXR_PEGTL_NAMESPACE::internal::iterator m_end; + + // each node will be default constructed + basic_node() = default; + + // no copy/move is necessary + // (nodes are always owned/handled by a std::unique_ptr) + basic_node( const basic_node& ) = delete; + basic_node( basic_node&& ) = delete; + + ~basic_node() = default; + + // no assignment either + basic_node& operator=( const basic_node& ) = delete; + basic_node& operator=( basic_node&& ) = delete; + + [[nodiscard]] bool is_root() const noexcept + { + return type.empty(); + } + + template< typename U > + [[nodiscard]] bool is_type() const noexcept + { + const auto u = demangle< U >(); + return ( ( type.data() == u.data() ) && ( type.size() == u.size() ) ) || ( type == u ); + } + + template< typename U > + void set_type() noexcept + { + type = demangle< U >(); + } + + [[nodiscard]] position begin() const + { + return position( m_begin, source ); + } + + [[nodiscard]] position end() const + { + return position( m_end, source ); + } + + [[nodiscard]] bool has_content() const noexcept + { + return m_end.data != nullptr; + } + + [[nodiscard]] std::string_view string_view() const noexcept + { + assert( has_content() ); + return std::string_view( m_begin.data, m_end.data - m_begin.data ); + } + + [[nodiscard]] std::string string() const + { + assert( has_content() ); + return std::string( m_begin.data, m_end.data ); + } + + template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > + [[nodiscard]] memory_input< P, Eol > as_memory_input() const + { + assert( has_content() ); + return { m_begin.data, m_end.data, source, m_begin.byte, m_begin.line, m_begin.column }; + } + + template< typename... States > + void remove_content( States&&... /*unused*/ ) noexcept + { + m_end = PXR_PEGTL_NAMESPACE::internal::iterator(); + } + + // all non-root nodes are initialized by calling this method + template< typename Rule, typename ParseInput, typename... States > + void start( const ParseInput& in, States&&... /*unused*/ ) + { + set_type< Rule >(); + source = in.source(); + m_begin = PXR_PEGTL_NAMESPACE::internal::iterator( in.iterator() ); + } + + // if parsing of the rule succeeded, this method is called + template< typename Rule, typename ParseInput, typename... States > + void success( const ParseInput& in, States&&... /*unused*/ ) noexcept + { + m_end = PXR_PEGTL_NAMESPACE::internal::iterator( in.iterator() ); + } + + // if parsing of the rule failed, this method is called + template< typename Rule, typename ParseInput, typename... States > + void failure( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept + {} + + // if parsing succeeded and the (optional) transform call + // did not discard the node, it is appended to its parent. + // note that "child" is the node whose Rule just succeeded + // and "*this" is the parent where the node should be appended. + template< typename... States > + void emplace_back( std::unique_ptr< node_t >&& child, States&&... /*unused*/ ) + { + assert( child ); + children.emplace_back( std::move( child ) ); + } + }; + + struct node + : basic_node< node > + {}; + + namespace internal + { + template< typename Node > + struct state + { + std::vector< std::unique_ptr< Node > > stack; + + state() + { + emplace_back(); + } + + void emplace_back() + { + stack.emplace_back( std::make_unique< Node >() ); + } + + [[nodiscard]] std::unique_ptr< Node >& back() noexcept + { + assert( !stack.empty() ); + return stack.back(); + } + + void pop_back() noexcept + { + assert( !stack.empty() ); + return stack.pop_back(); + } + }; + + template< typename Selector, typename... Parameters > + void transform( Parameters&&... /*unused*/ ) noexcept + {} + + template< typename Selector, typename ParseInput, typename Node, typename... States > + auto transform( const ParseInput& in, std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( Selector::transform( in, n, st... ) ) ) + -> decltype( (void)Selector::transform( in, n, st... ) ) + { + Selector::transform( in, n, st... ); + } + + template< typename Selector, typename ParseInput, typename Node, typename... States > + auto transform( const ParseInput& /*unused*/, std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( Selector::transform( n, st... ) ) ) + -> decltype( (void)Selector::transform( n, st... ) ) + { + Selector::transform( n, st... ); + } + + template< typename Rule, template< typename... > class Selector > + inline constexpr bool is_selected_node = ( PXR_PEGTL_NAMESPACE::internal::enable_control< Rule > && Selector< Rule >::value ); + + template< unsigned Level, typename Subs, template< typename... > class Selector > + inline constexpr bool is_leaf{}; + + template< typename... Rules, template< typename... > class Selector > + inline constexpr bool is_leaf< 0, type_list< Rules... >, Selector > = ( sizeof...( Rules ) == 0 ); + + template< unsigned Level, typename Rule, template< typename... > class Selector > + inline constexpr bool is_unselected_branch = ( !is_selected_node< Rule, Selector > && is_leaf< Level, typename Rule::subs_t, Selector > ); + + template< unsigned Level, typename... Rules, template< typename... > class Selector > + inline constexpr bool is_leaf< Level, type_list< Rules... >, Selector > = ( is_unselected_branch< Level - 1, Rules, Selector > && ... ); + + template< typename Node, template< typename... > class Selector, template< typename... > class Control > + struct make_control + { + template< typename Rule, bool, bool > + struct state_handler; + + template< typename Rule > + using type = rotate_states_right< state_handler< Rule, is_selected_node< Rule, Selector >, is_leaf< 8, typename Rule::subs_t, Selector > > >; + }; + + template< typename, typename, typename... > + inline constexpr bool node_has_unwind = false; + + template< typename Node, typename Rule, typename... States > + inline constexpr bool node_has_unwind< Node, + Rule, + decltype( std::declval< Node >().template unwind< Rule >( std::declval< States >()... ) ), + States... > = true; + + template< typename Control, typename... States > + inline constexpr bool control_has_unwind = PXR_PEGTL_NAMESPACE::internal::has_unwind< Control, void, States... >; + + template< typename Node, template< typename... > class Selector, template< typename... > class Control > + template< typename Rule > + struct make_control< Node, Selector, Control >::state_handler< Rule, false, true > + : remove_first_state< Control< Rule > > + {}; + + template< typename Node, template< typename... > class Selector, template< typename... > class Control > + template< typename Rule > + struct make_control< Node, Selector, Control >::state_handler< Rule, false, false > + : remove_first_state< Control< Rule > > + { + static constexpr bool enable = true; + + template< typename ParseInput, typename... States > + static void start( const ParseInput& /*unused*/, state< Node >& state, States&&... /*unused*/ ) + { + state.emplace_back(); + } + + template< typename ParseInput, typename... States > + static void success( const ParseInput& /*unused*/, state< Node >& state, States&&... /*unused*/ ) + { + auto n = std::move( state.back() ); + state.pop_back(); + for( auto& c : n->children ) { + state.back()->children.emplace_back( std::move( c ) ); + } + } + + template< typename ParseInput, typename... States > + static void failure( const ParseInput& /*unused*/, state< Node >& state, States&&... /*unused*/ ) + { + state.pop_back(); + } + + template< typename ParseInput, typename... States > + static void unwind( const ParseInput& /*unused*/, state< Node >& state, States&&... /*unused*/ ) + { + state.pop_back(); + } + }; + + template< typename Node, template< typename... > class Selector, template< typename... > class Control > + template< typename Rule, bool B > + struct make_control< Node, Selector, Control >::state_handler< Rule, true, B > + : remove_first_state< Control< Rule > > + { + template< typename ParseInput, typename... States > + static void start( const ParseInput& in, state< Node >& state, States&&... st ) + { + Control< Rule >::start( in, st... ); + state.emplace_back(); + state.back()->template start< Rule >( in, st... ); + } + + template< typename ParseInput, typename... States > + static void success( const ParseInput& in, state< Node >& state, States&&... st ) + { + auto n = std::move( state.back() ); + state.pop_back(); + n->template success< Rule >( in, st... ); + transform< Selector< Rule > >( in, n, st... ); + if( n ) { + state.back()->emplace_back( std::move( n ), st... ); + } + Control< Rule >::success( in, st... ); + } + + template< typename ParseInput, typename... States > + static void failure( const ParseInput& in, state< Node >& state, States&&... st ) + { + state.back()->template failure< Rule >( in, st... ); + state.pop_back(); + Control< Rule >::failure( in, st... ); + } + + template< typename ParseInput, typename... States > + static void unwind( [[maybe_unused]] const ParseInput& in, [[maybe_unused]] state< Node >& state, States&&... st ) + { + if constexpr( node_has_unwind< Node, Rule, void, const ParseInput&, States... > ) { + state.back()->template unwind< Rule >( in, st... ); + } + state.pop_back(); + if constexpr( control_has_unwind< Control< Rule >, const ParseInput&, States... > ) { + Control< Rule >::unwind( in, st... ); + } +#if defined( _MSC_VER ) + ( (void)st, + ... ); +#endif + } + }; + + template< typename > + using store_all = std::true_type; + + template< typename > + struct selector; + + template< typename T > + struct selector< std::tuple< T > > + { + using type = typename T::type; + }; + + template< typename... Ts > + struct selector< std::tuple< Ts... > > + { + static_assert( sizeof...( Ts ) == 0, "multiple matches found" ); + using type = std::false_type; + }; + + template< typename T > + using selector_t = typename selector< T >::type; + + template< typename Rule, typename Collection > + using select_tuple = std::conditional_t< Collection::template contains< Rule >, std::tuple< Collection >, std::tuple<> >; + + } // namespace internal + + template< typename Rule, typename... Collections > + using selector = internal::selector_t< decltype( std::tuple_cat( std::declval< internal::select_tuple< Rule, Collections > >()... ) ) >; + + template< typename Base > + struct apply + : std::true_type + { + template< typename... Rules > + struct on + { + using type = Base; + + template< typename Rule > + static constexpr bool contains = ( std::is_same_v< Rule, Rules > || ... ); + }; + }; + + struct store_content + : apply< store_content > + {}; + + // some nodes don't need to store their content + struct remove_content + : apply< remove_content > + { + template< typename Node, typename... States > + static void transform( std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( n->Node::remove_content( st... ) ) ) + { + n->remove_content( st... ); + } + }; + + // if a node has only one child, replace the node with its child, otherwise remove content + struct fold_one + : apply< fold_one > + { + template< typename Node, typename... States > + static void transform( std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( n->children.size(), n->Node::remove_content( st... ) ) ) + { + if( n->children.size() == 1 ) { + n = std::move( n->children.front() ); + } + else { + n->remove_content( st... ); + } + } + }; + + // if a node has no children, discard the node, otherwise remove content + struct discard_empty + : apply< discard_empty > + { + template< typename Node, typename... States > + static void transform( std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( (void)n->children.empty(), n->Node::remove_content( st... ) ) ) + { + if( n->children.empty() ) { + n.reset(); + } + else { + n->remove_content( st... ); + } + } + }; + + template< typename Rule, + typename Node, + template< typename... > class Selector = internal::store_all, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + typename ParseInput, + typename... States > + [[nodiscard]] std::unique_ptr< Node > parse( ParseInput&& in, States&&... st ) + { + internal::state< Node > state; + if( !PXR_PEGTL_NAMESPACE::parse< Rule, Action, internal::make_control< Node, Selector, Control >::template type >( in, st..., state ) ) { + return nullptr; + } + assert( state.stack.size() == 1 ); + return std::move( state.back() ); + } + + template< typename Rule, + template< typename... > class Selector = internal::store_all, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + typename ParseInput, + typename... States > + [[nodiscard]] std::unique_ptr< node > parse( ParseInput&& in, States&&... st ) + { + return parse< Rule, node, Selector, Action, Control >( in, st... ); + } + +} // namespace PXR_PEGTL_NAMESPACE::parse_tree + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/parse_tree_to_dot.hpp b/pxr/base/pegtl/pegtl/contrib/parse_tree_to_dot.hpp new file mode 100644 index 0000000000..258df36662 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/parse_tree_to_dot.hpp @@ -0,0 +1,111 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_PARSE_TREE_TO_DOT_HPP +#define PXR_PEGTL_CONTRIB_PARSE_TREE_TO_DOT_HPP + +#include +#include +#include + +#include "parse_tree.hpp" + +namespace PXR_PEGTL_NAMESPACE::parse_tree +{ + namespace internal + { + inline void escape( std::ostream& os, const std::string_view s ) + { + static const char* h = "0123456789abcdef"; + + const char* p = s.data(); + const char* l = p; + const char* const e = s.data() + s.size(); + while( p != e ) { + const unsigned char c = *p; + if( c == '\\' ) { + os.write( l, p - l ); + l = ++p; + os << "\\\\\\\\"; + } + else if( c == '"' ) { + os.write( l, p - l ); + l = ++p; + os << "\\\\\\\""; + } + else if( c < 32 ) { + os.write( l, p - l ); + l = ++p; + switch( c ) { + case '\a': + os << "\\\\a"; + break; + case '\b': + os << "\\\\b"; + break; + case '\f': + os << "\\\\f"; + break; + case '\n': + os << "\\\\n"; + break; + case '\r': + os << "\\\\r"; + break; + case '\t': + os << "\\\\t"; + break; + case '\v': + os << "\\\\v"; + break; + default: + os << "\\\\u00" << h[ ( c & 0xf0 ) >> 4 ] << h[ c & 0x0f ]; + } + } + else if( c == 127 ) { + os.write( l, p - l ); + l = ++p; + os << "\\\\u007f"; + } + else { + ++p; + } + } + os.write( l, p - l ); + } + + template< typename Node > + void print_dot_node( std::ostream& os, const Node& n, const std::string_view s ) + { + os << " x" << &n << " [ label=\""; + escape( os, s ); + if( n.has_content() ) { + os << "\\n\\\""; + escape( os, n.string_view() ); + os << "\\\""; + } + os << "\" ]\n"; + if( !n.children.empty() ) { + os << " x" << &n << " -> { "; + for( auto& up : n.children ) { + os << "x" << up.get() << ( ( up == n.children.back() ) ? " }\n" : ", " ); + } + for( auto& up : n.children ) { + print_dot_node( os, *up, up->type ); + } + } + } + + } // namespace internal + + template< typename Node > + void print_dot( std::ostream& os, const Node& n ) + { + os << "digraph parse_tree\n{\n"; + internal::print_dot_node( os, n, n.is_root() ? "ROOT" : n.type ); + os << "}\n"; + } + +} // namespace PXR_PEGTL_NAMESPACE::parse_tree + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/peg.hpp b/pxr/base/pegtl/pegtl/contrib/peg.hpp new file mode 100644 index 0000000000..4a1ab4df51 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/peg.hpp @@ -0,0 +1,121 @@ +// Copyright (c) 2021 Daniel Deptford +// Copyright (c) 2021-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_PEG_HPP +#define PXR_PEGTL_CONTRIB_PEG_HPP + +#include + +namespace PXR_PEGTL_NAMESPACE::peg +{ + // PEG grammar from https://pdos.csail.mit.edu/~baford/packrat/popl04/peg-popl04.pdf + namespace grammar + { + // clang-format off + struct AND; + struct Char; + struct Class; + struct CLOSE; + struct Comment; + struct Definition; + struct DOT; + struct EndOfFile; + struct EndOfLine; + struct Expression; + struct QUESTION; + struct IdentCont; + struct Identifier; + struct IdentStart; + struct LEFTARROW; + struct Literal; + struct NOT; + struct OPEN; + struct PLUS; + struct Prefix; + struct Primary; + struct Range; + struct Sequence; + struct SLASH; + struct Space; + struct Spacing; + struct STAR; + struct Suffix; + + struct Grammar : seq< Spacing, plus< Definition >, EndOfFile > {}; + + struct Definition : seq< Identifier, LEFTARROW, Expression > {}; + struct Expression : list< Sequence, SLASH > {}; + struct Sequence : star< Prefix > {}; + + struct Prefix : seq< opt< sor< AND, NOT > >, Suffix > {}; + struct Suffix : seq< Primary, opt< sor< QUESTION, STAR, PLUS > > > {}; + + struct Primary : sor< + seq< Identifier, not_at< LEFTARROW > >, + seq< OPEN, Expression, CLOSE >, + Literal, + Class, + DOT + > {}; + + struct Identifier : seq< IdentStart, star< IdentCont >, Spacing > {}; + + struct IdentStart : identifier_first {}; + + struct IdentCont : identifier_other {}; + + struct Literal : sor< + seq< one< '\'' >, until< one< '\'' >, Char >, Spacing >, + seq< one< '"' >, until< one< '"' >, Char >, Spacing > + > {}; + + struct Class : seq< one< '[' >, until< one< ']' >, Range >, Spacing > {}; + + struct Range : sor< + seq< Char, one< '-' >, Char >, + Char + > {}; + + struct Char : sor< + seq< + one< '\\' >, + one< 'n', 'r', 't', '\'', '"', '[', ']', '\\' > >, + seq< + one< '\\' >, + range< '0', '2' >, + range< '0', '7' >, + range< '0', '7' > >, + seq< + one< '\\' >, + range< '0','7' >, + opt< range< '0','7' > > >, + seq< + not_at< one< '\\' > >, + any > + > {}; + + struct LEFTARROW : seq< string< '<','-' >, Spacing > {}; + struct SLASH : seq< one< '/' >, Spacing > {}; + struct AND : seq< one< '&' >, Spacing > {}; + struct NOT : seq< one< '!' >, Spacing > {}; + struct QUESTION : seq< one< '?' >, Spacing > {}; + struct STAR : seq< one< '*' >, Spacing > {}; + struct PLUS : seq< one< '+' >, Spacing > {}; + struct OPEN : seq< one< '(' >, Spacing > {}; + struct CLOSE : seq< one< ')' >, Spacing > {}; + struct DOT : seq< one< '.' >, Spacing > {}; + + struct Spacing : star< sor< Space, Comment > > {}; + struct Comment : seq< one< '#' >, until< EndOfLine > > {}; + + struct Space : sor< one< ' ', '\t' >, EndOfLine > {}; + struct EndOfLine : sor< string< '\r', '\n' >, one< '\n' >, one< '\r' > > {}; + struct EndOfFile : eof {}; + // clang-format on + + } // namespace grammar + +} // namespace PXR_PEGTL_NAMESPACE::peg + +#endif // PXR_PEGTL_CONTRIB_PEG_HPP diff --git a/pxr/base/pegtl/pegtl/contrib/predicates.hpp b/pxr/base/pegtl/pegtl/contrib/predicates.hpp new file mode 100644 index 0000000000..a90455739d --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/predicates.hpp @@ -0,0 +1,126 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_PREDICATES_HPP +#define PXR_PEGTL_CONTRIB_PREDICATES_HPP + +#include "../config.hpp" +#include "../type_list.hpp" + +#include "../internal/bump_help.hpp" +#include "../internal/dependent_false.hpp" +#include "../internal/enable_control.hpp" +#include "../internal/failure.hpp" +#include "../internal/peek_char.hpp" +#include "../internal/peek_utf8.hpp" + +#include "analyze_traits.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename Peek, typename... Ps > + struct predicates_and_test + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return ( Ps::test( c ) && ... ); // TODO: Static assert that Ps::peek_t is the same as peek_t?! + } + }; + + template< typename Peek, typename P > + struct predicate_not_test + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return !P::test( c ); // TODO: Static assert that P::peek_t is the same as peek_t?! + } + }; + + template< typename Peek, typename... Ps > + struct predicates_or_test + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return ( Ps::test( c ) || ... ); // TODO: Static assert that Ps::peek_t is the same as peek_t?! + } + }; + + template< template< typename, typename... > class Test, typename Peek, typename... Ps > + struct predicates + : private Test< Peek, Ps... > + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + using rule_t = predicates; + using subs_t = empty_list; + + using base_t = Test< Peek, Ps... >; + using base_t::test; + + template< int Eol > + static constexpr bool can_match_eol = test( Eol ); + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + { + if( const auto t = Peek::peek( in ) ) { + if( test( t.data ) ) { + bump_help< predicates >( in, t.size ); + return true; + } + } + return false; + } + }; + + template< template< typename, typename... > class Test, typename Peek > + struct predicates< Test, Peek > + { + static_assert( dependent_false< Peek >, "Empty predicate list is not allowed!" ); + }; + + template< template< typename, typename... > class Test, typename Peek, typename... Ps > + inline constexpr bool enable_control< predicates< Test, Peek, Ps... > > = false; + + } // namespace internal + + inline namespace ascii + { + // clang-format off + template< typename... Ps > struct predicates_and : internal::predicates< internal::predicates_and_test, internal::peek_char, Ps... > {}; + template< typename P > struct predicate_not : internal::predicates< internal::predicate_not_test, internal::peek_char, P > {}; + template< typename... Ps > struct predicates_or : internal::predicates< internal::predicates_or_test, internal::peek_char, Ps... > {}; + // clang-format on + + } // namespace ascii + + namespace utf8 + { + // clang-format off + template< typename... Ps > struct predicates_and : internal::predicates< internal::predicates_and_test, internal::peek_utf8, Ps... > {}; + template< typename P > struct predicate_not : internal::predicates< internal::predicate_not_test, internal::peek_utf8, P > {}; + template< typename... Ps > struct predicates_or : internal::predicates< internal::predicates_or_test, internal::peek_utf8, Ps... > {}; + // clang-format on + + } // namespace utf8 + + template< typename Name, template< typename, typename... > class Test, typename Peek, typename... Ps > + struct analyze_traits< Name, internal::predicates< Test, Peek, Ps... > > + : analyze_any_traits<> + {}; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/print.hpp b/pxr/base/pegtl/pegtl/contrib/print.hpp new file mode 100644 index 0000000000..ed804dd984 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/print.hpp @@ -0,0 +1,75 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_PRINT_HPP +#define PXR_PEGTL_CONTRIB_PRINT_HPP + +#include + +#include "../config.hpp" +#include "../demangle.hpp" +#include "../type_list.hpp" +#include "../visit.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename Name > + struct print_names + { + static void visit( std::ostream& os ) + { + os << demangle< Name >() << '\n'; + } + }; + + template< typename Name > + struct print_debug + { + static void visit( std::ostream& os ) + { + const auto first = demangle< Name >(); + os << first << '\n'; + + const auto second = demangle< typename Name::rule_t >(); + if( first != second ) { + os << " (aka) " << second << '\n'; + } + + print_subs( os, typename Name::subs_t() ); + + os << '\n'; + } + + private: + template< typename... Rules > + static void print_subs( std::ostream& os, type_list< Rules... > /*unused*/ ) + { + ( print_sub< Rules >( os ), ... ); + } + + template< typename Rule > + static void print_sub( std::ostream& os ) + { + os << " (sub) " << demangle< Rule >() << '\n'; + } + }; + + } // namespace internal + + template< typename Grammar > + void print_names( std::ostream& os ) + { + visit< Grammar, internal::print_names >( os ); + } + + template< typename Grammar > + void print_debug( std::ostream& os ) + { + visit< Grammar, internal::print_debug >( os ); + } + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/print_coverage.hpp b/pxr/base/pegtl/pegtl/contrib/print_coverage.hpp new file mode 100644 index 0000000000..bf10707790 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/print_coverage.hpp @@ -0,0 +1,53 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_PRINT_COVERAGE_HPP +#define PXR_PEGTL_CONTRIB_PRINT_COVERAGE_HPP + +#include + +#include "coverage.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + inline std::ostream& operator<<( std::ostream& os, const coverage_result& result ) + { + os << "[\n"; + bool f = true; + for( const auto& [ k, v ] : result ) { + if( f ) { + f = false; + } + else { + os << ",\n"; + } + os << " {\n" + << " \"rule\": \"" << k << "\",\n" + << " \"start\": " << v.start << ", \"success\": " << v.success << ", \"failure\": " << v.failure << ", \"unwind\": " << v.unwind << ", \"raise\": " << v.raise << ",\n"; + if( v.branches.empty() ) { + os << " \"branches\": []\n"; + } + else { + os << " \"branches\": [\n"; + bool f2 = true; + for( const auto& [ k2, v2 ] : v.branches ) { + if( f2 ) { + f2 = false; + } + else { + os << ",\n"; + } + os << " { \"branch\": \"" << k2 << "\", \"start\": " << v2.start << ", \"success\": " << v2.success << ", \"failure\": " << v2.failure << ", \"unwind\": " << v2.unwind << ", \"raise\": " << v2.raise << " }"; + } + os << "\n ]\n"; + } + os << " }"; + } + os << "\n"; + os << "]\n"; + return os; + } + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/proto3.hpp b/pxr/base/pegtl/pegtl/contrib/proto3.hpp new file mode 100644 index 0000000000..49b51fd382 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/proto3.hpp @@ -0,0 +1,142 @@ +// Copyright (c) 2021-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_PROTO3_HPP +#define PXR_PEGTL_CONTRIB_PROTO3_HPP + +#include "../ascii.hpp" +#include "../config.hpp" +#include "../rules.hpp" + +namespace PXR_PEGTL_NAMESPACE::proto3 +{ + // protocol buffer v3 + // https://developers.google.com/protocol-buffers/docs/reference/proto3-spec + + // clang-format off + struct comment_sl : seq< two< '/' >, until< eolf > > {}; + struct comment_ml : if_must< string< '/', '*' >, until< string< '*', '/' > > > {}; + struct sp : sor< space, comment_sl, comment_ml > {}; + struct sps : star< sp > {}; + + struct comma : one< ',' > {}; + struct dot : one< '.' > {}; + struct equ : one< '=' > {}; + struct semi : one< ';' > {}; + + struct option; + struct message; + struct extend; + + struct ident_first : ranges< 'a', 'z', 'A', 'Z' > {}; // NOTE: Yes, no '_'. + struct ident_other : ranges< 'a', 'z', 'A', 'Z', '0', '9', '_' > {}; + struct ident : seq< ident_first, star< ident_other > > {}; + struct full_ident : list_must< ident, dot > {}; + + struct hex_lit : seq< one< '0' >, one< 'x', 'X' >, plus< xdigit > > {}; + struct oct_lit : seq< one< '0' >, plus< odigit > > {}; + struct dec_lit : seq< range< '1', '9' >, star< digit > > {}; + struct int_lit : sor< hex_lit, oct_lit, dec_lit > {}; + + struct sign : one< '+', '-' > {}; + struct exp : seq< one< 'E', 'e' >, opt< sign >, plus< digit > > {}; + struct float_lit : sor< + seq< plus< digit >, dot, exp >, + seq< plus< digit >, dot, star< digit >, opt< exp > >, + seq< dot, plus< digit >, opt< exp > >, + keyword< 'i', 'n', 'f' >, + keyword< 'n', 'a', 'n' > > {}; + + struct bool_lit : sor< keyword< 't', 'r', 'u', 'e' >, + keyword< 'f', 'a', 'l', 's', 'e' > > {}; + + struct hex_escape : if_must< one< 'x', 'X' >, xdigit, xdigit > {}; + struct oct_escape : if_must< odigit, odigit, odigit > {}; + struct char_escape : one< 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', '\'', '"' > {}; + struct escape : if_must< one< '\\' >, hex_escape, oct_escape, char_escape > {}; + struct char_value : sor< escape, not_one< '\n', '\0' > > {}; // NOTE: No need to exclude '\' from not_one<>, see escape rule. + template< char Q > + struct str_impl : if_must< one< Q >, until< one< Q >, char_value > > {}; + struct str_lit : sor< str_impl< '\'' >, str_impl< '"' > > {}; + + struct constant : sor< bool_lit, seq< opt< sign >, float_lit >, seq< opt< sign >, int_lit >, str_lit, full_ident > {}; + + struct option_name : seq< sor< ident, if_must< one< '(' >, full_ident, one< ')' > > >, star_must< dot, ident > > {}; + struct option : if_must< keyword< 'o', 'p', 't', 'i', 'o', 'n' >, sps, option_name, sps, equ, sps, constant, sps, semi > {}; + + struct bool_type : keyword< 'b', 'o', 'o', 'l' > {}; + struct bytes_type : keyword< 'b', 'y', 't', 'e', 's' > {}; + struct double_type : keyword< 'd', 'o', 'u', 'b', 'l', 'e' > {}; + struct float_type : keyword< 'f', 'l', 'o', 'a', 't' > {}; + struct string_type : keyword< 's', 't', 'r', 'i', 'n', 'g' > {}; + + struct int32_type : keyword< 'i', 'n', 't', '3', '2' > {}; + struct int64_type : keyword< 'i', 'n', 't', '6', '4' > {}; + struct sint32_type : keyword< 's', 'i', 'n', 't', '3', '2' > {}; + struct sint64_type : keyword< 's', 'i', 'n', 't', '6', '4' > {}; + struct uint32_type : keyword< 'u', 'i', 'n', 't', '3', '2' > {}; + struct uint64_type : keyword< 'u', 'i', 'n', 't', '6', '4' > {}; + struct fixed32_type : keyword< 'f', 'i', 'x', 'e', 'd', '3', '2' > {}; + struct fixed64_type : keyword< 'f', 'i', 'x', 'e', 'd', '6', '4' > {}; + struct sfixed32_type : keyword< 's', 'f', 'i', 'x', 'e', 'd', '3', '2' > {}; + struct sfixed64_type : keyword< 's', 'f', 'i', 'x', 'e', 'd', '6', '4' > {}; + + struct builtin_type : sor< bool_type, bytes_type, double_type, float_type, string_type, int32_type, int64_type, sint32_type, sint64_type, uint32_type, uint64_type, fixed32_type, fixed64_type, sfixed32_type, sfixed64_type > {}; + + struct defined_type : seq< opt< dot >, full_ident > {}; // NOTE: This replaces both message_type and enum_type -- they have the same syntax. + + struct type : sor< builtin_type, defined_type > {}; + + struct field_option : if_must< option_name, sps, equ, sps, constant > {}; + struct field_options : if_must< one< '[' >, sps, list< field_option, comma, sp >, sps, one< ']' > > {}; + struct field_name : ident {}; + struct field_number : int_lit {}; + struct field : seq< opt< sor< keyword< 'o', 'p', 't', 'i', 'o', 'n', 'a', 'l' >, keyword< 'r', 'e', 'p', 'e', 'a', 't', 'e', 'd' > >, sps >, type, sps, field_name, sps, equ, sps, field_number, sps, opt< field_options, sps >, semi > {}; + + struct oneof_name : ident {}; + struct oneof_field : if_must< type, sps, field_name, sps, equ, sps, field_number, sps, opt< field_options, sps >, semi > {}; + struct oneof_body : sor< oneof_field, semi > {}; + struct oneof : if_must< keyword< 'o', 'n', 'e', 'o', 'f' >, sps, oneof_name, sps, one< '{' >, sps, until< one< '}' >, oneof_body, sps >, sps > {}; + + struct key_type : seq< sor< bool_type, string_type, int32_type, int64_type, sint32_type, sint64_type, uint32_type, uint64_type, fixed32_type, fixed64_type, sfixed32_type, sfixed64_type >, not_at< ident_other > > {}; + struct map_name : ident {}; + struct map_field : if_must< keyword< 'm', 'a', 'p' >, sps, one< '<' >, sps, key_type, sps, comma, sps, type, sps, one< '>' >, sps, map_name, sps, equ, sps, field_number, sps, opt< field_options, sps >, semi > {}; + + struct range : if_must< int_lit, sps, keyword< 't', 'o' >, sps, sor< int_lit, keyword< 'm', 'a', 'x' > > > {}; + struct ranges : list_must< range, comma, sp > {}; + struct field_names : list_must< field_name, comma, sp > {}; + struct reserved : if_must< keyword< 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd' >, sps, sor< ranges, field_names >, sps, semi > {}; + + struct enum_name : ident {}; + struct enum_value_option : seq< option_name, sps, equ, sps, constant > {}; + struct enum_field : seq< ident, sps, equ, sps, int_lit, sps, opt_must< one< '[' >, sps, list_must< enum_value_option, comma, sp >, sps, one< ']' >, sps >, semi > {}; + struct enum_body : if_must< one< '{' >, sps, star< sor< option, enum_field, semi >, sps >, one< '}' > > {}; + struct enum_def : if_must< keyword< 'e', 'n', 'u', 'm' >, sps, enum_name, sps, enum_body > {}; + + struct message_thing : sor< field, enum_def, message, option, oneof, map_field, reserved, extend, semi > {}; + struct message_body : seq< one<'{'>, sps, star< message_thing, sps >, one<'}'> > {}; + struct message : if_must< keyword< 'm', 'e', 's', 's', 'a', 'g', 'e' >, sps, defined_type, sps, message_body > {}; + struct extend : if_must< keyword< 'e', 'x', 't', 'e', 'n', 'd' >, sps, defined_type, sps, message_body > {}; + + struct package : if_must< keyword< 'p', 'a', 'c', 'k', 'a', 'g', 'e' >, sps, full_ident, sps, semi > {}; + + struct import_option : opt< sor< keyword< 'w', 'e', 'a', 'k' >, keyword< 'p', 'u', 'b', 'l', 'i', 'c' > > > {}; + struct import : if_must< keyword< 'i', 'm', 'p', 'o', 'r', 't' >, sps, import_option, sps, str_lit, sps, semi > {}; + + struct rpc_name : ident {}; + struct rpc_type : if_must< one< '(' >, sps, opt< keyword< 's', 't', 'r', 'e', 'a', 'm' >, sps >, defined_type, sps, one< ')' > > {}; + struct rpc_options : if_must< one< '{' >, sps, star< sor< option, semi >, sps >, one< '}' > > {}; + struct rpc : if_must< keyword< 'r', 'p', 'c' >, sps, rpc_name, sps, rpc_type, sps, keyword< 'r', 'e', 't', 'u', 'r', 'n', 's' >, sps, rpc_type, sps, sor< semi, rpc_options > > {}; + struct service_name : ident {}; + struct service : if_must< keyword< 's', 'e', 'r', 'v', 'i', 'c', 'e' >, sps, service_name, sps, one< '{' >, sps, star< sor< option, rpc, semi >, sps >, one< '}' > > {}; + + struct body : sor< import, package, option, message, enum_def, service, extend, semi > {}; + + struct quote : one< '\'', '"' > {}; + struct head : if_must< keyword< 's', 'y', 'n', 't', 'a', 'x' >, sps, equ, sps, quote, string< 'p', 'r', 'o', 't', 'o', '3' >, quote, sps, semi > {}; + struct proto : must< sps, head, sps, star< body, sps >, eof > {}; + // clang-format on + +} // namespace PXR_PEGTL_NAMESPACE::proto3 + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/raw_string.hpp b/pxr/base/pegtl/pegtl/contrib/raw_string.hpp new file mode 100644 index 0000000000..b8c28214a5 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/raw_string.hpp @@ -0,0 +1,232 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_RAW_STRING_HPP +#define PXR_PEGTL_CONTRIB_RAW_STRING_HPP + +#include +#include + +#include "../apply_mode.hpp" +#include "../ascii.hpp" +#include "../config.hpp" +#include "../rewind_mode.hpp" +#include "../rules.hpp" + +#include "analyze_traits.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< char Open, char Marker > + struct raw_string_open + { + using rule_t = raw_string_open; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in, std::size_t& marker_size ) noexcept( noexcept( in.size( 0 ) ) ) + { + if( in.empty() || ( in.peek_char( 0 ) != Open ) ) { + return false; + } + for( std::size_t i = 1; i < in.size( i + 1 ); ++i ) { + switch( const auto c = in.peek_char( i ) ) { + case Open: + marker_size = i + 1; + in.bump_in_this_line( marker_size ); + (void)eol::match( in ); + return true; + case Marker: + break; + default: + return false; + } + } + return false; + } + }; + + template< char Open, char Marker > + inline constexpr bool enable_control< raw_string_open< Open, Marker > > = false; + + template< char Marker, char Close > + struct at_raw_string_close + { + using rule_t = at_raw_string_close; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in, const std::size_t& marker_size ) noexcept( noexcept( in.size( 0 ) ) ) + { + if( in.size( marker_size ) < marker_size ) { + return false; + } + if( in.peek_char( 0 ) != Close ) { + return false; + } + if( in.peek_char( marker_size - 1 ) != Close ) { + return false; + } + for( std::size_t i = 0; i < ( marker_size - 2 ); ++i ) { + if( in.peek_char( i + 1 ) != Marker ) { + return false; + } + } + return true; + } + }; + + template< char Marker, char Close > + inline constexpr bool enable_control< at_raw_string_close< Marker, Close > > = false; + + template< typename Cond, typename... Rules > + struct raw_string_until + : raw_string_until< Cond, seq< Rules... > > + {}; + + template< typename Cond > + struct raw_string_until< Cond > + { + using rule_t = raw_string_until; + using subs_t = type_list< Cond >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, const std::size_t& marker_size, States&&... /*unused*/ ) + { + auto m = in.template mark< M >(); + + while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, marker_size ) ) { + if( in.empty() ) { + return false; + } + in.bump(); + } + return m( true ); + } + }; + + template< typename Cond, typename Rule > + struct raw_string_until< Cond, Rule > + { + using rule_t = raw_string_until; + using subs_t = type_list< Cond, Rule >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, const std::size_t& marker_size, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + + while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, marker_size ) ) { + if( !Control< Rule >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) { + return false; + } + } + return m( true ); + } + }; + + template< typename Cond, typename... Rules > + inline constexpr bool enable_control< raw_string_until< Cond, Rules... > > = false; + + } // namespace internal + + // raw_string matches Lua-style long literals. + // + // The following description was taken from the Lua documentation + // (see http://www.lua.org/docs.html): + // + // - An "opening long bracket of level n" is defined as an opening square + // bracket followed by n equal signs followed by another opening square + // bracket. So, an opening long bracket of level 0 is written as `[[`, + // an opening long bracket of level 1 is written as `[=[`, and so on. + // - A "closing long bracket" is defined similarly; for instance, a closing + // long bracket of level 4 is written as `]====]`. + // - A "long literal" starts with an opening long bracket of any level and + // ends at the first closing long bracket of the same level. It can + // contain any text except a closing bracket of the same level. + // - Literals in this bracketed form can run for several lines, do not + // interpret any escape sequences, and ignore long brackets of any other + // level. + // - For convenience, when the opening long bracket is eagerly followed + // by a newline, the newline is not included in the string. + // + // Note that unlike Lua's long literal, a raw_string is customizable to use + // other characters than `[`, `=` and `]` for matching. Also note that Lua + // introduced newline-specific replacements in Lua 5.2, which we do not + // support on the grammar level. + + template< char Open, char Marker, char Close, typename... Contents > + struct raw_string + { + // This is used for binding the apply()-method and for error-reporting + // when a raw string is not closed properly or has invalid content. + struct content + : internal::raw_string_until< internal::at_raw_string_close< Marker, Close >, Contents... > + {}; + + using rule_t = raw_string; + using subs_t = empty_list; // type_list< internal::raw_string_open< Open, Marker >, content >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + std::size_t marker_size; + if( Control< internal::raw_string_open< Open, Marker > >::template match< A, M, Action, Control >( in, marker_size ) ) { + if( Control< content >::template match< A, M, Action, Control >( in, marker_size, st... ) ) { + in.bump_in_this_line( marker_size ); + return true; + } + } + return false; + } + }; + + template< typename Name, char Open, char Marker, char Close > + struct analyze_traits< Name, raw_string< Open, Marker, Close > > + : analyze_any_traits<> + {}; + + template< typename Name, char Open, char Marker, char Close, typename... Contents > + struct analyze_traits< Name, raw_string< Open, Marker, Close, Contents... > > + : analyze_traits< Name, typename seq< any, star< Contents... >, any >::rule_t > + {}; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/remove_first_state.hpp b/pxr/base/pegtl/pegtl/contrib/remove_first_state.hpp new file mode 100644 index 0000000000..2ce80d0c1c --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/remove_first_state.hpp @@ -0,0 +1,72 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_REMOVE_FIRST_STATE_HPP +#define PXR_PEGTL_CONTRIB_REMOVE_FIRST_STATE_HPP + +#include + +#include "../config.hpp" + +#include "../internal/has_unwind.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + // The first state is removed for most of the control functions forwarded to Base, + // start(), success(), failure(), unwind(), raise(), apply(), and apply0(). The call + // to match() is unchanged because it can call other grammar rules that require all + // states when starting their match to keep an even playing field. + + template< typename Base > + struct remove_first_state + : Base + { + template< typename ParseInput, typename State, typename... States > + static void start( const ParseInput& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Base::start( in, st... ) ) ) + { + Base::start( in, st... ); + } + + template< typename ParseInput, typename State, typename... States > + static void success( const ParseInput& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Base::success( in, st... ) ) ) + { + Base::success( in, st... ); + } + + template< typename ParseInput, typename State, typename... States > + static void failure( const ParseInput& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Base::failure( in, st... ) ) ) + { + Base::failure( in, st... ); + } + + template< typename ParseInput, typename State, typename... States > + [[noreturn]] static void raise( const ParseInput& in, State&& /*unused*/, States&&... st ) + { + Base::raise( in, st... ); + } + + template< typename ParseInput, typename State, typename... States > + static auto unwind( const ParseInput& in, State&& /*unused*/, States&&... st ) + -> std::enable_if_t< internal::has_unwind< Base, void, const ParseInput&, States... > > + { + Base::unwind( in, st... ); + } + + template< template< typename... > class Action, typename Iterator, typename ParseInput, typename State, typename... States > + static auto apply( const Iterator& begin, const ParseInput& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Base::template apply< Action >( begin, in, st... ) ) ) + -> decltype( Base::template apply< Action >( begin, in, st... ) ) + { + return Base::template apply< Action >( begin, in, st... ); + } + + template< template< typename... > class Action, typename ParseInput, typename State, typename... States > + static auto apply0( const ParseInput& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Base::template apply0< Action >( in, st... ) ) ) + -> decltype( Base::template apply0< Action >( in, st... ) ) + { + return Base::template apply0< Action >( in, st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/remove_last_states.hpp b/pxr/base/pegtl/pegtl/contrib/remove_last_states.hpp new file mode 100644 index 0000000000..0accd277fc --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/remove_last_states.hpp @@ -0,0 +1,121 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_REMOVE_LAST_STATES_HPP +#define PXR_PEGTL_CONTRIB_REMOVE_LAST_STATES_HPP + +#include +#include + +#include "../config.hpp" + +#include "../internal/has_unwind.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + // The last N states are removed for most of the control functions forwarded to Base, + // start(), success(), failure(), unwind(), raise(), apply(), and apply0(). The call + // to match() is unchanged because it can call other grammar rules that require all + // states when starting their match to keep an even playing field. + + template< typename Base, std::size_t N > + struct remove_last_states + : Base + { + template< typename ParseInput, typename Tuple, std::size_t... Is > + static void start_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::start( in, std::get< Is >( t )... ) ) ) + { + Base::start( in, std::get< Is >( t )... ); + } + + template< typename ParseInput, typename... States > + static void start( const ParseInput& in, States&&... st ) noexcept( noexcept( start_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ) ) ) + { + start_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ); + } + + template< typename ParseInput, typename Tuple, std::size_t... Is > + static void success_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::success( in, std::get< Is >( t )... ) ) ) + { + Base::success( in, std::get< Is >( t )... ); + } + + template< typename ParseInput, typename... States > + static void success( const ParseInput& in, States&&... st ) noexcept( noexcept( success_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ) ) ) + { + success_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ); + } + + template< typename ParseInput, typename Tuple, std::size_t... Is > + static void failure_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::failure( in, std::get< Is >( t )... ) ) ) + { + Base::failure( in, std::get< Is >( t )... ); + } + + template< typename ParseInput, typename... States > + static void failure( const ParseInput& in, States&&... st ) noexcept( noexcept( failure_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ) ) ) + { + failure_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ); + } + + template< typename ParseInput, typename Tuple, std::size_t... Is > + [[noreturn]] static void raise_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) + { + Base::raise( in, std::get< Is >( t )... ); + } + + template< typename ParseInput, typename... States > + [[noreturn]] static void raise( const ParseInput& in, States&&... st ) + { + raise_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ); + } + + template< typename ParseInput, typename Tuple, std::size_t... Is > + static auto unwind_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) + -> std::enable_if_t< internal::has_unwind< Base, void, const ParseInput&, std::tuple_element_t< Is, Tuple >... > > + { + Base::unwind( in, std::get< Is >( t )... ); + } + + template< typename ParseInput, typename... States > + static auto unwind( const ParseInput& in, States&&... st ) + -> decltype( unwind_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ) ) + { + unwind_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ); + } + + template< template< typename... > class Action, typename Iterator, typename ParseInput, typename Tuple, std::size_t... Is > + static auto apply_impl( const Iterator& begin, const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::template apply< Action >( begin, in, std::get< Is >( t )... ) ) ) + -> decltype( Base::template apply< Action >( begin, in, std::get< Is >( t )... ) ) + { + return Base::template apply< Action >( begin, in, std::get< Is >( t )... ); + } + + template< template< typename... > class Action, typename Iterator, typename ParseInput, typename... States > + static auto apply( const Iterator& begin, const ParseInput& in, States&&... st ) noexcept( noexcept( apply_impl< Action >( begin, in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ) ) ) + -> decltype( apply_impl< Action >( begin, in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ) ) + { + return apply_impl< Action >( begin, in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ); + } + + template< template< typename... > class Action, typename ParseInput, typename Tuple, std::size_t... Is > + static auto apply0_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::template apply0< Action >( in, std::get< Is >( t )... ) ) ) + -> decltype( Base::template apply0< Action >( in, std::get< Is >( t )... ) ) + { + return Base::template apply0< Action >( in, std::get< Is >( t )... ); + } + + template< template< typename... > class Action, typename ParseInput, typename... States > + static auto apply0( const ParseInput& in, States&&... st ) noexcept( noexcept( apply0_impl< Action >( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ) ) ) + -> decltype( apply0_impl< Action >( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ) ) + { + return apply0_impl< Action >( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) - N >() ); + } + }; + + template< typename Base > + using remove_last_state = remove_last_states< Base, 1 >; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/rep_one_min_max.hpp b/pxr/base/pegtl/pegtl/contrib/rep_one_min_max.hpp new file mode 100644 index 0000000000..d07628bea2 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/rep_one_min_max.hpp @@ -0,0 +1,100 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_REP_ONE_MIN_MAX_HPP +#define PXR_PEGTL_CONTRIB_REP_ONE_MIN_MAX_HPP + +#include +#include + +#include "../config.hpp" +#include "../type_list.hpp" + +#include "../internal/bump_help.hpp" +#include "../internal/bytes.hpp" +#include "../internal/enable_control.hpp" +#include "../internal/opt.hpp" + +#include "analyze_traits.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< unsigned Min, unsigned Max, char C > + struct rep_one_min_max + { + using rule_t = rep_one_min_max; + using subs_t = empty_list; + + static_assert( Min <= Max ); + + template< int Eol > + static constexpr bool can_match_eol = ( C == Eol ); + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) + { + const auto size = in.size( Max + 1 ); + if( size < Min ) { + return false; + } + std::size_t i = 0; + while( ( i < size ) && ( in.peek_char( i ) == C ) ) { + ++i; + } + if( ( Min <= i ) && ( i <= Max ) ) { + bump_help< rep_one_min_max >( in, i ); + return true; + } + return false; + } + }; + + template< unsigned Max, char C > + struct rep_one_min_max< 0, Max, C > + { + using rule_t = rep_one_min_max; + using subs_t = empty_list; + + template< int Eol > + static constexpr bool can_match_eol = ( C == Eol ); + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) + { + const auto size = in.size( Max + 1 ); + std::size_t i = 0; + while( ( i < size ) && ( in.peek_char( i ) == C ) ) { + ++i; + } + if( i <= Max ) { + bump_help< rep_one_min_max >( in, i ); + return true; + } + return false; + } + }; + + template< unsigned Min, unsigned Max, char C > + inline constexpr bool enable_control< rep_one_min_max< Min, Max, C > > = false; + + } // namespace internal + + inline namespace ascii + { + template< unsigned Min, unsigned Max, char C > + struct rep_one_min_max + : internal::rep_one_min_max< Min, Max, C > + {}; + + } // namespace ascii + + template< typename Name, unsigned Min, unsigned Max, char C > + struct analyze_traits< Name, internal::rep_one_min_max< Min, Max, C > > + : std::conditional_t< ( Min != 0 ), analyze_any_traits<>, analyze_opt_traits<> > + {}; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/rep_string.hpp b/pxr/base/pegtl/pegtl/contrib/rep_string.hpp new file mode 100644 index 0000000000..3e884df9bd --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/rep_string.hpp @@ -0,0 +1,43 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_REP_STRING_HPP +#define PXR_PEGTL_CONTRIB_REP_STRING_HPP + +#include + +#include "../config.hpp" +#include "../internal/string.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< std::size_t, typename, char... > + struct make_rep_string; + + template< char... Ss, char... Cs > + struct make_rep_string< 0, string< Ss... >, Cs... > + { + using type = string< Ss... >; + }; + + template< std::size_t N, char... Ss, char... Cs > + struct make_rep_string< N, string< Ss... >, Cs... > + : make_rep_string< N - 1, string< Ss..., Cs... >, Cs... > + {}; + + } // namespace internal + + inline namespace ascii + { + template< std::size_t N, char... Cs > + struct rep_string + : internal::make_rep_string< N, internal::string<>, Cs... >::type + {}; + + } // namespace ascii + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/separated_seq.hpp b/pxr/base/pegtl/pegtl/contrib/separated_seq.hpp new file mode 100644 index 0000000000..63d3200575 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/separated_seq.hpp @@ -0,0 +1,45 @@ +// Copyright (c) 2021-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_SEPARATED_SEQ_HPP +#define PXR_PEGTL_CONTRIB_SEPARATED_SEQ_HPP + +#include "../config.hpp" + +#include "../internal/seq.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename... > + struct sep; + + template< typename... Ts, typename S, typename Rule, typename... Rules > + struct sep< type_list< Ts... >, S, Rule, Rules... > + : sep< type_list< Ts..., Rule, S >, S, Rules... > + {}; + + template< typename... Ts, typename S, typename Rule > + struct sep< type_list< Ts... >, S, Rule > + { + using type = seq< Ts..., Rule >; + }; + + template< typename S > + struct sep< type_list<>, S > + { + using type = seq<>; + }; + + } // namespace internal + + template< typename S, typename... Rules > + struct separated_seq + : internal::sep< type_list<>, S, Rules... >::type + {}; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/shuffle_states.hpp b/pxr/base/pegtl/pegtl/contrib/shuffle_states.hpp new file mode 100644 index 0000000000..936a789933 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/shuffle_states.hpp @@ -0,0 +1,193 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_SHUFFLE_STATES_HPP +#define PXR_PEGTL_CONTRIB_SHUFFLE_STATES_HPP + +#include +#include +#include + +#include "../config.hpp" + +#include "../internal/has_unwind.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< std::size_t N > + struct rotate_left + { + template< std::size_t I, std::size_t S > + static constexpr std::size_t value = ( I + N ) % S; + }; + + template< std::size_t N > + struct rotate_right + { + template< std::size_t I, std::size_t S > + static constexpr std::size_t value = ( I + S - N ) % S; + }; + + struct reverse + { + template< std::size_t I, std::size_t S > + static constexpr std::size_t value = ( S - 1 ) - I; + }; + + } // namespace internal + + // Applies 'Shuffle' to the states of start(), success(), failure(), raise(), apply(), and apply0() + template< typename Base, typename Shuffle > + struct shuffle_states + : Base + { + template< typename ParseInput, typename Tuple, std::size_t... Is > + static void start_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::start( in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ) ) ) + { + Base::start( in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ); + } + + template< typename ParseInput, typename... States > + static void start( const ParseInput& in, States&&... st ) noexcept( noexcept( start_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ) ) ) + { + start_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ); + } + + template< typename ParseInput, typename State > + static void start( const ParseInput& in, State&& st ) noexcept( noexcept( Base::start( in, st ) ) ) + { + Base::start( in, st ); + } + + template< typename ParseInput, typename Tuple, std::size_t... Is > + static void success_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::success( in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ) ) ) + { + Base::success( in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ); + } + + template< typename ParseInput, typename... States > + static void success( const ParseInput& in, States&&... st ) noexcept( noexcept( success_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ) ) ) + { + success_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ); + } + + template< typename ParseInput, typename State > + static void success( const ParseInput& in, State&& st ) noexcept( noexcept( Base::success( in, st ) ) ) + { + Base::success( in, st ); + } + + template< typename ParseInput, typename Tuple, std::size_t... Is > + static void failure_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::failure( in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ) ) ) + { + Base::failure( in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ); + } + + template< typename ParseInput, typename... States > + static void failure( const ParseInput& in, States&&... st ) noexcept( noexcept( failure_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ) ) ) + { + failure_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ); + } + + template< typename ParseInput, typename State > + static void failure( const ParseInput& in, State&& st ) noexcept( noexcept( Base::failure( in, st ) ) ) + { + Base::failure( in, st ); + } + + template< typename ParseInput, typename Tuple, std::size_t... Is > + [[noreturn]] static void raise_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) + { + Base::raise( in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ); + } + + template< typename ParseInput, typename... States > + [[noreturn]] static void raise( const ParseInput& in, States&&... st ) + { + raise_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ); + } + + template< typename ParseInput, typename State > + [[noreturn]] static void raise( const ParseInput& in, State&& st ) + { + Base::raise( in, st ); + } + + template< typename ParseInput, typename Tuple, std::size_t... Is > + static auto unwind_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) + -> std::enable_if_t< internal::has_unwind< Base, void, const ParseInput&, std::tuple_element_t< Shuffle::template value< Is, sizeof...( Is ) >, Tuple >... > > + { + Base::unwind( in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ); + } + + template< typename ParseInput, typename... States > + static auto unwind( const ParseInput& in, States&&... st ) + -> decltype( unwind_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ) ) + { + unwind_impl( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ); + } + + template< typename ParseInput, typename State > + static auto unwind( const ParseInput& in, State&& st ) + -> std::enable_if_t< internal::has_unwind< Base, void, const ParseInput&, State > > + { + Base::unwind( in, st ); + } + + template< template< typename... > class Action, typename Iterator, typename ParseInput, typename Tuple, std::size_t... Is > + static auto apply_impl( const Iterator& begin, const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::template apply< Action >( begin, in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ) ) ) + -> decltype( Base::template apply< Action >( begin, in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ) ) + { + return Base::template apply< Action >( begin, in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ); + } + + template< template< typename... > class Action, typename Iterator, typename ParseInput, typename... States > + static auto apply( const Iterator& begin, const ParseInput& in, States&&... st ) noexcept( noexcept( apply_impl< Action >( begin, in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ) ) ) + -> decltype( apply_impl< Action >( begin, in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ) ) + { + return apply_impl< Action >( begin, in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ); + } + + template< template< typename... > class Action, typename Iterator, typename ParseInput, typename State > + static auto apply( const Iterator& begin, const ParseInput& in, State&& st ) noexcept( noexcept( Base::template apply< Action >( begin, in, st ) ) ) + -> decltype( Base::template apply< Action >( begin, in, st ) ) + { + return Base::template apply< Action >( begin, in, st ); + } + + template< template< typename... > class Action, typename ParseInput, typename Tuple, std::size_t... Is > + static auto apply0_impl( const ParseInput& in, const Tuple& t, std::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::template apply0< Action >( in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ) ) ) + -> decltype( Base::template apply0< Action >( in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ) ) + { + return Base::template apply0< Action >( in, std::get< Shuffle::template value< Is, sizeof...( Is ) > >( t )... ); + } + + template< template< typename... > class Action, typename ParseInput, typename... States > + static auto apply0( const ParseInput& in, States&&... st ) noexcept( noexcept( apply0_impl< Action >( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ) ) ) + -> decltype( apply0_impl< Action >( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ) ) + { + return apply0_impl< Action >( in, std::tie( st... ), std::make_index_sequence< sizeof...( st ) >() ); + } + + template< template< typename... > class Action, typename ParseInput, typename State > + static auto apply0( const ParseInput& in, State&& st ) noexcept( noexcept( Base::template apply0< Action >( in, st ) ) ) + -> decltype( Base::template apply0< Action >( in, st ) ) + { + return Base::template apply0< Action >( in, st ); + } + }; + + template< typename Base, std::size_t N = 1 > + using rotate_states_left = shuffle_states< Base, internal::rotate_left< N > >; + + template< typename Base, std::size_t N = 1 > + using rotate_states_right = shuffle_states< Base, internal::rotate_right< N > >; + + template< typename Base > + using reverse_states = shuffle_states< Base, internal::reverse >; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/state_control.hpp b/pxr/base/pegtl/pegtl/contrib/state_control.hpp new file mode 100644 index 0000000000..c1ec46e590 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/state_control.hpp @@ -0,0 +1,122 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_STATE_CONTROL_HPP +#define PXR_PEGTL_CONTRIB_STATE_CONTROL_HPP + +#include + +#include "shuffle_states.hpp" + +#include "../config.hpp" +#include "../internal/has_unwind.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< template< typename... > class Control > + struct state_control + { + template< typename Rule > + struct control + : Control< Rule > + { + static constexpr bool enable = true; + + template< typename ParseInput, typename State, typename... States > + static void start( [[maybe_unused]] const ParseInput& in, [[maybe_unused]] State& state, [[maybe_unused]] States&&... st ) + { + if constexpr( Control< Rule >::enable ) { + Control< Rule >::start( in, st... ); + } + if constexpr( State::template enable< Rule > ) { + state.template start< Rule >( in, st... ); + } +#if defined( _MSC_VER ) + ( (void)st, + ... ); +#endif + } + + template< typename ParseInput, typename State, typename... States > + static void success( [[maybe_unused]] const ParseInput& in, [[maybe_unused]] State& state, [[maybe_unused]] States&&... st ) + { + if constexpr( State::template enable< Rule > ) { + state.template success< Rule >( in, st... ); + } + if constexpr( Control< Rule >::enable ) { + Control< Rule >::success( in, st... ); + } +#if defined( _MSC_VER ) + ( (void)st, + ... ); +#endif + } + + template< typename ParseInput, typename State, typename... States > + static void failure( [[maybe_unused]] const ParseInput& in, [[maybe_unused]] State& state, [[maybe_unused]] States&&... st ) + { + if constexpr( State::template enable< Rule > ) { + state.template failure< Rule >( in, st... ); + } + if constexpr( Control< Rule >::enable ) { + Control< Rule >::failure( in, st... ); + } +#if defined( _MSC_VER ) + ( (void)st, + ... ); +#endif + } + + template< typename ParseInput, typename State, typename... States > + [[noreturn]] static void raise( const ParseInput& in, [[maybe_unused]] State& state, States&&... st ) + { + if constexpr( State::template enable< Rule > ) { + state.template raise< Rule >( in, st... ); + } + Control< Rule >::raise( in, st... ); + } + + template< typename ParseInput, typename State, typename... States > + static auto unwind( [[maybe_unused]] const ParseInput& in, [[maybe_unused]] State& state, [[maybe_unused]] States&&... st ) + -> std::enable_if_t< State::template enable< Rule > || ( Control< Rule >::enable && internal::has_unwind< Control< Rule >, void, const ParseInput&, States... > ) > + { + if constexpr( State::template enable< Rule > ) { + state.template unwind< Rule >( in, st... ); + } + if constexpr( Control< Rule >::enable && internal::has_unwind< Control< Rule >, void, const ParseInput&, States... > ) { + Control< Rule >::unwind( in, st... ); + } +#if defined( _MSC_VER ) + ( (void)st, + ... ); +#endif + } + + template< template< typename... > class Action, typename Iterator, typename ParseInput, typename State, typename... States > + static auto apply( const Iterator& begin, const ParseInput& in, [[maybe_unused]] State& state, States&&... st ) + -> decltype( Control< Rule >::template apply< Action >( begin, in, st... ) ) + { + if constexpr( State::template enable< Rule > ) { + state.template apply< Rule >( in, st... ); + } + return Control< Rule >::template apply< Action >( begin, in, st... ); + } + + template< template< typename... > class Action, typename ParseInput, typename State, typename... States > + static auto apply0( const ParseInput& in, [[maybe_unused]] State& state, States&&... st ) + -> decltype( Control< Rule >::template apply0< Action >( in, st... ) ) + { + if constexpr( State::template enable< Rule > ) { + state.template apply0< Rule >( in, st... ); + } + return Control< Rule >::template apply0< Action >( in, st... ); + } + }; + + template< typename Rule > + using type = rotate_states_right< control< Rule > >; + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/to_string.hpp b/pxr/base/pegtl/pegtl/contrib/to_string.hpp new file mode 100644 index 0000000000..d19540fef8 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/to_string.hpp @@ -0,0 +1,38 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_TO_STRING_HPP +#define PXR_PEGTL_CONTRIB_TO_STRING_HPP + +#include + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename > + struct to_string; + + template< template< char... > class X, char... Cs > + struct to_string< X< Cs... > > + { + [[nodiscard]] static std::string get() + { + const char s[] = { Cs..., 0 }; + return std::string( s, sizeof...( Cs ) ); + } + }; + + } // namespace internal + + template< typename T > + [[nodiscard]] std::string to_string() + { + return internal::to_string< T >::get(); + } + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/trace.hpp b/pxr/base/pegtl/pegtl/contrib/trace.hpp new file mode 100644 index 0000000000..b789b0d680 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/trace.hpp @@ -0,0 +1,227 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_TRACE_HPP +#define PXR_PEGTL_CONTRIB_TRACE_HPP + +#include +#include +#include +#include +#include + +#include "state_control.hpp" + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../demangle.hpp" +#include "../normal.hpp" +#include "../nothing.hpp" +#include "../parse.hpp" +#include "../rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< bool HideInternal = false, bool UseColor = true, std::size_t IndentIncrement = 2, std::size_t InitialIndent = 8 > + struct tracer_traits + { + template< typename Rule > + static constexpr bool enable = ( HideInternal ? normal< Rule >::enable : true ); + + static constexpr std::size_t initial_indent = InitialIndent; + static constexpr std::size_t indent_increment = IndentIncrement; + + static constexpr std::string_view ansi_reset = UseColor ? "\033[m" : ""; + static constexpr std::string_view ansi_rule = UseColor ? "\033[36m" : ""; + static constexpr std::string_view ansi_hide = UseColor ? "\033[37m" : ""; + + static constexpr std::string_view ansi_position = UseColor ? "\033[1;34m" : ""; + static constexpr std::string_view ansi_success = UseColor ? "\033[32m" : ""; + static constexpr std::string_view ansi_failure = UseColor ? "\033[31m" : ""; + static constexpr std::string_view ansi_raise = UseColor ? "\033[1;31m" : ""; + static constexpr std::string_view ansi_unwind = UseColor ? "\033[31m" : ""; + static constexpr std::string_view ansi_apply = UseColor ? "\033[1;36m" : ""; + }; + + using standard_tracer_traits = tracer_traits< true >; + using complete_tracer_traits = tracer_traits< false >; + + template< typename TracerTraits > + struct tracer + { + const std::ios_base::fmtflags m_flags; + std::size_t m_count = 0; + std::vector< std::size_t > m_stack; + position m_position; + + template< typename Rule > + static constexpr bool enable = TracerTraits::template enable< Rule >; + + template< typename ParseInput > + explicit tracer( const ParseInput& in ) + : m_flags( std::cerr.flags() ), + m_position( in.position() ) + { + std::cerr << std::left; + print_position(); + } + + tracer( const tracer& ) = delete; + tracer( tracer&& ) = delete; + + ~tracer() + { + std::cerr.flags( m_flags ); + } + + tracer& operator=( const tracer& ) = delete; + tracer& operator=( tracer&& ) = delete; + + [[nodiscard]] std::size_t indent() const noexcept + { + return TracerTraits::initial_indent + TracerTraits::indent_increment * m_stack.size(); + } + + void print_position() const + { + std::cerr << std::setw( indent() ) << ' ' << TracerTraits::ansi_position << "position" << TracerTraits::ansi_reset << ' ' << m_position << '\n'; + } + + void update_position( const position& p ) + { + if( m_position != p ) { + m_position = p; + print_position(); + } + } + + template< typename Rule, typename ParseInput, typename... States > + void start( const ParseInput& /*unused*/, States&&... /*unused*/ ) + { + std::cerr << '#' << std::setw( indent() - 1 ) << ++m_count << TracerTraits::ansi_rule << demangle< Rule >() << TracerTraits::ansi_reset << '\n'; + m_stack.push_back( m_count ); + } + + template< typename Rule, typename ParseInput, typename... States > + void success( const ParseInput& in, States&&... /*unused*/ ) + { + const auto prev = m_stack.back(); + m_stack.pop_back(); + std::cerr << std::setw( indent() ) << ' ' << TracerTraits::ansi_success << "success" << TracerTraits::ansi_reset; + if( m_count != prev ) { + std::cerr << " #" << prev << ' ' << TracerTraits::ansi_hide << demangle< Rule >() << TracerTraits::ansi_reset; + } + std::cerr << '\n'; + update_position( in.position() ); + } + + template< typename Rule, typename ParseInput, typename... States > + void failure( const ParseInput& in, States&&... /*unused*/ ) + { + const auto prev = m_stack.back(); + m_stack.pop_back(); + std::cerr << std::setw( indent() ) << ' ' << TracerTraits::ansi_failure << "failure" << TracerTraits::ansi_reset; + if( m_count != prev ) { + std::cerr << " #" << prev << ' ' << TracerTraits::ansi_hide << demangle< Rule >() << TracerTraits::ansi_reset; + } + std::cerr << '\n'; + update_position( in.position() ); + } + + template< typename Rule, typename ParseInput, typename... States > + void raise( const ParseInput& /*unused*/, States&&... /*unused*/ ) + { + std::cerr << std::setw( indent() ) << ' ' << TracerTraits::ansi_raise << "raise" << TracerTraits::ansi_reset << ' ' << TracerTraits::ansi_rule << demangle< Rule >() << TracerTraits::ansi_reset << '\n'; + } + + template< typename Rule, typename ParseInput, typename... States > + void unwind( const ParseInput& in, States&&... /*unused*/ ) + { + const auto prev = m_stack.back(); + m_stack.pop_back(); + std::cerr << std::setw( indent() ) << ' ' << TracerTraits::ansi_unwind << "unwind" << TracerTraits::ansi_reset; + if( m_count != prev ) { + std::cerr << " #" << prev << ' ' << TracerTraits::ansi_hide << demangle< Rule >() << TracerTraits::ansi_reset; + } + std::cerr << '\n'; + update_position( in.position() ); + } + + template< typename Rule, typename ParseInput, typename... States > + void apply( const ParseInput& /*unused*/, States&&... /*unused*/ ) + { + std::cerr << std::setw( static_cast< int >( indent() - TracerTraits::indent_increment ) ) << ' ' << TracerTraits::ansi_apply << "apply" << TracerTraits::ansi_reset << '\n'; + } + + template< typename Rule, typename ParseInput, typename... States > + void apply0( const ParseInput& /*unused*/, States&&... /*unused*/ ) + { + std::cerr << std::setw( static_cast< int >( indent() - TracerTraits::indent_increment ) ) << ' ' << TracerTraits::ansi_apply << "apply0" << TracerTraits::ansi_reset << '\n'; + } + + template< typename Rule, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + typename ParseInput, + typename... States > + bool parse( ParseInput&& in, States&&... st ) + { + return PXR_PEGTL_NAMESPACE::parse< Rule, Action, state_control< Control >::template type >( in, st..., *this ); + } + }; + + template< typename Rule, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + typename ParseInput, + typename... States > + bool standard_trace( ParseInput&& in, States&&... st ) + { + tracer< standard_tracer_traits > tr( in ); + return tr.parse< Rule, Action, Control >( in, st... ); + } + + template< typename Rule, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + typename ParseInput, + typename... States > + bool complete_trace( ParseInput&& in, States&&... st ) + { + tracer< complete_tracer_traits > tr( in ); + return tr.parse< Rule, Action, Control >( in, st... ); + } + + template< typename Tracer > + struct trace + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + if constexpr( sizeof...( st ) == 0 ) { + return PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, state_control< Control >::template type >( in, st..., Tracer( in ) ); + } + else if constexpr( !std::is_same_v< std::tuple_element_t< sizeof...( st ) - 1, std::tuple< States... > >, Tracer& > ) { + return PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, state_control< Control >::template type >( in, st..., Tracer( in ) ); + } + else { + return PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); + } + } + }; + + using trace_standard = trace< tracer< standard_tracer_traits > >; + using trace_complete = trace< tracer< complete_tracer_traits > >; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/uint16.hpp b/pxr/base/pegtl/pegtl/contrib/uint16.hpp new file mode 100644 index 0000000000..82e30ca981 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/uint16.hpp @@ -0,0 +1,62 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_UINT16_HPP +#define PXR_PEGTL_CONTRIB_UINT16_HPP + +#include "../config.hpp" +#include "../internal/result_on_found.hpp" +#include "../internal/rules.hpp" + +#include "internal/peek_mask_uint.hpp" +#include "internal/peek_uint.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace uint16_be + { + // clang-format off + struct any : internal::any< internal::peek_uint16_be > {}; + + template< std::uint16_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint16_be, Cs... > {}; + template< std::uint16_t Lo, std::uint16_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint16_be, Lo, Hi > {}; + template< std::uint16_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint16_be, Cs... > {}; + template< std::uint16_t Lo, std::uint16_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint16_be, Lo, Hi > {}; + template< std::uint16_t... Cs > struct ranges : internal::ranges< internal::peek_uint16_be, Cs... > {}; + template< std::uint16_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint16_be, Cs >... > {}; + + template< std::uint16_t M, std::uint16_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint16_be< M >, Cs... > {}; + template< std::uint16_t M, std::uint16_t Lo, std::uint16_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint16_be< M >, Lo, Hi > {}; + template< std::uint16_t M, std::uint16_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint16_be< M >, Cs... > {}; + template< std::uint16_t M, std::uint16_t Lo, std::uint16_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint16_be< M >, Lo, Hi > {}; + template< std::uint16_t M, std::uint16_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint16_be< M >, Cs... > {}; + template< std::uint16_t M, std::uint16_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint16_be< M >, Cs >... > {}; + // clang-format on + + } // namespace uint16_be + + namespace uint16_le + { + // clang-format off + struct any : internal::any< internal::peek_uint16_le > {}; + + template< std::uint16_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint16_le, Cs... > {}; + template< std::uint16_t Lo, std::uint16_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint16_le, Lo, Hi > {}; + template< std::uint16_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint16_le, Cs... > {}; + template< std::uint16_t Lo, std::uint16_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint16_le, Lo, Hi > {}; + template< std::uint16_t... Cs > struct ranges : internal::ranges< internal::peek_uint16_le, Cs... > {}; + template< std::uint16_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint16_le, Cs >... > {}; + + template< std::uint16_t M, std::uint16_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint16_le< M >, Cs... > {}; + template< std::uint16_t M, std::uint16_t Lo, std::uint16_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint16_le< M >, Lo, Hi > {}; + template< std::uint16_t M, std::uint16_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint16_le< M >, Cs... > {}; + template< std::uint16_t M, std::uint16_t Lo, std::uint16_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint16_le< M >, Lo, Hi > {}; + template< std::uint16_t M, std::uint16_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint16_le< M >, Cs... > {}; + template< std::uint16_t M, std::uint16_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint16_le< M >, Cs >... > {}; + // clang-format on + + } // namespace uint16_le + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/uint32.hpp b/pxr/base/pegtl/pegtl/contrib/uint32.hpp new file mode 100644 index 0000000000..12079d9c10 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/uint32.hpp @@ -0,0 +1,62 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_UINT32_HPP +#define PXR_PEGTL_CONTRIB_UINT32_HPP + +#include "../config.hpp" +#include "../internal/result_on_found.hpp" +#include "../internal/rules.hpp" + +#include "internal/peek_mask_uint.hpp" +#include "internal/peek_uint.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace uint32_be + { + // clang-format off + struct any : internal::any< internal::peek_uint32_be > {}; + + template< std::uint32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint32_be, Cs... > {}; + template< std::uint32_t Lo, std::uint32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint32_be, Lo, Hi > {}; + template< std::uint32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint32_be, Cs... > {}; + template< std::uint32_t Lo, std::uint32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint32_be, Lo, Hi > {}; + template< std::uint32_t... Cs > struct ranges : internal::ranges< internal::peek_uint32_be, Cs... > {}; + template< std::uint32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint32_be, Cs >... > {}; + + template< std::uint32_t M, std::uint32_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint32_be< M >, Cs... > {}; + template< std::uint32_t M, std::uint32_t Lo, std::uint32_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint32_be< M >, Lo, Hi > {}; + template< std::uint32_t M, std::uint32_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint32_be< M >, Cs... > {}; + template< std::uint32_t M, std::uint32_t Lo, std::uint32_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint32_be< M >, Lo, Hi > {}; + template< std::uint32_t M, std::uint32_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint32_be< M >, Cs... > {}; + template< std::uint32_t M, std::uint32_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint32_be< M >, Cs >... > {}; + // clang-format on + + } // namespace uint32_be + + namespace uint32_le + { + // clang-format off + struct any : internal::any< internal::peek_uint32_le > {}; + + template< std::uint32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint32_le, Cs... > {}; + template< std::uint32_t Lo, std::uint32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint32_le, Lo, Hi > {}; + template< std::uint32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint32_le, Cs... > {}; + template< std::uint32_t Lo, std::uint32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint32_le, Lo, Hi > {}; + template< std::uint32_t... Cs > struct ranges : internal::ranges< internal::peek_uint32_le, Cs... > {}; + template< std::uint32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint32_le, Cs >... > {}; + + template< std::uint32_t M, std::uint32_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint32_le< M >, Cs... > {}; + template< std::uint32_t M, std::uint32_t Lo, std::uint32_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint32_le< M >, Lo, Hi > {}; + template< std::uint32_t M, std::uint32_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint32_le< M >, Cs... > {}; + template< std::uint32_t M, std::uint32_t Lo, std::uint32_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint32_le< M >, Lo, Hi > {}; + template< std::uint32_t M, std::uint32_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint32_le< M >, Cs... > {}; + template< std::uint32_t M, std::uint32_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint32_le< M >, Cs >... > {}; + // clang-format on + + } // namespace uint32_le + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/uint64.hpp b/pxr/base/pegtl/pegtl/contrib/uint64.hpp new file mode 100644 index 0000000000..6f5caf18d2 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/uint64.hpp @@ -0,0 +1,63 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_UINT64_HPP +#define PXR_PEGTL_CONTRIB_UINT64_HPP + +#include "../config.hpp" +#include "../internal/result_on_found.hpp" +#include "../internal/rules.hpp" + +#include "internal/peek_mask_uint.hpp" +#include "internal/peek_uint.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace uint64_be + { + // clang-format off + struct any : internal::any< internal::peek_uint64_be > {}; + + template< std::uint64_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint64_be, Cs... > {}; + template< std::uint64_t Lo, std::uint64_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint64_be, Lo, Hi > {}; + template< std::uint64_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint64_be, Cs... > {}; + template< std::uint64_t Lo, std::uint64_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint64_be, Lo, Hi > {}; + template< std::uint64_t... Cs > struct ranges : internal::ranges< internal::peek_uint64_be, Cs... > {}; + template< std::uint64_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint64_be, Cs >... > {}; + + + template< std::uint64_t M, std::uint64_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint64_be< M >, Cs... > {}; + template< std::uint64_t M, std::uint64_t Lo, std::uint64_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint64_be< M >, Lo, Hi > {}; + template< std::uint64_t M, std::uint64_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint64_be< M >, Cs... > {}; + template< std::uint64_t M, std::uint64_t Lo, std::uint64_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint64_be< M >, Lo, Hi > {}; + template< std::uint64_t M, std::uint64_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint64_be< M >, Cs... > {}; + template< std::uint64_t M, std::uint64_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint64_be< M >, Cs >... > {}; + // clang-format on + + } // namespace uint64_be + + namespace uint64_le + { + // clang-format off + struct any : internal::any< internal::peek_uint64_le > {}; + + template< std::uint64_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint64_le, Cs... > {}; + template< std::uint64_t Lo, std::uint64_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint64_le, Lo, Hi > {}; + template< std::uint64_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint64_le, Cs... > {}; + template< std::uint64_t Lo, std::uint64_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint64_le, Lo, Hi > {}; + template< std::uint64_t... Cs > struct ranges : internal::ranges< internal::peek_uint64_le, Cs... > {}; + template< std::uint64_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint64_le, Cs >... > {}; + + template< std::uint64_t M, std::uint64_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint64_le< M >, Cs... > {}; + template< std::uint64_t M, std::uint64_t Lo, std::uint64_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint64_le< M >, Lo, Hi > {}; + template< std::uint64_t M, std::uint64_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint64_le< M >, Cs... > {}; + template< std::uint64_t M, std::uint64_t Lo, std::uint64_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint64_le< M >, Lo, Hi > {}; + template< std::uint64_t M, std::uint64_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint64_le< M >, Cs... > {}; + template< std::uint64_t M, std::uint64_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint64_le< M >, Cs >... > {}; + // clang-format on + + } // namespace uint64_le + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/uint8.hpp b/pxr/base/pegtl/pegtl/contrib/uint8.hpp new file mode 100644 index 0000000000..867d13e2e8 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/uint8.hpp @@ -0,0 +1,36 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_UINT8_HPP +#define PXR_PEGTL_CONTRIB_UINT8_HPP + +#include "../config.hpp" +#include "../internal/result_on_found.hpp" +#include "../internal/rules.hpp" + +#include "internal/peek_mask_uint8.hpp" +#include "internal/peek_uint8.hpp" + +namespace PXR_PEGTL_NAMESPACE::uint8 +{ + // clang-format off + struct any : internal::any< internal::peek_uint8 > {}; + + template< std::uint8_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint8, Cs... > {}; + template< std::uint8_t Lo, std::uint8_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint8, Lo, Hi > {}; + template< std::uint8_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint8, Cs... > {}; + template< std::uint8_t Lo, std::uint8_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint8, Lo, Hi > {}; + template< std::uint8_t... Cs > struct ranges : internal::ranges< internal::peek_uint8, Cs... > {}; + template< std::uint8_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint8, Cs >... > {}; + + template< std::uint8_t M, std::uint8_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint8< M >, Cs... > {}; + template< std::uint8_t M, std::uint8_t Lo, std::uint8_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint8< M >, Lo, Hi > {}; + template< std::uint8_t M, std::uint8_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint8< M >, Cs... > {}; + template< std::uint8_t M, std::uint8_t Lo, std::uint8_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint8< M >, Lo, Hi > {}; + template< std::uint8_t M, std::uint8_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint8< M >, Cs... > {}; + template< std::uint8_t M, std::uint8_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint8< M >, Cs >... > {}; + // clang-format on + +} // namespace PXR_PEGTL_NAMESPACE::uint8 + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/unescape.hpp b/pxr/base/pegtl/pegtl/contrib/unescape.hpp new file mode 100644 index 0000000000..d611120f29 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/unescape.hpp @@ -0,0 +1,214 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_UNESCAPE_HPP +#define PXR_PEGTL_CONTRIB_UNESCAPE_HPP + +#include +#include +#include + +#include "../ascii.hpp" +#include "../config.hpp" +#include "../parse_error.hpp" + +namespace PXR_PEGTL_NAMESPACE::unescape +{ + // Utility functions for the unescape actions. + + [[nodiscard]] inline bool utf8_append_utf32( std::string& string, const unsigned utf32 ) + { + if( utf32 <= 0x7f ) { + string += char( utf32 & 0xff ); + return true; + } + if( utf32 <= 0x7ff ) { + char tmp[] = { char( ( ( utf32 & 0x7c0 ) >> 6 ) | 0xc0 ), + char( ( ( utf32 & 0x03f ) ) | 0x80 ) }; + string.append( tmp, sizeof( tmp ) ); + return true; + } + if( utf32 <= 0xffff ) { + if( utf32 >= 0xd800 && utf32 <= 0xdfff ) { + // nope, this is a UTF-16 surrogate + return false; + } + char tmp[] = { char( ( ( utf32 & 0xf000 ) >> 12 ) | 0xe0 ), + char( ( ( utf32 & 0x0fc0 ) >> 6 ) | 0x80 ), + char( ( ( utf32 & 0x003f ) ) | 0x80 ) }; + string.append( tmp, sizeof( tmp ) ); + return true; + } + if( utf32 <= 0x10ffff ) { + char tmp[] = { char( ( ( utf32 & 0x1c0000 ) >> 18 ) | 0xf0 ), + char( ( ( utf32 & 0x03f000 ) >> 12 ) | 0x80 ), + char( ( ( utf32 & 0x000fc0 ) >> 6 ) | 0x80 ), + char( ( ( utf32 & 0x00003f ) ) | 0x80 ) }; + string.append( tmp, sizeof( tmp ) ); + return true; + } + return false; + } + + // This function MUST only be called for characters matching PXR_PEGTL_NAMESPACE::ascii::xdigit! + template< typename I > + [[nodiscard]] I unhex_char( const char c ) + { + switch( c ) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return I( c - '0' ); + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + return I( c - 'a' + 10 ); + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + return I( c - 'A' + 10 ); + default: // LCOV_EXCL_LINE + std::terminate(); // LCOV_EXCL_LINE + } + } + + template< typename I > + [[nodiscard]] I unhex_string( const char* begin, const char* end ) + { + I r = 0; + while( begin != end ) { + r <<= 4; + r += unhex_char< I >( *begin++ ); + } + return r; + } + + // Actions for common unescape situations. + + struct append_all + { + template< typename ActionInput > + static void apply( const ActionInput& in, std::string& s ) + { + s.append( in.begin(), in.size() ); + } + }; + + // This action MUST be called for a character matching T which MUST be PXR_PEGTL_NAMESPACE::one< ... >. + template< typename T, char... Rs > + struct unescape_c + { + template< typename ActionInput > + static void apply( const ActionInput& in, std::string& s ) + { + assert( in.size() == 1 ); + s += apply_one( in, static_cast< const T* >( nullptr ) ); + } + + template< typename ActionInput, char... Qs > + [[nodiscard]] static char apply_one( const ActionInput& in, const one< Qs... >* /*unused*/ ) + { + static_assert( sizeof...( Qs ) == sizeof...( Rs ), "size mismatch between escaped characters and their mappings" ); + return apply_two( in, { Qs... }, { Rs... } ); + } + + template< typename ActionInput > + [[nodiscard]] static char apply_two( const ActionInput& in, const std::initializer_list< char >& q, const std::initializer_list< char >& r ) + { + const char c = *in.begin(); + for( std::size_t i = 0; i < q.size(); ++i ) { + if( *( q.begin() + i ) == c ) { + return *( r.begin() + i ); + } + } + std::terminate(); // LCOV_EXCL_LINE + } + }; + + // See src/example/pegtl/unescape.cpp for why the following two actions + // skip the first input character. They also MUST be called + // with non-empty matched inputs! + + struct unescape_u + { +#if defined( __cpp_exceptions ) + template< typename ActionInput > + static void apply( const ActionInput& in, std::string& s ) + { + assert( !in.empty() ); // First character MUST be present, usually 'u' or 'U'. + if( !utf8_append_utf32( s, unhex_string< unsigned >( in.begin() + 1, in.end() ) ) ) { + throw parse_error( "invalid escaped unicode code point", in ); + } + } +#else + template< typename ActionInput > + static bool apply( const ActionInput& in, std::string& s ) + { + assert( !in.empty() ); // First character MUST be present, usually 'u' or 'U'. + return utf8_append_utf32( s, unhex_string< unsigned >( in.begin() + 1, in.end() ) ); + } +#endif + }; + + struct unescape_x + { + template< typename ActionInput > + static void apply( const ActionInput& in, std::string& s ) + { + assert( !in.empty() ); // First character MUST be present, usually 'x'. + s += unhex_string< char >( in.begin() + 1, in.end() ); + } + }; + + // The unescape_j action is similar to unescape_u, however unlike + // unescape_u it + // (a) assumes exactly 4 hexdigits per escape sequence, + // (b) accepts multiple consecutive escaped 16-bit values. + // When applied to more than one escape sequence, unescape_j + // translates UTF-16 surrogate pairs in the input into a single + // UTF-8 sequence in s, as required for JSON by RFC 8259. + + struct unescape_j + { + template< typename ActionInput > + static bool apply( const ActionInput& in, std::string& s ) + { + assert( ( ( in.size() + 1 ) % 6 ) == 0 ); // Expects multiple "\\u1234", starting with the first "u". + for( const char* b = in.begin() + 1; b < in.end(); b += 6 ) { + const auto c = unhex_string< unsigned >( b, b + 4 ); + if( ( 0xd800 <= c ) && ( c <= 0xdbff ) && ( b + 6 < in.end() ) ) { + const auto d = unhex_string< unsigned >( b + 6, b + 10 ); + if( ( 0xdc00 <= d ) && ( d <= 0xdfff ) ) { + b += 6; + (void)utf8_append_utf32( s, ( ( ( c & 0x03ff ) << 10 ) | ( d & 0x03ff ) ) + 0x10000 ); + continue; + } + } + if( !utf8_append_utf32( s, c ) ) { +#if defined( __cpp_exceptions ) + throw parse_error( "invalid escaped unicode code point", in ); +#else + return false; +#endif + } + } + return true; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::unescape + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/uri.hpp b/pxr/base/pegtl/pegtl/contrib/uri.hpp new file mode 100644 index 0000000000..1ae245405e --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/uri.hpp @@ -0,0 +1,111 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_URI_HPP +#define PXR_PEGTL_CONTRIB_URI_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/contrib/uri.hpp" +#else + +#include + +#include "../ascii.hpp" +#include "../config.hpp" +#include "../rules.hpp" +#include "../utf8.hpp" + +#include "abnf.hpp" +#include "integer.hpp" + +namespace PXR_PEGTL_NAMESPACE::uri +{ + // URI grammar according to RFC 3986. + + // This grammar is a direct PEG translation of the original URI grammar. + // It should be considered experimental -- in case of any issues, in particular + // missing rules for attached actions, please contact the developers. + + // Note that this grammar has multiple top-level rules. + + using dot = one< '.' >; + using colon = one< ':' >; + + // clang-format off + struct dec_octet : maximum_rule< std::uint8_t > {}; + + struct IPv4address : seq< dec_octet, dot, dec_octet, dot, dec_octet, dot, dec_octet > {}; + + struct h16 : rep_min_max< 1, 4, abnf::HEXDIG > {}; + struct ls32 : sor< seq< h16, colon, h16 >, IPv4address > {}; + + struct dcolon : two< ':' > {}; + + struct IPv6address : sor< seq< rep< 6, h16, colon >, ls32 >, + seq< dcolon, rep< 5, h16, colon >, ls32 >, + seq< opt< h16 >, dcolon, rep< 4, h16, colon >, ls32 >, + seq< opt< h16, opt< colon, h16 > >, dcolon, rep< 3, h16, colon >, ls32 >, + seq< opt< h16, rep_opt< 2, colon, h16 > >, dcolon, rep< 2, h16, colon >, ls32 >, + seq< opt< h16, rep_opt< 3, colon, h16 > >, dcolon, h16, colon, ls32 >, + seq< opt< h16, rep_opt< 4, colon, h16 > >, dcolon, ls32 >, + seq< opt< h16, rep_opt< 5, colon, h16 > >, dcolon, h16 >, + seq< opt< h16, rep_opt< 6, colon, h16 > >, dcolon > > {}; + + struct gen_delims : one< ':', '/', '?', '#', '[', ']', '@' > {}; + struct sub_delims : one< '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=' > {}; + + struct unreserved : sor< abnf::ALPHA, abnf::DIGIT, one< '-', '.', '_', '~' > > {}; + struct reserved : sor< gen_delims, sub_delims > {}; + + struct IPvFuture : if_must< one< 'v', 'V' >, plus< abnf::HEXDIG >, dot, plus< sor< unreserved, sub_delims, colon > > > {}; + + struct IP_literal : if_must< one< '[' >, sor< IPvFuture, IPv6address >, one< ']' > > {}; + + struct pct_encoded : if_must< one< '%' >, abnf::HEXDIG, abnf::HEXDIG > {}; + struct pchar : sor< unreserved, pct_encoded, sub_delims, one< ':', '@' > > {}; + + struct query : star< sor< pchar, one< '/', '?' > > > {}; + struct fragment : star< sor< pchar, one< '/', '?' > > > {}; + + struct segment : star< pchar > {}; + struct segment_nz : plus< pchar > {}; + struct segment_nz_nc : plus< sor< unreserved, pct_encoded, sub_delims, one< '@' > > > {}; // non-zero-length segment without any colon ":" + + struct path_abempty : star< one< '/' >, segment > {}; + struct path_absolute : seq< one< '/' >, opt< segment_nz, star< one< '/' >, segment > > > {}; + struct path_noscheme : seq< segment_nz_nc, star< one< '/' >, segment > > {}; + struct path_rootless : seq< segment_nz, star< one< '/' >, segment > > {}; + struct path_empty : success {}; + + struct path : sor< path_noscheme, // begins with a non-colon segment + path_rootless, // begins with a segment + path_absolute, // begins with "/" but not "//" + path_abempty > {}; // begins with "/" or is empty + + struct reg_name : star< sor< unreserved, pct_encoded, sub_delims > > {}; + + struct port : star< abnf::DIGIT > {}; + struct host : sor< IP_literal, IPv4address, reg_name > {}; + struct userinfo : star< sor< unreserved, pct_encoded, sub_delims, colon > > {}; + struct opt_userinfo : opt< userinfo, one< '@' > > {}; + struct authority : seq< opt_userinfo, host, opt< colon, port > > {}; + + struct scheme : seq< abnf::ALPHA, star< sor< abnf::ALPHA, abnf::DIGIT, one< '+', '-', '.' > > > > {}; + + using dslash = two< '/' >; + using opt_query = opt_must< one< '?' >, query >; + using opt_fragment = opt_must< one< '#' >, fragment >; + + struct hier_part : sor< if_must< dslash, authority, path_abempty >, path_rootless, path_absolute, path_empty > {}; + struct relative_part : sor< if_must< dslash, authority, path_abempty >, path_noscheme, path_absolute, path_empty > {}; + struct relative_ref : seq< relative_part, opt_query, opt_fragment > {}; + + struct URI : seq< scheme, one< ':' >, hier_part, opt_query, opt_fragment > {}; + struct URI_reference : sor< URI, relative_ref > {}; + struct absolute_URI : seq< scheme, one< ':' >, hier_part, opt_query > {}; + // clang-format on + +} // namespace PXR_PEGTL_NAMESPACE::uri + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/utf16.hpp b/pxr/base/pegtl/pegtl/contrib/utf16.hpp new file mode 100644 index 0000000000..2d3fd23d27 --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/utf16.hpp @@ -0,0 +1,57 @@ +// Copyright (c) 2015-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_UTF16_HPP +#define PXR_PEGTL_CONTRIB_UTF16_HPP + +#include "../config.hpp" +#include "../internal/result_on_found.hpp" +#include "../internal/rules.hpp" + +#include "internal/peek_utf16.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace utf16_be + { + // clang-format off + struct any : internal::any< internal::peek_utf16_be > {}; + struct bom : internal::one< internal::result_on_found::success, internal::peek_utf16_be, 0xfeff > {}; + template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf16_be, Cs... > {}; + template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf16_be, Lo, Hi > {}; + template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf16_be, Cs... > {}; + template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_utf16_be, Lo, Hi > {}; + template< char32_t... Cs > struct ranges : internal::ranges< internal::peek_utf16_be, Cs... > {}; + template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_utf16_be, Cs >... > {}; + // clang-format on + + } // namespace utf16_be + + namespace utf16_le + { + // clang-format off + struct any : internal::any< internal::peek_utf16_le > {}; + struct bom : internal::one< internal::result_on_found::success, internal::peek_utf16_le, 0xfeff > {}; + template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf16_le, Cs... > {}; + template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf16_le, Lo, Hi > {}; + template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf16_le, Cs... > {}; + template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_utf16_le, Lo, Hi > {}; + template< char32_t... Cs > struct ranges : internal::ranges< internal::peek_utf16_le, Cs... > {}; + template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_utf16_le, Cs >... > {}; + // clang-format on + + } // namespace utf16_le + +#if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( __CYGWIN__ ) + namespace utf16 = utf16_le; +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + namespace utf16 = utf16_le; +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + namespace utf16 = utf16_be; +#else +#error Unknown endianness. +#endif + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/contrib/utf32.hpp b/pxr/base/pegtl/pegtl/contrib/utf32.hpp new file mode 100644 index 0000000000..e70f79ab9f --- /dev/null +++ b/pxr/base/pegtl/pegtl/contrib/utf32.hpp @@ -0,0 +1,57 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CONTRIB_UTF32_HPP +#define PXR_PEGTL_CONTRIB_UTF32_HPP + +#include "../config.hpp" +#include "../internal/result_on_found.hpp" +#include "../internal/rules.hpp" + +#include "internal/peek_utf32.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace utf32_be + { + // clang-format off + struct any : internal::any< internal::peek_utf32_be > {}; + struct bom : internal::one< internal::result_on_found::success, internal::peek_utf32_be, 0xfeff > {}; + template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf32_be, Cs... > {}; + template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf32_be, Lo, Hi > {}; + template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf32_be, Cs... > {}; + template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_utf32_be, Lo, Hi > {}; + template< char32_t... Cs > struct ranges : internal::ranges< internal::peek_utf32_be, Cs... > {}; + template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_utf32_be, Cs >... > {}; + // clang-format on + + } // namespace utf32_be + + namespace utf32_le + { + // clang-format off + struct any : internal::any< internal::peek_utf32_le > {}; + struct bom : internal::one< internal::result_on_found::success, internal::peek_utf32_le, 0xfeff > {}; + template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf32_le, Cs... > {}; + template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf32_le, Lo, Hi > {}; + template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf32_le, Cs... > {}; + template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_utf32_le, Lo, Hi > {}; + template< char32_t... Cs > struct ranges : internal::ranges< internal::peek_utf32_le, Cs... > {}; + template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_utf32_le, Cs >... > {}; + // clang-format on + + } // namespace utf32_le + +#if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( __CYGWIN__ ) + namespace utf32 = utf32_le; +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + namespace utf32 = utf32_le; +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + namespace utf32 = utf32_be; +#else +#error Unknown endianness. +#endif + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/cstream_input.hpp b/pxr/base/pegtl/pegtl/cstream_input.hpp new file mode 100644 index 0000000000..e5ce8aea27 --- /dev/null +++ b/pxr/base/pegtl/pegtl/cstream_input.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_CSTREAM_INPUT_HPP +#define PXR_PEGTL_CSTREAM_INPUT_HPP + +#include + +#include "buffer_input.hpp" +#include "config.hpp" +#include "eol.hpp" + +#include "internal/cstream_reader.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< typename Eol = eol::lf_crlf, std::size_t Chunk = 64 > + struct cstream_input + : buffer_input< internal::cstream_reader, Eol, std::string, Chunk > + { + template< typename T > + cstream_input( std::FILE* in_stream, const std::size_t in_maximum, T&& in_source ) + : buffer_input< internal::cstream_reader, Eol, std::string, Chunk >( std::forward< T >( in_source ), in_maximum, in_stream ) + {} + }; + + template< typename... Ts > + cstream_input( Ts&&... ) -> cstream_input<>; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/demangle.hpp b/pxr/base/pegtl/pegtl/demangle.hpp new file mode 100644 index 0000000000..3abfe49754 --- /dev/null +++ b/pxr/base/pegtl/pegtl/demangle.hpp @@ -0,0 +1,182 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_DEMANGLE_HPP +#define PXR_PEGTL_DEMANGLE_HPP + +#include + +#include "config.hpp" + +// ensure a consistent interface +namespace PXR_PEGTL_NAMESPACE +{ +#if !defined( __clang__ ) && defined( __GNUC__ ) && ( __GNUC__ == 7 ) + + template< typename T > + [[nodiscard]] std::string_view demangle() noexcept; + +#else + + template< typename T > + [[nodiscard]] constexpr std::string_view demangle() noexcept; + +#endif + +} // namespace PXR_PEGTL_NAMESPACE + +#if defined( __clang__ ) + +#if defined( _LIBCPP_VERSION ) + +template< typename T > +[[nodiscard]] constexpr std::string_view PXR_PEGTL_NAMESPACE::demangle() noexcept +{ + constexpr std::string_view sv = __PRETTY_FUNCTION__; + constexpr auto begin = sv.find( '=' ); + static_assert( begin != std::string_view::npos ); + return sv.substr( begin + 2, sv.size() - begin - 3 ); +} + +#else + +namespace PXR_PEGTL_NAMESPACE::internal +{ + // When using libstdc++ with clang, std::string_view::find is not constexpr :( + template< char C > + constexpr const char* string_view_find( const char* p, std::size_t n ) noexcept + { + while( n ) { + if( *p == C ) { + return p; + } + ++p; + --n; + } + return nullptr; + } + +} // namespace PXR_PEGTL_NAMESPACE::internal + +template< typename T > +[[nodiscard]] constexpr std::string_view PXR_PEGTL_NAMESPACE::demangle() noexcept +{ + constexpr std::string_view sv = __PRETTY_FUNCTION__; + constexpr auto begin = internal::string_view_find< '=' >( sv.data(), sv.size() ); + static_assert( begin != nullptr ); + return { begin + 2, sv.data() + sv.size() - begin - 3 }; +} + +#endif + +#elif defined( __GNUC__ ) + +#if( __GNUC__ == 7 ) + +// GCC 7 wrongly sometimes disallows __PRETTY_FUNCTION__ in constexpr functions, +// therefore we drop the 'constexpr' and hope for the best. +template< typename T > +[[nodiscard]] std::string_view PXR_PEGTL_NAMESPACE::demangle() noexcept +{ + const std::string_view sv = __PRETTY_FUNCTION__; + const auto begin = sv.find( '=' ); + const auto tmp = sv.substr( begin + 2 ); + const auto end = tmp.rfind( ';' ); + return tmp.substr( 0, end ); +} + +#elif( __GNUC__ == 9 ) && ( __GNUC_MINOR__ < 3 ) + +#if !defined( __cpp_rtti ) +#error "RTTI support required for GCC 9.1/9.2" +#else + +#include + +// GCC 9.1 and 9.2 have a bug that leads to truncated __PRETTY_FUNCTION__ names, +// see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91155 +template< typename T > +[[nodiscard]] constexpr std::string_view PXR_PEGTL_NAMESPACE::demangle() noexcept +{ + // fallback: requires RTTI, no demangling + return typeid( T ).name(); +} + +#endif + +#else + +namespace PXR_PEGTL_NAMESPACE::special +{ + template< typename T > + [[nodiscard]] constexpr std::string_view demangle() noexcept + { + constexpr std::string_view sv = __PRETTY_FUNCTION__; + constexpr auto begin = sv.find( '=' ); + static_assert( begin != std::string_view::npos ); + constexpr auto tmp = sv.substr( begin + 2 ); + constexpr auto end = tmp.rfind( ';' ); + static_assert( end != std::string_view::npos ); + return tmp.substr( 0, end ); + } + +} // namespace PXR_PEGTL_NAMESPACE::special + +template< typename T > +[[nodiscard]] constexpr std::string_view PXR_PEGTL_NAMESPACE::demangle() noexcept +{ + return special::demangle< T >(); +} + +#endif + +#elif defined( _MSC_VER ) + +#if( _MSC_VER < 1920 ) + +template< typename T > +[[nodiscard]] constexpr std::string_view PXR_PEGTL_NAMESPACE::demangle() noexcept +{ + const std::string_view sv = __FUNCSIG__; + const auto begin = sv.find( "demangle<" ); + const auto tmp = sv.substr( begin + 9 ); + const auto end = tmp.rfind( '>' ); + return tmp.substr( 0, end ); +} + +#else + +template< typename T > +[[nodiscard]] constexpr std::string_view PXR_PEGTL_NAMESPACE::demangle() noexcept +{ + // we can not add static_assert for additional safety, + // see issues #296, #301 and #308 + constexpr std::string_view sv = __FUNCSIG__; + constexpr auto begin = sv.find( "demangle<" ); + constexpr auto tmp = sv.substr( begin + 9 ); + constexpr auto end = tmp.rfind( '>' ); + return tmp.substr( 0, end ); +} + +#endif + +#else + +#if !defined( __cpp_rtti ) +#error "RTTI support required for unknown compilers" +#else + +#include + +template< typename T > +[[nodiscard]] constexpr std::string_view PXR_PEGTL_NAMESPACE::demangle() noexcept +{ + // fallback: requires RTTI, no demangling + return typeid( T ).name(); +} + +#endif + +#endif + +#endif diff --git a/pxr/base/pegtl/pegtl/disable_action.hpp b/pxr/base/pegtl/pegtl/disable_action.hpp new file mode 100644 index 0000000000..6c88452f58 --- /dev/null +++ b/pxr/base/pegtl/pegtl/disable_action.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_DISABLE_ACTION_HPP +#define PXR_PEGTL_DISABLE_ACTION_HPP + +#include "apply_mode.hpp" +#include "config.hpp" +#include "match.hpp" +#include "nothing.hpp" +#include "rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + struct disable_action + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + return PXR_PEGTL_NAMESPACE::match< Rule, apply_mode::nothing, M, Action, Control >( in, st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/discard_input.hpp b/pxr/base/pegtl/pegtl/discard_input.hpp new file mode 100644 index 0000000000..e9a57dda37 --- /dev/null +++ b/pxr/base/pegtl/pegtl/discard_input.hpp @@ -0,0 +1,37 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_DISCARD_INPUT_HPP +#define PXR_PEGTL_DISCARD_INPUT_HPP + +#include "apply_mode.hpp" +#include "config.hpp" +#include "match.hpp" +#include "nothing.hpp" +#include "rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + struct discard_input + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + const bool result = PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); + in.discard(); + return result; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/discard_input_on_failure.hpp b/pxr/base/pegtl/pegtl/discard_input_on_failure.hpp new file mode 100644 index 0000000000..0839ab06db --- /dev/null +++ b/pxr/base/pegtl/pegtl/discard_input_on_failure.hpp @@ -0,0 +1,39 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_DISCARD_INPUT_ON_FAILURE_HPP +#define PXR_PEGTL_DISCARD_INPUT_ON_FAILURE_HPP + +#include "apply_mode.hpp" +#include "config.hpp" +#include "match.hpp" +#include "nothing.hpp" +#include "rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + struct discard_input_on_failure + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + const bool result = PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); + if( !result ) { + in.discard(); + } + return result; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/discard_input_on_success.hpp b/pxr/base/pegtl/pegtl/discard_input_on_success.hpp new file mode 100644 index 0000000000..5400209839 --- /dev/null +++ b/pxr/base/pegtl/pegtl/discard_input_on_success.hpp @@ -0,0 +1,39 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_DISCARD_INPUT_ON_SUCCESS_HPP +#define PXR_PEGTL_DISCARD_INPUT_ON_SUCCESS_HPP + +#include "apply_mode.hpp" +#include "config.hpp" +#include "match.hpp" +#include "nothing.hpp" +#include "rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + struct discard_input_on_success + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + const bool result = PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); + if( result ) { + in.discard(); + } + return result; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/enable_action.hpp b/pxr/base/pegtl/pegtl/enable_action.hpp new file mode 100644 index 0000000000..96e4030f3d --- /dev/null +++ b/pxr/base/pegtl/pegtl/enable_action.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_ENABLE_ACTION_HPP +#define PXR_PEGTL_ENABLE_ACTION_HPP + +#include "apply_mode.hpp" +#include "config.hpp" +#include "match.hpp" +#include "nothing.hpp" +#include "rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + struct enable_action + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + return PXR_PEGTL_NAMESPACE::match< Rule, apply_mode::action, M, Action, Control >( in, st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/eol.hpp b/pxr/base/pegtl/pegtl/eol.hpp new file mode 100644 index 0000000000..50d372a937 --- /dev/null +++ b/pxr/base/pegtl/pegtl/eol.hpp @@ -0,0 +1,37 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_EOL_HPP +#define PXR_PEGTL_EOL_HPP + +#include "config.hpp" + +#include "internal/eol.hpp" + +#include "internal/cr_crlf_eol.hpp" +#include "internal/cr_eol.hpp" +#include "internal/crlf_eol.hpp" +#include "internal/lf_crlf_eol.hpp" +#include "internal/lf_eol.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + inline namespace ascii + { + // this is both a rule and a pseudo-namespace for eol::cr, ... + struct eol : internal::eol + { + // clang-format off + struct cr : internal::cr_eol {}; + struct cr_crlf : internal::cr_crlf_eol {}; + struct crlf : internal::crlf_eol {}; + struct lf : internal::lf_eol {}; + struct lf_crlf : internal::lf_crlf_eol {}; + // clang-format on + }; + + } // namespace ascii + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/eol_pair.hpp b/pxr/base/pegtl/pegtl/eol_pair.hpp new file mode 100644 index 0000000000..caee52ad0a --- /dev/null +++ b/pxr/base/pegtl/pegtl/eol_pair.hpp @@ -0,0 +1,18 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_EOL_PAIR_HPP +#define PXR_PEGTL_EOL_PAIR_HPP + +#include +#include + +#include "config.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + using eol_pair = std::pair< bool, std::size_t >; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/file_input.hpp b/pxr/base/pegtl/pegtl/file_input.hpp new file mode 100644 index 0000000000..5b7578b7fd --- /dev/null +++ b/pxr/base/pegtl/pegtl/file_input.hpp @@ -0,0 +1,44 @@ +// Copyright (c) 2015-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_FILE_INPUT_HPP +#define PXR_PEGTL_FILE_INPUT_HPP + +#include "config.hpp" +#include "eol.hpp" +#include "tracking_mode.hpp" + +#if defined( __unix__ ) || ( defined( __APPLE__ ) && defined( __MACH__ ) ) +#include // Required for _POSIX_MAPPED_FILES +#endif + +#if defined( _POSIX_MAPPED_FILES ) || defined( _WIN32 ) +#include "mmap_input.hpp" +#else +#include "read_input.hpp" +#endif + +namespace PXR_PEGTL_NAMESPACE +{ +#if defined( _POSIX_MAPPED_FILES ) || defined( _WIN32 ) + template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > + struct file_input + : mmap_input< P, Eol > + { + using mmap_input< P, Eol >::mmap_input; + }; +#else + template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > + struct file_input + : read_input< P, Eol > + { + using read_input< P, Eol >::read_input; + }; +#endif + + template< typename... Ts > + explicit file_input( Ts&&... ) -> file_input<>; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/action.hpp b/pxr/base/pegtl/pegtl/internal/action.hpp new file mode 100644 index 0000000000..b530bb6d3c --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/action.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_ACTION_HPP +#define PXR_PEGTL_INTERNAL_ACTION_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< template< typename... > class Action, typename... Rules > + struct action + : action< Action, seq< Rules... > > + {}; + + template< template< typename... > class Action > + struct action< Action > + : success + {}; + + template< template< typename... > class Action, typename Rule > + struct action< Action, Rule > + { + using rule_t = action; + using subs_t = type_list< Rule >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + return Control< Rule >::template match< A, M, Action, Control >( in, st... ); + } + }; + + template< template< typename... > class Action, typename... Rules > + inline constexpr bool enable_control< action< Action, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/action_input.hpp b/pxr/base/pegtl/pegtl/internal/action_input.hpp new file mode 100644 index 0000000000..57039bacb3 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/action_input.hpp @@ -0,0 +1,106 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_ACTION_INPUT_HPP +#define PXR_PEGTL_INTERNAL_ACTION_INPUT_HPP + +#include +#include +#include +#include + +#include "iterator.hpp" + +#include "../config.hpp" +#include "../position.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename ParseInput > + class action_input + { + public: + using input_t = ParseInput; + using iterator_t = typename ParseInput::iterator_t; + + action_input( const iterator_t& in_begin, const ParseInput& in_input ) noexcept + : m_begin( in_begin ), + m_input( in_input ) + {} + + action_input( const action_input& ) = delete; + action_input( action_input&& ) = delete; + + ~action_input() = default; + + action_input& operator=( const action_input& ) = delete; + action_input& operator=( action_input&& ) = delete; + + [[nodiscard]] const iterator_t& iterator() const noexcept + { + return m_begin; + } + + [[nodiscard]] const ParseInput& input() const noexcept + { + return m_input; + } + + [[nodiscard]] const char* begin() const noexcept + { + if constexpr( std::is_same_v< iterator_t, const char* > ) { + return iterator(); + } + else { + return iterator().data; + } + } + + [[nodiscard]] const char* end() const noexcept + { + return input().current(); + } + + [[nodiscard]] bool empty() const noexcept + { + return begin() == end(); + } + + [[nodiscard]] std::size_t size() const noexcept + { + return std::size_t( end() - begin() ); + } + + [[nodiscard]] std::string string() const + { + return std::string( begin(), size() ); + } + + [[nodiscard]] std::string_view string_view() const noexcept + { + return std::string_view( begin(), size() ); + } + + [[nodiscard]] char peek_char( const std::size_t offset = 0 ) const noexcept + { + return begin()[ offset ]; + } + + [[nodiscard]] std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept + { + return static_cast< std::uint8_t >( peek_char( offset ) ); + } + + [[nodiscard]] PXR_PEGTL_NAMESPACE::position position() const + { + return input().position( iterator() ); // NOTE: Not efficient with lazy inputs. + } + + protected: + const iterator_t m_begin; + const ParseInput& m_input; + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/any.hpp b/pxr/base/pegtl/pegtl/internal/any.hpp new file mode 100644 index 0000000000..33b289f9bc --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/any.hpp @@ -0,0 +1,77 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_ANY_HPP +#define PXR_PEGTL_INTERNAL_ANY_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "peek_char.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Peek > + struct any; + + template<> + struct any< peek_char > + { + using peek_t = peek_char; + using data_t = char; + + using rule_t = any; + using subs_t = empty_list; + + [[nodiscard]] static bool test( const char /*unused*/ ) noexcept + { + return true; + } + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.empty() ) ) + { + if( !in.empty() ) { + in.bump(); + return true; + } + return false; + } + }; + + template< typename Peek > + struct any + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + using rule_t = any; + using subs_t = empty_list; + + template< int Eol > + static constexpr bool can_match_eol = true; + + [[nodiscard]] static bool test( const data_t /*unused*/ ) noexcept + { + return true; + } + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + { + if( const auto t = Peek::peek( in ) ) { + in.bump( t.size ); + return true; + } + return false; + } + }; + + template< typename Peek > + inline constexpr bool enable_control< any< Peek > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/apply.hpp b/pxr/base/pegtl/pegtl/internal/apply.hpp new file mode 100644 index 0000000000..36fdf98ac1 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/apply.hpp @@ -0,0 +1,53 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_APPLY_HPP +#define PXR_PEGTL_INTERNAL_APPLY_HPP + +#include "../config.hpp" + +#include "apply_single.hpp" +#include "enable_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... Actions > + struct apply + { + using rule_t = apply; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( [[maybe_unused]] ParseInput& in, [[maybe_unused]] States&&... st ) + { + if constexpr( ( A == apply_mode::action ) && ( sizeof...( Actions ) > 0 ) ) { + using action_t = typename ParseInput::action_t; + const action_t i2( in.iterator(), in ); // No data -- range is from begin to begin. + return ( apply_single< Actions >::match( i2, st... ) && ... ); + } + else { +#if defined( _MSC_VER ) + ( (void)st, ... ); +#endif + return true; + } + } + }; + + template< typename... Actions > + inline constexpr bool enable_control< apply< Actions... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/apply0.hpp b/pxr/base/pegtl/pegtl/internal/apply0.hpp new file mode 100644 index 0000000000..aa9d2afd9a --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/apply0.hpp @@ -0,0 +1,51 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_APPLY0_HPP +#define PXR_PEGTL_INTERNAL_APPLY0_HPP + +#include "../config.hpp" + +#include "apply0_single.hpp" +#include "enable_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... Actions > + struct apply0 + { + using rule_t = apply0; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& /*unused*/, [[maybe_unused]] States&&... st ) + { + if constexpr( A == apply_mode::action ) { + return ( apply0_single< Actions >::match( st... ) && ... ); + } + else { +#if defined( _MSC_VER ) + ( (void)st, ... ); +#endif + return true; + } + } + }; + + template< typename... Actions > + inline constexpr bool enable_control< apply0< Actions... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/apply0_single.hpp b/pxr/base/pegtl/pegtl/internal/apply0_single.hpp new file mode 100644 index 0000000000..c6ea4a1fa8 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/apply0_single.hpp @@ -0,0 +1,34 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_APPLY0_SINGLE_HPP +#define PXR_PEGTL_INTERNAL_APPLY0_SINGLE_HPP + +#include "../config.hpp" + +#include + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Action > + struct apply0_single + { + template< typename... States > + [[nodiscard]] static auto match( States&&... st ) noexcept( noexcept( Action::apply0( st... ) ) ) + -> std::enable_if_t< std::is_same_v< decltype( Action::apply0( st... ) ), void >, bool > + { + Action::apply0( st... ); + return true; + } + + template< typename... States > + [[nodiscard]] static auto match( States&&... st ) noexcept( noexcept( Action::apply0( st... ) ) ) + -> std::enable_if_t< std::is_same_v< decltype( Action::apply0( st... ) ), bool >, bool > + { + return Action::apply0( st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/apply_single.hpp b/pxr/base/pegtl/pegtl/internal/apply_single.hpp new file mode 100644 index 0000000000..a292975031 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/apply_single.hpp @@ -0,0 +1,34 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_APPLY_SINGLE_HPP +#define PXR_PEGTL_INTERNAL_APPLY_SINGLE_HPP + +#include "../config.hpp" + +#include + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Action > + struct apply_single + { + template< typename ActionInput, typename... States > + [[nodiscard]] static auto match( const ActionInput& in, States&&... st ) noexcept( noexcept( Action::apply( in, st... ) ) ) + -> std::enable_if_t< std::is_same_v< decltype( Action::apply( in, st... ) ), void >, bool > + { + Action::apply( in, st... ); + return true; + } + + template< typename ActionInput, typename... States > + [[nodiscard]] static auto match( const ActionInput& in, States&&... st ) noexcept( noexcept( Action::apply( in, st... ) ) ) + -> std::enable_if_t< std::is_same_v< decltype( Action::apply( in, st... ) ), bool >, bool > + { + return Action::apply( in, st... ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/at.hpp b/pxr/base/pegtl/pegtl/internal/at.hpp new file mode 100644 index 0000000000..cc551abf08 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/at.hpp @@ -0,0 +1,55 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_AT_HPP +#define PXR_PEGTL_INTERNAL_AT_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... Rules > + struct at + : at< seq< Rules... > > + {}; + + template<> + struct at<> + : success + {}; + + template< typename Rule > + struct at< Rule > + { + using rule_t = at; + using subs_t = type_list< Rule >; + + template< apply_mode, + rewind_mode, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + const auto m = in.template mark< rewind_mode::required >(); + return Control< Rule >::template match< apply_mode::nothing, rewind_mode::active, Action, Control >( in, st... ); + } + }; + + template< typename... Rules > + inline constexpr bool enable_control< at< Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/bof.hpp b/pxr/base/pegtl/pegtl/internal/bof.hpp new file mode 100644 index 0000000000..2c8a786f59 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/bof.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_BOF_HPP +#define PXR_PEGTL_INTERNAL_BOF_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct bof + { + using rule_t = bof; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept + { + return in.byte() == 0; + } + }; + + template<> + inline constexpr bool enable_control< bof > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/bol.hpp b/pxr/base/pegtl/pegtl/internal/bol.hpp new file mode 100644 index 0000000000..08dad2e2c8 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/bol.hpp @@ -0,0 +1,31 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_BOL_HPP +#define PXR_PEGTL_INTERNAL_BOL_HPP + +#include "../config.hpp" +#include "../type_list.hpp" + +#include "enable_control.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct bol + { + using rule_t = bol; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept + { + return in.column() == 1; + } + }; + + template<> + inline constexpr bool enable_control< bol > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/bump.hpp b/pxr/base/pegtl/pegtl/internal/bump.hpp new file mode 100644 index 0000000000..75aa60e54d --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/bump.hpp @@ -0,0 +1,45 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_BUMP_HPP +#define PXR_PEGTL_INTERNAL_BUMP_HPP + +#include "../config.hpp" + +#include "iterator.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + inline void bump( iterator& iter, const std::size_t count, const int ch ) noexcept + { + for( std::size_t i = 0; i < count; ++i ) { + if( iter.data[ i ] == ch ) { + ++iter.line; + iter.column = 1; + } + else { + ++iter.column; + } + } + iter.byte += count; + iter.data += count; + } + + inline void bump_in_this_line( iterator& iter, const std::size_t count ) noexcept + { + iter.data += count; + iter.byte += count; + iter.column += count; + } + + inline void bump_to_next_line( iterator& iter, const std::size_t count ) noexcept + { + ++iter.line; + iter.byte += count; + iter.column = 1; + iter.data += count; + } + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/bump_help.hpp b/pxr/base/pegtl/pegtl/internal/bump_help.hpp new file mode 100644 index 0000000000..fba0e8504f --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/bump_help.hpp @@ -0,0 +1,26 @@ +// Copyright (c) 2015-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_BUMP_HELP_HPP +#define PXR_PEGTL_INTERNAL_BUMP_HELP_HPP + +#include + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Rule, typename ParseInput > + void bump_help( ParseInput& in, const std::size_t count ) + { + if constexpr( Rule::template can_match_eol< ParseInput::eol_t::ch > ) { + in.bump( count ); + } + else { + in.bump_in_this_line( count ); + } + } + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/bytes.hpp b/pxr/base/pegtl/pegtl/internal/bytes.hpp new file mode 100644 index 0000000000..3989077de4 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/bytes.hpp @@ -0,0 +1,43 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_BYTES_HPP +#define PXR_PEGTL_INTERNAL_BYTES_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "success.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< unsigned Cnt > + struct bytes + { + using rule_t = bytes; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) ) + { + if( in.size( Cnt ) >= Cnt ) { + in.bump( Cnt ); + return true; + } + return false; + } + }; + + template<> + struct bytes< 0 > + : success + {}; + + template< unsigned Cnt > + inline constexpr bool enable_control< bytes< Cnt > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/control.hpp b/pxr/base/pegtl/pegtl/internal/control.hpp new file mode 100644 index 0000000000..857b9b2c36 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/control.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_CONTROL_HPP +#define PXR_PEGTL_INTERNAL_CONTROL_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< template< typename... > class Control, typename... Rules > + struct control + : control< Control, seq< Rules... > > + {}; + + template< template< typename... > class Control > + struct control< Control > + : success + {}; + + template< template< typename... > class Control, typename Rule > + struct control< Control, Rule > + { + using rule_t = control; + using subs_t = type_list< Rule >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + return Control< Rule >::template match< A, M, Action, Control >( in, st... ); + } + }; + + template< template< typename... > class Control, typename... Rules > + inline constexpr bool enable_control< control< Control, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/cr_crlf_eol.hpp b/pxr/base/pegtl/pegtl/internal/cr_crlf_eol.hpp new file mode 100644 index 0000000000..d73dedb187 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/cr_crlf_eol.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_CR_CRLF_EOL_HPP +#define PXR_PEGTL_INTERNAL_CR_CRLF_EOL_HPP + +#include "../config.hpp" +#include "../eol_pair.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct cr_crlf_eol + { + static constexpr int ch = '\r'; + + template< typename ParseInput > + [[nodiscard]] static eol_pair match( ParseInput& in ) noexcept( noexcept( in.size( 2 ) ) ) + { + eol_pair p = { false, in.size( 2 ) }; + if( p.second ) { + if( in.peek_char() == '\r' ) { + in.bump_to_next_line( 1 + ( ( p.second > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) ); + p.first = true; + } + } + return p; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/cr_eol.hpp b/pxr/base/pegtl/pegtl/internal/cr_eol.hpp new file mode 100644 index 0000000000..14ed447d55 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/cr_eol.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_CR_EOL_HPP +#define PXR_PEGTL_INTERNAL_CR_EOL_HPP + +#include "../config.hpp" +#include "../eol_pair.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct cr_eol + { + static constexpr int ch = '\r'; + + template< typename ParseInput > + [[nodiscard]] static eol_pair match( ParseInput& in ) noexcept( noexcept( in.size( 1 ) ) ) + { + eol_pair p = { false, in.size( 1 ) }; + if( p.second ) { + if( in.peek_char() == '\r' ) { + in.bump_to_next_line(); + p.first = true; + } + } + return p; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/crlf_eol.hpp b/pxr/base/pegtl/pegtl/internal/crlf_eol.hpp new file mode 100644 index 0000000000..7bf76ac140 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/crlf_eol.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_CRLF_EOL_HPP +#define PXR_PEGTL_INTERNAL_CRLF_EOL_HPP + +#include "../config.hpp" +#include "../eol_pair.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct crlf_eol + { + static constexpr int ch = '\n'; + + template< typename ParseInput > + [[nodiscard]] static eol_pair match( ParseInput& in ) noexcept( noexcept( in.size( 2 ) ) ) + { + eol_pair p = { false, in.size( 2 ) }; + if( p.second > 1 ) { + if( ( in.peek_char() == '\r' ) && ( in.peek_char( 1 ) == '\n' ) ) { + in.bump_to_next_line( 2 ); + p.first = true; + } + } + return p; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/cstream_reader.hpp b/pxr/base/pegtl/pegtl/internal/cstream_reader.hpp new file mode 100644 index 0000000000..588fc62cbd --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/cstream_reader.hpp @@ -0,0 +1,58 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_CSTREAM_READER_HPP +#define PXR_PEGTL_INTERNAL_CSTREAM_READER_HPP + +#include +#include +#include + +#if defined( __cpp_exceptions ) +#include +#else +#include +#endif + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct cstream_reader + { + explicit cstream_reader( std::FILE* s ) noexcept + : m_cstream( s ) + { + assert( m_cstream != nullptr ); + } + + [[nodiscard]] std::size_t operator()( char* buffer, const std::size_t length ) const + { + if( const auto r = std::fread( buffer, 1, length, m_cstream ) ) { + return r; + } + if( std::feof( m_cstream ) != 0 ) { + return 0; + } + + // Please contact us if you know how to provoke the following exception. + // The example on cppreference.com doesn't work, at least not on macOS. + + // LCOV_EXCL_START +#if defined( __cpp_exceptions ) + const auto ec = std::ferror( m_cstream ); + assert( ec != 0 ); + throw std::system_error( ec, std::system_category(), "std::fread() failed" ); +#else + std::fputs( "std::fread() failed\n", stderr ); + std::terminate(); +#endif + // LCOV_EXCL_STOP + } + + std::FILE* m_cstream; + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/cstring_reader.hpp b/pxr/base/pegtl/pegtl/internal/cstring_reader.hpp new file mode 100644 index 0000000000..87b7241930 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/cstring_reader.hpp @@ -0,0 +1,40 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_CSTRING_READER_HPP +#define PXR_PEGTL_INTERNAL_CSTRING_READER_HPP + +#include +#include + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct cstring_reader + { + explicit cstring_reader( const char* zero_terminated ) noexcept + : m_cstring( zero_terminated ) + { + assert( m_cstring != nullptr ); + } + + [[nodiscard]] std::size_t operator()( char* buffer, const std::size_t length ) noexcept + { + std::size_t i = 0; + char c; + + while( ( i < length ) && ( ( c = m_cstring[ i ] ) != 0 ) ) { + *buffer++ = c; + ++i; + } + m_cstring += i; + return i; + } + + const char* m_cstring; + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/dependent_false.hpp b/pxr/base/pegtl/pegtl/internal/dependent_false.hpp new file mode 100644 index 0000000000..1cf128cab1 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/dependent_false.hpp @@ -0,0 +1,16 @@ +// Copyright (c) 2018-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_DEPENDENT_FALSE_HPP +#define PXR_PEGTL_INTERNAL_DEPENDENT_FALSE_HPP + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... > + inline constexpr bool dependent_false = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/disable.hpp b/pxr/base/pegtl/pegtl/internal/disable.hpp new file mode 100644 index 0000000000..d89a4f3d5a --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/disable.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_DISABLE_HPP +#define PXR_PEGTL_INTERNAL_DISABLE_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... Rules > + struct disable + : disable< seq< Rules... > > + {}; + + template<> + struct disable<> + : success + {}; + + template< typename Rule > + struct disable< Rule > + { + using rule_t = disable; + using subs_t = type_list< Rule >; + + template< apply_mode, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + return Control< Rule >::template match< apply_mode::nothing, M, Action, Control >( in, st... ); + } + }; + + template< typename... Rules > + inline constexpr bool enable_control< disable< Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/discard.hpp b/pxr/base/pegtl/pegtl/internal/discard.hpp new file mode 100644 index 0000000000..d769351eef --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/discard.hpp @@ -0,0 +1,34 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_DISCARD_HPP +#define PXR_PEGTL_INTERNAL_DISCARD_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct discard + { + using rule_t = discard; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept + { + static_assert( noexcept( in.discard() ) ); + in.discard(); + return true; + } + }; + + template<> + inline constexpr bool enable_control< discard > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/enable.hpp b/pxr/base/pegtl/pegtl/internal/enable.hpp new file mode 100644 index 0000000000..db6d66d225 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/enable.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_ENABLE_HPP +#define PXR_PEGTL_INTERNAL_ENABLE_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... Rules > + struct enable + : enable< seq< Rules... > > + {}; + + template<> + struct enable<> + : success + {}; + + template< typename Rule > + struct enable< Rule > + { + using rule_t = enable; + using subs_t = type_list< Rule >; + + template< apply_mode, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + return Control< Rule >::template match< apply_mode::action, M, Action, Control >( in, st... ); + } + }; + + template< typename... Rules > + inline constexpr bool enable_control< enable< Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/enable_control.hpp b/pxr/base/pegtl/pegtl/internal/enable_control.hpp new file mode 100644 index 0000000000..54ee04c383 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/enable_control.hpp @@ -0,0 +1,25 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_ENABLE_CONTROL_HPP +#define PXR_PEGTL_INTERNAL_ENABLE_CONTROL_HPP + +#include + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + // This class is a simple tagging mechanism. + // By default, enable_control< Rule > is 'true'. + // Each internal (!) rule that should be hidden + // from the control and action class' callbacks + // simply specializes enable_control<> to return + // 'true' for the above expression. + + template< typename Rule > + inline constexpr bool enable_control = true; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/eof.hpp b/pxr/base/pegtl/pegtl/internal/eof.hpp new file mode 100644 index 0000000000..d5d80408dc --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/eof.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_EOF_HPP +#define PXR_PEGTL_INTERNAL_EOF_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct eof + { + using rule_t = eof; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.empty() ) ) + { + return in.empty(); + } + }; + + template<> + inline constexpr bool enable_control< eof > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/eol.hpp b/pxr/base/pegtl/pegtl/internal/eol.hpp new file mode 100644 index 0000000000..8c14522727 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/eol.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_EOL_HPP +#define PXR_PEGTL_INTERNAL_EOL_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct eol + { + using rule_t = eol; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( ParseInput::eol_t::match( in ) ) ) + { + return ParseInput::eol_t::match( in ).first; + } + }; + + template<> + inline constexpr bool enable_control< eol > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/eolf.hpp b/pxr/base/pegtl/pegtl/internal/eolf.hpp new file mode 100644 index 0000000000..30d1291d9e --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/eolf.hpp @@ -0,0 +1,33 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_EOLF_HPP +#define PXR_PEGTL_INTERNAL_EOLF_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct eolf + { + using rule_t = eolf; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( ParseInput::eol_t::match( in ) ) ) + { + const auto p = ParseInput::eol_t::match( in ); + return p.first || ( !p.second ); + } + }; + + template<> + inline constexpr bool enable_control< eolf > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/failure.hpp b/pxr/base/pegtl/pegtl/internal/failure.hpp new file mode 100644 index 0000000000..231d1ae80f --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/failure.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_FAILURE_HPP +#define PXR_PEGTL_INTERNAL_FAILURE_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct failure + { + using rule_t = failure; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& /*unused*/ ) noexcept + { + return false; + } + }; + + template<> + inline constexpr bool enable_control< failure > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/file_mapper_posix.hpp b/pxr/base/pegtl/pegtl/internal/file_mapper_posix.hpp new file mode 100644 index 0000000000..f9b3bafcd3 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/file_mapper_posix.hpp @@ -0,0 +1,159 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_FILE_MAPPER_POSIX_HPP +#define PXR_PEGTL_INTERNAL_FILE_MAPPER_POSIX_HPP + +#include +#include +#include +#include +#include + +#if !defined( __cpp_exceptions ) +#include +#include +#endif + +#include + +#include "../config.hpp" + +#include "filesystem.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct file_opener + { + explicit file_opener( const internal::filesystem::path& path ) // NOLINT(modernize-pass-by-value) + : m_path( path ), + m_fd( open() ) + {} + + file_opener( const file_opener& ) = delete; + file_opener( file_opener&& ) = delete; + + ~file_opener() + { + ::close( m_fd ); + } + + file_opener& operator=( const file_opener& ) = delete; + file_opener& operator=( file_opener&& ) = delete; + + [[nodiscard]] std::size_t size() const + { + struct stat st; + errno = 0; + if( ::fstat( m_fd, &st ) < 0 ) { + // LCOV_EXCL_START +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "fstat() failed", m_path, ec ); +#else + std::perror( "fstat() failed" ); + std::terminate(); +#endif + // LCOV_EXCL_STOP + } + return std::size_t( st.st_size ); + } + + const internal::filesystem::path m_path; + const int m_fd; + + private: + [[nodiscard]] int open() const + { + errno = 0; + const int fd = ::open( m_path.c_str(), + O_RDONLY +#if defined( O_CLOEXEC ) + | O_CLOEXEC +#endif + ); + if( fd >= 0 ) { + return fd; + } +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "open() failed", m_path, ec ); +#else + std::perror( "open() failed" ); + std::terminate(); +#endif + } + }; + + class file_mapper + { + public: + explicit file_mapper( const internal::filesystem::path& path ) + : file_mapper( file_opener( path ) ) + {} + + explicit file_mapper( const file_opener& reader ) + : m_size( reader.size() ), + m_data( static_cast< const char* >( ::mmap( nullptr, m_size, PROT_READ, MAP_PRIVATE, reader.m_fd, 0 ) ) ) + { + if( ( m_size != 0 ) && ( intptr_t( m_data ) == -1 ) ) { + // LCOV_EXCL_START +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "mmap() failed", reader.m_path, ec ); +#else + std::perror( "mmap() failed" ); + std::terminate(); +#endif + // LCOV_EXCL_STOP + } + } + + file_mapper( const file_mapper& ) = delete; + file_mapper( file_mapper&& ) = delete; + + ~file_mapper() + { + // Legacy C interface requires pointer-to-mutable but does not write through the pointer. + ::munmap( const_cast< char* >( m_data ), m_size ); + } + + file_mapper& operator=( const file_mapper& ) = delete; + file_mapper& operator=( file_mapper&& ) = delete; + + [[nodiscard]] bool empty() const noexcept + { + return m_size == 0; + } + + [[nodiscard]] std::size_t size() const noexcept + { + return m_size; + } + + using iterator = const char*; + using const_iterator = const char*; + + [[nodiscard]] iterator data() const noexcept + { + return m_data; + } + + [[nodiscard]] iterator begin() const noexcept + { + return m_data; + } + + [[nodiscard]] iterator end() const noexcept + { + return m_data + m_size; + } + + private: + const std::size_t m_size; + const char* const m_data; + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/file_mapper_win32.hpp b/pxr/base/pegtl/pegtl/internal/file_mapper_win32.hpp new file mode 100644 index 0000000000..e41000ed1a --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/file_mapper_win32.hpp @@ -0,0 +1,243 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_FILE_MAPPER_WIN32_HPP +#define PXR_PEGTL_INTERNAL_FILE_MAPPER_WIN32_HPP + +#if !defined( NOMINMAX ) +#define NOMINMAX +#define PXR_PEGTL_NOMINMAX_WAS_DEFINED +#endif + +#if !defined( WIN32_LEAN_AND_MEAN ) +#define WIN32_LEAN_AND_MEAN +#define PXR_PEGTL_WIN32_LEAN_AND_MEAN_WAS_DEFINED +#endif + +#include + +#if defined( PXR_PEGTL_NOMINMAX_WAS_DEFINED ) +#undef NOMINMAX +#undef PXR_PEGTL_NOMINMAX_WAS_DEFINED +#endif + +#if defined( PXR_PEGTL_WIN32_LEAN_AND_MEAN_WAS_DEFINED ) +#undef WIN32_LEAN_AND_MEAN +#undef PXR_PEGTL_WIN32_LEAN_AND_MEAN_WAS_DEFINED +#endif + +#include "../config.hpp" + +#if !defined( __cpp_exceptions ) +#include +#include +#endif + +#include "filesystem.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct file_opener + { + explicit file_opener( const internal::filesystem::path& path ) + : m_path( path ), + m_handle( open() ) + {} + + file_opener( const file_opener& ) = delete; + file_opener( file_opener&& ) = delete; + + ~file_opener() + { + ::CloseHandle( m_handle ); + } + + file_opener& operator=( const file_opener& ) = delete; + file_opener& operator=( file_opener&& ) = delete; + + [[nodiscard]] std::size_t size() const + { + LARGE_INTEGER size; + if( !::GetFileSizeEx( m_handle, &size ) ) { +#if defined( __cpp_exceptions ) + internal::error_code ec( ::GetLastError(), internal::system_category() ); + throw internal::filesystem::filesystem_error( "GetFileSizeEx() failed", m_path, ec ); +#else + std::perror( "GetFileSizeEx() failed" ); + std::terminate(); +#endif + } + return std::size_t( size.QuadPart ); + } + + const internal::filesystem::path m_path; + const HANDLE m_handle; + + private: + [[nodiscard]] HANDLE open() const + { + SetLastError( 0 ); +#if( _WIN32_WINNT >= 0x0602 ) + const HANDLE handle = ::CreateFile2( m_path.c_str(), + GENERIC_READ, + FILE_SHARE_READ, + OPEN_EXISTING, + nullptr ); + if( handle != INVALID_HANDLE_VALUE ) { + return handle; + } +#if defined( __cpp_exceptions ) + internal::error_code ec( ::GetLastError(), internal::system_category() ); + throw internal::filesystem::filesystem_error( "CreateFile2() failed", m_path, ec ); +#else + std::perror( "CreateFile2() failed" ); + std::terminate(); +#endif +#else + const HANDLE handle = ::CreateFileW( m_path.c_str(), + GENERIC_READ, + FILE_SHARE_READ, + nullptr, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + nullptr ); + if( handle != INVALID_HANDLE_VALUE ) { + return handle; + } +#if defined( __cpp_exceptions ) + internal::error_code ec( ::GetLastError(), internal::system_category() ); + throw internal::filesystem::filesystem_error( "CreateFileW()", m_path, ec ); +#else + std::perror( "CreateFileW() failed" ); + std::terminate(); +#endif +#endif + } + }; + + struct win32_file_mapper + { + explicit win32_file_mapper( const internal::filesystem::path& path ) + : win32_file_mapper( file_opener( path ) ) + {} + + explicit win32_file_mapper( const file_opener& reader ) + : m_size( reader.size() ), + m_handle( open( reader ) ) + {} + + win32_file_mapper( const win32_file_mapper& ) = delete; + win32_file_mapper( win32_file_mapper&& ) = delete; + + ~win32_file_mapper() + { + ::CloseHandle( m_handle ); + } + + win32_file_mapper& operator=( const win32_file_mapper& ) = delete; + win32_file_mapper& operator=( win32_file_mapper&& ) = delete; + + const size_t m_size; + const HANDLE m_handle; + + private: + [[nodiscard]] HANDLE open( const file_opener& reader ) const + { + const uint64_t file_size = reader.size(); + SetLastError( 0 ); + // Use `CreateFileMappingW` because a) we're not specifying a + // mapping name, so the character type is of no consequence, and + // b) it's defined in `memoryapi.h`, unlike + // `CreateFileMappingA`(?!) + const HANDLE handle = ::CreateFileMappingW( reader.m_handle, + nullptr, + PAGE_READONLY, + DWORD( file_size >> 32 ), + DWORD( file_size & 0xffffffff ), + nullptr ); + if( handle != NULL || file_size == 0 ) { + return handle; + } +#if defined( __cpp_exceptions ) + internal::error_code ec( ::GetLastError(), internal::system_category() ); + throw internal::filesystem::filesystem_error( "CreateFileMappingW() failed", reader.m_path, ec ); +#else + std::perror( "CreateFileMappingW() failed" ); + std::terminate(); +#endif + } + }; + + class file_mapper + { + public: + explicit file_mapper( const internal::filesystem::path& path ) + : file_mapper( win32_file_mapper( path ) ) + {} + + explicit file_mapper( const win32_file_mapper& mapper ) + : m_size( mapper.m_size ), + m_data( static_cast< const char* >( ::MapViewOfFile( mapper.m_handle, + FILE_MAP_READ, + 0, + 0, + 0 ) ) ) + { + if( ( m_size != 0 ) && ( intptr_t( m_data ) == 0 ) ) { +#if defined( __cpp_exceptions ) + internal::error_code ec( ::GetLastError(), internal::system_category() ); + throw internal::filesystem::filesystem_error( "MapViewOfFile() failed", ec ); +#else + std::perror( "MapViewOfFile() failed" ); + std::terminate(); +#endif + } + } + + file_mapper( const file_mapper& ) = delete; + file_mapper( file_mapper&& ) = delete; + + ~file_mapper() + { + ::UnmapViewOfFile( LPCVOID( m_data ) ); + } + + file_mapper& operator=( const file_mapper& ) = delete; + file_mapper& operator=( file_mapper&& ) = delete; + + [[nodiscard]] bool empty() const noexcept + { + return m_size == 0; + } + + [[nodiscard]] std::size_t size() const noexcept + { + return m_size; + } + + using iterator = const char*; + using const_iterator = const char*; + + [[nodiscard]] iterator data() const noexcept + { + return m_data; + } + + [[nodiscard]] iterator begin() const noexcept + { + return m_data; + } + + [[nodiscard]] iterator end() const noexcept + { + return m_data + m_size; + } + + private: + const std::size_t m_size; + const char* const m_data; + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/file_reader.hpp b/pxr/base/pegtl/pegtl/internal/file_reader.hpp new file mode 100644 index 0000000000..b81c09c8ae --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/file_reader.hpp @@ -0,0 +1,152 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_FILE_READER_HPP +#define PXR_PEGTL_INTERNAL_FILE_READER_HPP + +#include +#include +#include +#include + +#if !defined( __cpp_exceptions ) +#include +#endif + +#include "../config.hpp" + +#include "filesystem.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + [[nodiscard]] inline std::FILE* file_open( const internal::filesystem::path& path ) + { + errno = 0; +#if defined( _MSC_VER ) + std::FILE* file; + if( ::_wfopen_s( &file, path.c_str(), L"rb" ) == 0 ) { + return file; + } +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "_wfopen_s() failed", path, ec ); +#else + std::perror( "_wfopen_s() failed" ); + std::terminate(); +#endif +#else +#if defined( __MINGW32__ ) + if( auto* file = std::fopen( path.string().c_str(), "rb" ) ) +#else + if( auto* file = std::fopen( path.c_str(), "rbe" ) ) +#endif + { + return file; + } +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "std::fopen() failed", path, ec ); +#else + std::perror( "std::fopen() failed" ); + std::terminate(); +#endif +#endif + } + + struct file_close + { + void operator()( FILE* f ) const noexcept + { + std::fclose( f ); + } + }; + + class file_reader + { + public: + explicit file_reader( const internal::filesystem::path& path ) + : file_reader( file_open( path ), path ) + {} + + file_reader( FILE* file, const internal::filesystem::path& path ) // NOLINT(modernize-pass-by-value) + : m_path( path ), + m_file( file ) + {} + + file_reader( const file_reader& ) = delete; + file_reader( file_reader&& ) = delete; + + ~file_reader() = default; + + file_reader& operator=( const file_reader& ) = delete; + file_reader& operator=( file_reader&& ) = delete; + + [[nodiscard]] std::size_t size() const + { + errno = 0; + if( std::fseek( m_file.get(), 0, SEEK_END ) != 0 ) { + // LCOV_EXCL_START +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "std::fseek() failed [SEEK_END]", m_path, ec ); +#else + std::perror( "std::fseek() failed [SEEK_END]" ); + std::terminate(); +#endif + // LCOV_EXCL_STOP + } + errno = 0; + const auto s = std::ftell( m_file.get() ); + if( s < 0 ) { + // LCOV_EXCL_START +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "std::ftell() failed", m_path, ec ); +#else + std::perror( "std::ftell() failed" ); + std::terminate(); +#endif + // LCOV_EXCL_STOP + } + errno = 0; + if( std::fseek( m_file.get(), 0, SEEK_SET ) != 0 ) { + // LCOV_EXCL_START +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "std::fseek() failed [SEEK_SET]", m_path, ec ); +#else + std::perror( "std::fseek() failed [SEEK_SET]" ); + std::terminate(); +#endif + // LCOV_EXCL_STOP + } + return std::size_t( s ); + } + + [[nodiscard]] std::string read() const + { + std::string nrv; + nrv.resize( size() ); + errno = 0; + if( !nrv.empty() && ( std::fread( &nrv[ 0 ], nrv.size(), 1, m_file.get() ) != 1 ) ) { + // LCOV_EXCL_START +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "std::fread() failed", m_path, ec ); +#else + std::perror( "std::fread() failed" ); + std::terminate(); +#endif + // LCOV_EXCL_STOP + } + return nrv; + } + + private: + const internal::filesystem::path m_path; + const std::unique_ptr< std::FILE, file_close > m_file; + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/filesystem.hpp b/pxr/base/pegtl/pegtl/internal/filesystem.hpp new file mode 100644 index 0000000000..6de3e90339 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/filesystem.hpp @@ -0,0 +1,64 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_FILESYSTEM_HPP +#define PXR_PEGTL_INTERNAL_FILESYSTEM_HPP + +#include "../config.hpp" + +#if defined( PXR_PEGTL_BOOST_FILESYSTEM ) + +#define BOOST_FILESYSTEM_NO_DEPRECATED + +#include + +namespace PXR_PEGTL_NAMESPACE::internal +{ + namespace filesystem = ::boost::filesystem; + + using error_code = ::boost::system::error_code; + + inline const auto& system_category() noexcept + { + return ::boost::system::system_category(); + } + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#elif defined( PXR_PEGTL_STD_EXPERIMENTAL_FILESYSTEM ) + +#include + +namespace PXR_PEGTL_NAMESPACE::internal +{ + namespace filesystem = ::std::experimental::filesystem; + + using error_code = ::std::error_code; + + inline const auto& system_category() noexcept + { + return ::std::system_category(); + } + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#else + +#include + +namespace PXR_PEGTL_NAMESPACE::internal +{ + namespace filesystem = ::std::filesystem; + + using error_code = ::std::error_code; + + inline const auto& system_category() noexcept + { + return ::std::system_category(); + } + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/has_apply.hpp b/pxr/base/pegtl/pegtl/internal/has_apply.hpp new file mode 100644 index 0000000000..d4926162e9 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/has_apply.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_HAS_APPLY_HPP +#define PXR_PEGTL_INTERNAL_HAS_APPLY_HPP + +#include + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename, typename, template< typename... > class, typename... > + inline constexpr bool has_apply = false; + + template< typename C, template< typename... > class Action, typename... S > + inline constexpr bool has_apply< C, decltype( C::template apply< Action >( std::declval< S >()... ) ), Action, S... > = true; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/has_apply0.hpp b/pxr/base/pegtl/pegtl/internal/has_apply0.hpp new file mode 100644 index 0000000000..d3a46d3643 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/has_apply0.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_HAS_APPLY0_HPP +#define PXR_PEGTL_INTERNAL_HAS_APPLY0_HPP + +#include + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename, typename, template< typename... > class, typename... > + inline constexpr bool has_apply0 = false; + + template< typename C, template< typename... > class Action, typename... S > + inline constexpr bool has_apply0< C, decltype( C::template apply0< Action >( std::declval< S >()... ) ), Action, S... > = true; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/has_match.hpp b/pxr/base/pegtl/pegtl/internal/has_match.hpp new file mode 100644 index 0000000000..4c1952e3dd --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/has_match.hpp @@ -0,0 +1,40 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_HAS_MATCH_HPP +#define PXR_PEGTL_INTERNAL_HAS_MATCH_HPP + +#include + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename, + typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + inline constexpr bool has_match = false; + + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + 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; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/has_unwind.hpp b/pxr/base/pegtl/pegtl/internal/has_unwind.hpp new file mode 100644 index 0000000000..a800626784 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/has_unwind.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_HAS_UNWIND_HPP +#define PXR_PEGTL_INTERNAL_HAS_UNWIND_HPP + +#include + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename, typename... > + inline constexpr bool has_unwind = false; + + template< typename C, typename... S > + inline constexpr bool has_unwind< C, decltype( C::unwind( std::declval< S >()... ) ), S... > = true; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/identifier.hpp b/pxr/base/pegtl/pegtl/internal/identifier.hpp new file mode 100644 index 0000000000..3a60c4fd3e --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/identifier.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_IDENTIFIER_HPP +#define PXR_PEGTL_INTERNAL_IDENTIFIER_HPP + +#include "../config.hpp" + +#include "peek_char.hpp" +#include "ranges.hpp" +#include "seq.hpp" +#include "star.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + using identifier_first = ranges< peek_char, 'a', 'z', 'A', 'Z', '_' >; + using identifier_other = ranges< peek_char, 'a', 'z', 'A', 'Z', '0', '9', '_' >; + using identifier = seq< identifier_first, star< identifier_other > >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/if_apply.hpp b/pxr/base/pegtl/pegtl/internal/if_apply.hpp new file mode 100644 index 0000000000..67ca4d2b6e --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/if_apply.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_IF_APPLY_HPP +#define PXR_PEGTL_INTERNAL_IF_APPLY_HPP + +#include "../config.hpp" + +#include "apply_single.hpp" +#include "enable_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Rule, typename... Actions > + struct if_apply + { + using rule_t = if_apply; + using subs_t = type_list< Rule >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + if constexpr( ( A == apply_mode::action ) && ( sizeof...( Actions ) != 0 ) ) { + using action_t = typename ParseInput::action_t; + auto m = in.template mark< rewind_mode::required >(); + if( Control< Rule >::template match< apply_mode::action, rewind_mode::active, Action, Control >( in, st... ) ) { + const action_t i2( m.iterator(), in ); + return m( ( apply_single< Actions >::match( i2, st... ) && ... ) ); + } + return false; + } + else { + return Control< Rule >::template match< A, M, Action, Control >( in, st... ); + } + } + }; + + template< typename Rule, typename... Actions > + inline constexpr bool enable_control< if_apply< Rule, Actions... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/if_must.hpp b/pxr/base/pegtl/pegtl/internal/if_must.hpp new file mode 100644 index 0000000000..203a98d0f9 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/if_must.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_IF_MUST_HPP +#define PXR_PEGTL_INTERNAL_IF_MUST_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/if_must.hpp" +#else + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "must.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< bool Default, typename Cond, typename... Rules > + struct if_must + { + using rule_t = if_must; + using subs_t = type_list< Cond, must< Rules... > >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + if( Control< Cond >::template match< A, M, Action, Control >( in, st... ) ) { + (void)Control< must< Rules... > >::template match< A, M, Action, Control >( in, st... ); + return true; + } + return Default; + } + }; + + template< bool Default, typename Cond, typename... Rules > + inline constexpr bool enable_control< if_must< Default, Cond, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/internal/if_must_else.hpp b/pxr/base/pegtl/pegtl/internal/if_must_else.hpp new file mode 100644 index 0000000000..d7b53a39f3 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/if_must_else.hpp @@ -0,0 +1,26 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_IF_MUST_ELSE_HPP +#define PXR_PEGTL_INTERNAL_IF_MUST_ELSE_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/if_must_else.hpp" +#else + +#include "../config.hpp" + +#include "if_then_else.hpp" +#include "must.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Cond, typename Then, typename Else > + using if_must_else = if_then_else< Cond, must< Then >, must< Else > >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/internal/if_then_else.hpp b/pxr/base/pegtl/pegtl/internal/if_then_else.hpp new file mode 100644 index 0000000000..99c2a906d5 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/if_then_else.hpp @@ -0,0 +1,51 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_IF_THEN_ELSE_HPP +#define PXR_PEGTL_INTERNAL_IF_THEN_ELSE_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "not_at.hpp" +#include "seq.hpp" +#include "sor.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Cond, typename Then, typename Else > + struct if_then_else + { + using rule_t = if_then_else; + using subs_t = type_list< Cond, Then, Else >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + + if( Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) { + return m( Control< Then >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ); + } + return m( Control< Else >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ); + } + }; + + template< typename Cond, typename Then, typename Else > + inline constexpr bool enable_control< if_then_else< Cond, Then, Else > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/input_pair.hpp b/pxr/base/pegtl/pegtl/internal/input_pair.hpp new file mode 100644 index 0000000000..dfd69a54a7 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/input_pair.hpp @@ -0,0 +1,29 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_INPUT_PAIR_HPP +#define PXR_PEGTL_INTERNAL_INPUT_PAIR_HPP + +#include + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Data > + struct input_pair + { + Data data; + std::uint8_t size; + + using data_t = Data; + + explicit operator bool() const noexcept + { + return size > 0; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/istream_reader.hpp b/pxr/base/pegtl/pegtl/internal/istream_reader.hpp new file mode 100644 index 0000000000..3178cf7b16 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/istream_reader.hpp @@ -0,0 +1,50 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_ISTREAM_READER_HPP +#define PXR_PEGTL_INTERNAL_ISTREAM_READER_HPP + +#include + +#if defined( __cpp_exceptions ) +#include +#else +#include +#include +#endif + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct istream_reader + { + explicit istream_reader( std::istream& s ) noexcept + : m_istream( s ) + {} + + [[nodiscard]] std::size_t operator()( char* buffer, const std::size_t length ) + { + m_istream.read( buffer, std::streamsize( length ) ); + + if( const auto r = m_istream.gcount() ) { + return std::size_t( r ); + } + if( m_istream.eof() ) { + return 0; + } +#if defined( __cpp_exceptions ) + const auto ec = errno; + throw std::system_error( ec, std::system_category(), "std::istream::read() failed" ); +#else + std::fputs( "std::istream::read() failed\n", stderr ); + std::terminate(); +#endif + } + + std::istream& m_istream; + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/istring.hpp b/pxr/base/pegtl/pegtl/internal/istring.hpp new file mode 100644 index 0000000000..39524ac09c --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/istring.hpp @@ -0,0 +1,81 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_ISTRING_HPP +#define PXR_PEGTL_INTERNAL_ISTRING_HPP + +#include + +#include "../config.hpp" + +#include "bump_help.hpp" +#include "enable_control.hpp" +#include "one.hpp" +#include "result_on_found.hpp" +#include "success.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< char C > + inline constexpr bool is_alpha = ( ( 'a' <= C ) && ( C <= 'z' ) ) || ( ( 'A' <= C ) && ( C <= 'Z' ) ); + + template< char C > + [[nodiscard]] constexpr bool ichar_equal( const char c ) noexcept + { + if constexpr( is_alpha< C > ) { + return ( C | 0x20 ) == ( c | 0x20 ); + } + else { + return c == C; + } + } + + template< char... Cs > + [[nodiscard]] constexpr bool istring_equal( const char* r ) noexcept + { + return ( ichar_equal< Cs >( *r++ ) && ... ); + } + + template< char... Cs > + struct istring; + + template<> + struct istring<> + : success + {}; + + // template< char C > + // struct istring< C > + // : std::conditional_t< is_alpha< C >, one< result_on_found::success, peek_char, C | 0x20, C & ~0x20 >, one< result_on_found::success, peek_char, C > > + // {}; + + template< char... Cs > + struct istring + { + using rule_t = istring; + using subs_t = empty_list; + + template< int Eol > + static constexpr bool can_match_eol = one< result_on_found::success, peek_char, Cs... >::template can_match_eol< Eol >; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) ) + { + if( in.size( sizeof...( Cs ) ) >= sizeof...( Cs ) ) { + if( istring_equal< Cs... >( in.current() ) ) { + bump_help< istring >( in, sizeof...( Cs ) ); + return true; + } + } + return false; + } + }; + + template< char... Cs > + inline constexpr bool enable_control< istring< Cs... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/iterator.hpp b/pxr/base/pegtl/pegtl/internal/iterator.hpp new file mode 100644 index 0000000000..d9df2c58a1 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/iterator.hpp @@ -0,0 +1,49 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_ITERATOR_HPP +#define PXR_PEGTL_INTERNAL_ITERATOR_HPP + +#include +#include + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct iterator + { + iterator() = default; + + explicit iterator( const char* in_data ) noexcept + : data( in_data ) + {} + + iterator( const char* in_data, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_column ) noexcept + : data( in_data ), + byte( in_byte ), + line( in_line ), + column( in_column ) + { + assert( in_line != 0 ); + assert( in_column != 0 ); + } + + iterator( const iterator& ) = default; + iterator( iterator&& ) = default; + + ~iterator() = default; + + iterator& operator=( const iterator& ) = default; + iterator& operator=( iterator&& ) = default; + + const char* data = nullptr; + + std::size_t byte = 0; + std::size_t line = 1; + std::size_t column = 1; + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/lf_crlf_eol.hpp b/pxr/base/pegtl/pegtl/internal/lf_crlf_eol.hpp new file mode 100644 index 0000000000..332b4f36ad --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/lf_crlf_eol.hpp @@ -0,0 +1,37 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_LF_CRLF_EOL_HPP +#define PXR_PEGTL_INTERNAL_LF_CRLF_EOL_HPP + +#include "../config.hpp" +#include "../eol_pair.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct lf_crlf_eol + { + static constexpr int ch = '\n'; + + template< typename ParseInput > + [[nodiscard]] static eol_pair match( ParseInput& in ) noexcept( noexcept( in.size( 2 ) ) ) + { + eol_pair p = { false, in.size( 2 ) }; + if( p.second ) { + const auto a = in.peek_char(); + if( a == '\n' ) { + in.bump_to_next_line(); + p.first = true; + } + else if( ( a == '\r' ) && ( p.second > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) { + in.bump_to_next_line( 2 ); + p.first = true; + } + } + return p; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/lf_eol.hpp b/pxr/base/pegtl/pegtl/internal/lf_eol.hpp new file mode 100644 index 0000000000..d417405973 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/lf_eol.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_LF_EOL_HPP +#define PXR_PEGTL_INTERNAL_LF_EOL_HPP + +#include "../config.hpp" +#include "../eol_pair.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct lf_eol + { + static constexpr int ch = '\n'; + + template< typename ParseInput > + [[nodiscard]] static eol_pair match( ParseInput& in ) noexcept( noexcept( in.size( 1 ) ) ) + { + eol_pair p = { false, in.size( 1 ) }; + if( p.second ) { + if( in.peek_char() == '\n' ) { + in.bump_to_next_line(); + p.first = true; + } + } + return p; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/list.hpp b/pxr/base/pegtl/pegtl/internal/list.hpp new file mode 100644 index 0000000000..a046519d69 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/list.hpp @@ -0,0 +1,19 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_LIST_HPP +#define PXR_PEGTL_INTERNAL_LIST_HPP + +#include "../config.hpp" + +#include "seq.hpp" +#include "star.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Rule, typename Sep > + using list = seq< Rule, star< Sep, Rule > >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/list_must.hpp b/pxr/base/pegtl/pegtl/internal/list_must.hpp new file mode 100644 index 0000000000..61d8132467 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/list_must.hpp @@ -0,0 +1,25 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_LIST_MUST_HPP +#define PXR_PEGTL_INTERNAL_LIST_MUST_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/list_must.hpp" +#else + +#include "../config.hpp" + +#include "must.hpp" +#include "seq.hpp" +#include "star.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Rule, typename Sep > + using list_must = seq< Rule, star< Sep, must< Rule > > >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/internal/list_tail.hpp b/pxr/base/pegtl/pegtl/internal/list_tail.hpp new file mode 100644 index 0000000000..1cbcdb9280 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/list_tail.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_LIST_TAIL_HPP +#define PXR_PEGTL_INTERNAL_LIST_TAIL_HPP + +#include "../config.hpp" + +#include "opt.hpp" +#include "seq.hpp" +#include "star.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Rule, typename Sep > + using list_tail = seq< Rule, star< Sep, Rule >, opt< Sep > >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/list_tail_pad.hpp b/pxr/base/pegtl/pegtl/internal/list_tail_pad.hpp new file mode 100644 index 0000000000..3d2c534413 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/list_tail_pad.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_LIST_TAIL_PAD_HPP +#define PXR_PEGTL_INTERNAL_LIST_TAIL_PAD_HPP + +#include "../config.hpp" + +#include "list.hpp" +#include "opt.hpp" +#include "pad.hpp" +#include "seq.hpp" +#include "star.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Rule, typename Sep, typename Pad > + using list_tail_pad = seq< Rule, star< pad< Sep, Pad >, Rule >, opt< star< Pad >, Sep > >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/marker.hpp b/pxr/base/pegtl/pegtl/internal/marker.hpp new file mode 100644 index 0000000000..dd35e9ca97 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/marker.hpp @@ -0,0 +1,80 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_MARKER_HPP +#define PXR_PEGTL_INTERNAL_MARKER_HPP + +#include "../config.hpp" +#include "../rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Iterator, rewind_mode M > + class [[nodiscard]] marker + { + public: + static constexpr rewind_mode next_rewind_mode = M; + + explicit marker( const Iterator& /*unused*/ ) noexcept + {} + + marker( const marker& ) = delete; + marker( marker&& ) = delete; + + ~marker() = default; + + marker& operator=( const marker& ) = delete; + marker& operator=( marker&& ) = delete; + + [[nodiscard]] bool operator()( const bool result ) const noexcept + { + return result; + } + }; + + template< typename Iterator > + class [[nodiscard]] marker< Iterator, rewind_mode::required > + { + public: + static constexpr rewind_mode next_rewind_mode = rewind_mode::active; + + explicit marker( Iterator& i ) noexcept + : m_saved( i ), + m_input( &i ) + {} + + marker( const marker& ) = delete; + marker( marker&& ) = delete; + + ~marker() + { + if( m_input != nullptr ) { + ( *m_input ) = m_saved; + } + } + + marker& operator=( const marker& ) = delete; + marker& operator=( marker&& ) = delete; + + [[nodiscard]] bool operator()( const bool result ) noexcept + { + if( result ) { + m_input = nullptr; + return true; + } + return false; + } + + [[nodiscard]] const Iterator& iterator() const noexcept + { + return m_saved; + } + + private: + const Iterator m_saved; + Iterator* m_input; + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/minus.hpp b/pxr/base/pegtl/pegtl/internal/minus.hpp new file mode 100644 index 0000000000..e8de8f710e --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/minus.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_MINUS_HPP +#define PXR_PEGTL_INTERNAL_MINUS_HPP + +#include "../config.hpp" + +#include "eof.hpp" +#include "not_at.hpp" +#include "rematch.hpp" +#include "seq.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename M, typename S > + using minus = rematch< M, not_at< S, eof > >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/missing_apply.hpp b/pxr/base/pegtl/pegtl/internal/missing_apply.hpp new file mode 100644 index 0000000000..e8bae871af --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/missing_apply.hpp @@ -0,0 +1,28 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_MISSING_APPLY_HPP +#define PXR_PEGTL_INTERNAL_MISSING_APPLY_HPP + +#include "../config.hpp" +#include "../rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Control, + template< typename... > + class Action, + typename ParseInput, + typename... States > + void missing_apply( ParseInput& in, States&&... st ) + { + // This function only exists for better error messages, which means that it is only called when we know that it won't compile. + // LCOV_EXCL_START + auto m = in.template mark< rewind_mode::required >(); + (void)Control::template apply< Action >( m.iterator(), in, st... ); + // LCOV_EXCL_STOP + } + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/missing_apply0.hpp b/pxr/base/pegtl/pegtl/internal/missing_apply0.hpp new file mode 100644 index 0000000000..60cbdd6863 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/missing_apply0.hpp @@ -0,0 +1,26 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_MISSING_APPLY0_HPP +#define PXR_PEGTL_INTERNAL_MISSING_APPLY0_HPP + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Control, + template< typename... > + class Action, + typename ParseInput, + typename... States > + void missing_apply0( ParseInput& in, States&&... st ) + { + // This function only exists for better error messages, which means that it is only called when we know that it won't compile. + // LCOV_EXCL_START + (void)Control::template apply0< Action >( in, st... ); + // LCOV_EXCL_STOP + } + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/must.hpp b/pxr/base/pegtl/pegtl/internal/must.hpp new file mode 100644 index 0000000000..90363c8566 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/must.hpp @@ -0,0 +1,69 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_MUST_HPP +#define PXR_PEGTL_INTERNAL_MUST_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/must.hpp" +#else + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + // The general case applies must<> to each of the + // rules in the 'Rules' parameter pack individually. + + template< typename... Rules > + struct must + : seq< must< Rules >... > + {}; + + template<> + struct must<> + : success + {}; + + // While in theory the implementation for a single rule could + // be simplified to must< Rule > = sor< Rule, raise< Rule > >, this + // would result in some unnecessary run-time overhead. + + template< typename Rule > + struct must< Rule > + { + using rule_t = must; + using subs_t = type_list< Rule >; + + template< apply_mode A, + rewind_mode, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + if( !Control< Rule >::template match< A, rewind_mode::dontcare, Action, Control >( in, st... ) ) { + Control< Rule >::raise( static_cast< const ParseInput& >( in ), st... ); + } + return true; + } + }; + + template< typename... Rules > + inline constexpr bool enable_control< must< Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/internal/not_at.hpp b/pxr/base/pegtl/pegtl/internal/not_at.hpp new file mode 100644 index 0000000000..54b7deeca9 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/not_at.hpp @@ -0,0 +1,55 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_NOT_AT_HPP +#define PXR_PEGTL_INTERNAL_NOT_AT_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "failure.hpp" +#include "seq.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... Rules > + struct not_at + : not_at< seq< Rules... > > + {}; + + template<> + struct not_at<> + : failure + {}; + + template< typename Rule > + struct not_at< Rule > + { + using rule_t = not_at; + using subs_t = type_list< Rule >; + + template< apply_mode, + rewind_mode, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + const auto m = in.template mark< rewind_mode::required >(); + return !Control< Rule >::template match< apply_mode::nothing, rewind_mode::active, Action, Control >( in, st... ); + } + }; + + template< typename... Rules > + inline constexpr bool enable_control< not_at< Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/one.hpp b/pxr/base/pegtl/pegtl/internal/one.hpp new file mode 100644 index 0000000000..ebf84c6713 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/one.hpp @@ -0,0 +1,66 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_ONE_HPP +#define PXR_PEGTL_INTERNAL_ONE_HPP + +#include + +#include "../config.hpp" + +#include "any.hpp" +#include "bump_help.hpp" +#include "enable_control.hpp" +#include "failure.hpp" +#include "result_on_found.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< result_on_found R, typename Peek, typename Peek::data_t... Cs > + struct one + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + using rule_t = one; + using subs_t = empty_list; + + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return ( ( c == Cs ) || ... ) == bool( R ); + } + + template< int Eol > + static constexpr bool can_match_eol = test( Eol ); + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + { + if( const auto t = Peek::peek( in ) ) { + if( test( t.data ) ) { + bump_help< one >( in, t.size ); + return true; + } + } + return false; + } + }; + + template< typename Peek > + struct one< result_on_found::success, Peek > + : failure + {}; + + template< typename Peek > + struct one< result_on_found::failure, Peek > + : any< Peek > + {}; + + template< result_on_found R, typename Peek, typename Peek::data_t... Cs > + inline constexpr bool enable_control< one< R, Peek, Cs... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/opt.hpp b/pxr/base/pegtl/pegtl/internal/opt.hpp new file mode 100644 index 0000000000..073d629f05 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/opt.hpp @@ -0,0 +1,57 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_OPT_HPP +#define PXR_PEGTL_INTERNAL_OPT_HPP + +#include + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... Rules > + struct opt + : opt< seq< Rules... > > + {}; + + template<> + struct opt<> + : success + {}; + + template< typename Rule > + struct opt< Rule > + { + using rule_t = opt; + using subs_t = type_list< Rule >; + + template< apply_mode A, + rewind_mode, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + (void)Control< Rule >::template match< A, rewind_mode::required, Action, Control >( in, st... ); + return true; + } + }; + + template< typename... Rules > + inline constexpr bool enable_control< opt< Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/pad.hpp b/pxr/base/pegtl/pegtl/internal/pad.hpp new file mode 100644 index 0000000000..fe526ee198 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/pad.hpp @@ -0,0 +1,19 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_PAD_HPP +#define PXR_PEGTL_INTERNAL_PAD_HPP + +#include "../config.hpp" + +#include "seq.hpp" +#include "star.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Rule, typename Pad1, typename Pad2 = Pad1 > + using pad = seq< star< Pad1 >, Rule, star< Pad2 > >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/pad_opt.hpp b/pxr/base/pegtl/pegtl/internal/pad_opt.hpp new file mode 100644 index 0000000000..6b1d9daf93 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/pad_opt.hpp @@ -0,0 +1,20 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_PAD_OPT_HPP +#define PXR_PEGTL_INTERNAL_PAD_OPT_HPP + +#include "../config.hpp" + +#include "opt.hpp" +#include "seq.hpp" +#include "star.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Rule, typename Pad > + using pad_opt = seq< star< Pad >, opt< Rule, star< Pad > > >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/path_to_string.hpp b/pxr/base/pegtl/pegtl/internal/path_to_string.hpp new file mode 100644 index 0000000000..c800f43804 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/path_to_string.hpp @@ -0,0 +1,28 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_PATH_TO_STRING_HPP +#define PXR_PEGTL_INTERNAL_PATH_TO_STRING_HPP + +#include + +#include "../config.hpp" +#include "filesystem.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + [[nodiscard]] inline std::string path_to_string( const internal::filesystem::path& path ) + { +#if defined( PXR_PEGTL_BOOST_FILESYSTEM ) + return path.string(); +#elif defined( __cpp_char8_t ) + const auto s = path.u8string(); + return { reinterpret_cast< const char* >( s.data() ), s.size() }; +#else + return path.u8string(); +#endif + } + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/peek_char.hpp b/pxr/base/pegtl/pegtl/internal/peek_char.hpp new file mode 100644 index 0000000000..321c78bfcc --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/peek_char.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_PEEK_CHAR_HPP +#define PXR_PEGTL_INTERNAL_PEEK_CHAR_HPP + +#include + +#include "../config.hpp" + +#include "input_pair.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct peek_char + { + using data_t = char; + using pair_t = input_pair< char >; + + template< typename ParseInput > + [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.empty() ) ) + { + if( in.empty() ) { + return { 0, 0 }; + } + return { in.peek_char(), 1 }; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/peek_utf8.hpp b/pxr/base/pegtl/pegtl/internal/peek_utf8.hpp new file mode 100644 index 0000000000..401dc3944e --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/peek_utf8.hpp @@ -0,0 +1,89 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_PEEK_UTF8_HPP +#define PXR_PEGTL_INTERNAL_PEEK_UTF8_HPP + +#include "../config.hpp" + +#include "input_pair.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct peek_utf8 + { + using data_t = char32_t; + using pair_t = input_pair< char32_t >; + + template< typename ParseInput > + [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.empty() ) ) + { + if( in.empty() ) { + return { 0, 0 }; + } + const char32_t c0 = in.peek_uint8(); + if( ( c0 & 0x80 ) == 0 ) { + return { c0, 1 }; + } + return peek_impl( in, c0 ); + } + + private: + template< typename ParseInput > + [[nodiscard]] static pair_t peek_impl( ParseInput& in, char32_t c0 ) noexcept( noexcept( in.size( 4 ) ) ) + { + if( ( c0 & 0xE0 ) == 0xC0 ) { + if( in.size( 2 ) >= 2 ) { + const char32_t c1 = in.peek_uint8( 1 ); + if( ( c1 & 0xC0 ) == 0x80 ) { + c0 &= 0x1F; + c0 <<= 6; + c0 |= ( c1 & 0x3F ); + if( c0 >= 0x80 ) { + return { c0, 2 }; + } + } + } + } + else if( ( c0 & 0xF0 ) == 0xE0 ) { + if( in.size( 3 ) >= 3 ) { + const char32_t c1 = in.peek_uint8( 1 ); + const char32_t c2 = in.peek_uint8( 2 ); + if( ( ( c1 & 0xC0 ) == 0x80 ) && ( ( c2 & 0xC0 ) == 0x80 ) ) { + c0 &= 0x0F; + c0 <<= 6; + c0 |= ( c1 & 0x3F ); + c0 <<= 6; + c0 |= ( c2 & 0x3F ); + if( c0 >= 0x800 && !( c0 >= 0xD800 && c0 <= 0xDFFF ) ) { + return { c0, 3 }; + } + } + } + } + else if( ( c0 & 0xF8 ) == 0xF0 ) { + if( in.size( 4 ) >= 4 ) { + const char32_t c1 = in.peek_uint8( 1 ); + const char32_t c2 = in.peek_uint8( 2 ); + const char32_t c3 = in.peek_uint8( 3 ); + if( ( ( c1 & 0xC0 ) == 0x80 ) && ( ( c2 & 0xC0 ) == 0x80 ) && ( ( c3 & 0xC0 ) == 0x80 ) ) { + c0 &= 0x07; + c0 <<= 6; + c0 |= ( c1 & 0x3F ); + c0 <<= 6; + c0 |= ( c2 & 0x3F ); + c0 <<= 6; + c0 |= ( c3 & 0x3F ); + if( c0 >= 0x10000 && c0 <= 0x10FFFF ) { + return { c0, 4 }; + } + } + } + } + return { 0, 0 }; + } + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/pegtl_string.hpp b/pxr/base/pegtl/pegtl/internal/pegtl_string.hpp new file mode 100644 index 0000000000..209e8885e0 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/pegtl_string.hpp @@ -0,0 +1,90 @@ +// Copyright (c) 2015-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_PEGTL_STRING_HPP +#define PXR_PEGTL_INTERNAL_PEGTL_STRING_HPP + +#include +#include + +#include "../ascii.hpp" +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + // Inspired by https://github.com/irrequietus/typestring + // Rewritten and reduced to what is needed for the PEGTL + // and to work with Visual Studio 2015. + + template< typename, typename, typename, typename, typename, typename, typename, typename > + struct string_join; + + template< template< char... > class S, char... C0s, char... C1s, char... C2s, char... C3s, char... C4s, char... C5s, char... C6s, char... C7s > + struct string_join< S< C0s... >, S< C1s... >, S< C2s... >, S< C3s... >, S< C4s... >, S< C5s... >, S< C6s... >, S< C7s... > > + { + using type = S< C0s..., C1s..., C2s..., C3s..., C4s..., C5s..., C6s..., C7s... >; + }; + + template< template< char... > class S, char, bool > + struct string_at + { + using type = S<>; + }; + + template< template< char... > class S, char C > + struct string_at< S, C, true > + { + using type = S< C >; + }; + + template< typename T, std::size_t S > + struct string_max_length + { + static_assert( S <= 512, "String longer than 512 (excluding terminating \\0)!" ); + using type = T; + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#define PXR_PEGTL_INTERNAL_EMPTY() +#define PXR_PEGTL_INTERNAL_DEFER( X ) X PXR_PEGTL_INTERNAL_EMPTY() +#define PXR_PEGTL_INTERNAL_EXPAND( ... ) __VA_ARGS__ + +#define PXR_PEGTL_INTERNAL_STRING_AT( S, x, n ) \ + PXR_PEGTL_NAMESPACE::internal::string_at< S, ( 0##n < ( sizeof( x ) / sizeof( char ) ) ) ? ( x )[ 0##n ] : 0, ( 0##n < ( sizeof( x ) / sizeof( char ) ) - 1 ) >::type + +#define PXR_PEGTL_INTERNAL_JOIN_8( M, S, x, n ) \ + PXR_PEGTL_NAMESPACE::internal::string_join< PXR_PEGTL_INTERNAL_DEFER( M )( S, x, n##0 ), \ + PXR_PEGTL_INTERNAL_DEFER( M )( S, x, n##1 ), \ + PXR_PEGTL_INTERNAL_DEFER( M )( S, x, n##2 ), \ + PXR_PEGTL_INTERNAL_DEFER( M )( S, x, n##3 ), \ + PXR_PEGTL_INTERNAL_DEFER( M )( S, x, n##4 ), \ + PXR_PEGTL_INTERNAL_DEFER( M )( S, x, n##5 ), \ + PXR_PEGTL_INTERNAL_DEFER( M )( S, x, n##6 ), \ + PXR_PEGTL_INTERNAL_DEFER( M )( S, x, n##7 ) >::type + +#define PXR_PEGTL_INTERNAL_STRING_8( S, x, n ) \ + PXR_PEGTL_INTERNAL_JOIN_8( PXR_PEGTL_INTERNAL_STRING_AT, S, x, n ) + +#define PXR_PEGTL_INTERNAL_STRING_64( S, x, n ) \ + PXR_PEGTL_INTERNAL_JOIN_8( PXR_PEGTL_INTERNAL_STRING_8, S, x, n ) + +#define PXR_PEGTL_INTERNAL_STRING_512( S, x, n ) \ + PXR_PEGTL_INTERNAL_JOIN_8( PXR_PEGTL_INTERNAL_STRING_64, S, x, n ) + +#define PXR_PEGTL_INTERNAL_STRING( S, x ) \ + PXR_PEGTL_INTERNAL_EXPAND( \ + PXR_PEGTL_INTERNAL_EXPAND( \ + PXR_PEGTL_INTERNAL_EXPAND( \ + PXR_PEGTL_NAMESPACE::internal::string_max_length< PXR_PEGTL_INTERNAL_STRING_512( S, x, ), sizeof( x ) - 1 >::type ) ) ) + +#define PXR_PEGTL_STRING( x ) \ + PXR_PEGTL_INTERNAL_STRING( PXR_PEGTL_NAMESPACE::ascii::string, x ) + +#define PXR_PEGTL_ISTRING( x ) \ + PXR_PEGTL_INTERNAL_STRING( PXR_PEGTL_NAMESPACE::ascii::istring, x ) + +#define PXR_PEGTL_KEYWORD( x ) \ + PXR_PEGTL_INTERNAL_STRING( PXR_PEGTL_NAMESPACE::ascii::keyword, x ) + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/plus.hpp b/pxr/base/pegtl/pegtl/internal/plus.hpp new file mode 100644 index 0000000000..03b9a3b2e0 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/plus.hpp @@ -0,0 +1,60 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_PLUS_HPP +#define PXR_PEGTL_INTERNAL_PLUS_HPP + +#include + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + // While plus<> could easily be implemented with + // seq< Rule, Rules ..., star< Rule, Rules ... > > we + // provide an explicit implementation to optimise away + // the otherwise created input mark. + + template< typename Rule, typename... Rules > + struct plus + : plus< seq< Rule, Rules... > > + {}; + + template< typename Rule > + struct plus< Rule > + { + using rule_t = plus; + using subs_t = type_list< Rule >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + if( Control< Rule >::template match< A, M, Action, Control >( in, st... ) ) { + while( Control< Rule >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) { + } + return true; + } + return false; + } + }; + + template< typename Rule, typename... Rules > + inline constexpr bool enable_control< plus< Rule, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/raise.hpp b/pxr/base/pegtl/pegtl/internal/raise.hpp new file mode 100644 index 0000000000..8ce1fb8b4a --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/raise.hpp @@ -0,0 +1,49 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_RAISE_HPP +#define PXR_PEGTL_INTERNAL_RAISE_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/raise.hpp" +#else + +#include + +#include "../config.hpp" + +#include "enable_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename T > + struct raise + { + using rule_t = raise; + using subs_t = empty_list; + + template< apply_mode, + rewind_mode, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[noreturn]] static bool match( ParseInput& in, States&&... st ) + { + Control< T >::raise( static_cast< const ParseInput& >( in ), st... ); + } + }; + + template< typename T > + inline constexpr bool enable_control< raise< T > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/internal/range.hpp b/pxr/base/pegtl/pegtl/internal/range.hpp new file mode 100644 index 0000000000..970a90ee26 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/range.hpp @@ -0,0 +1,60 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_RANGE_HPP +#define PXR_PEGTL_INTERNAL_RANGE_HPP + +#include "../config.hpp" + +#include "bump_help.hpp" +#include "enable_control.hpp" +#include "one.hpp" +#include "result_on_found.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< result_on_found R, typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > + struct range + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + using rule_t = range; + using subs_t = empty_list; + + static_assert( Lo < Hi, "invalid range" ); + + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return ( ( Lo <= c ) && ( c <= Hi ) ) == bool( R ); + } + + template< int Eol > + static constexpr bool can_match_eol = test( Eol ); + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + { + if( const auto t = Peek::peek( in ) ) { + if( test( t.data ) ) { + bump_help< range >( in, t.size ); + return true; + } + } + return false; + } + }; + + template< result_on_found R, typename Peek, typename Peek::data_t C > + struct range< R, Peek, C, C > + : one< R, Peek, C > + {}; + + template< result_on_found R, typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > + inline constexpr bool enable_control< range< R, Peek, Lo, Hi > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/ranges.hpp b/pxr/base/pegtl/pegtl/internal/ranges.hpp new file mode 100644 index 0000000000..446a6572be --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/ranges.hpp @@ -0,0 +1,90 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_RANGES_HPP +#define PXR_PEGTL_INTERNAL_RANGES_HPP + +#include "../config.hpp" + +#include + +#include "bump_help.hpp" +#include "enable_control.hpp" +#include "failure.hpp" +#include "one.hpp" +#include "range.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Char, Char Lo, Char Hi > + constexpr bool validate_range( Char c ) noexcept + { + static_assert( Lo <= Hi, "invalid range" ); + return ( Lo <= c ) && ( c <= Hi ); + } + + template< typename Peek, typename Peek::data_t... Cs > + struct ranges + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + using rule_t = ranges; + using subs_t = empty_list; + + template< std::size_t... Is > + [[nodiscard]] static constexpr bool test( std::index_sequence< Is... > /*unused*/, const data_t c ) noexcept + { + constexpr const data_t cs[] = { Cs... }; + if constexpr( sizeof...( Cs ) % 2 == 0 ) { + return ( validate_range< data_t, cs[ 2 * Is ], cs[ 2 * Is + 1 ] >( c ) || ... ); + } + else { + return ( validate_range< data_t, cs[ 2 * Is ], cs[ 2 * Is + 1 ] >( c ) || ... ) || ( c == cs[ sizeof...( Cs ) - 1 ] ); + } + } + + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return test( std::make_index_sequence< sizeof...( Cs ) / 2 >(), c ); + } + + template< int Eol > + static constexpr bool can_match_eol = test( Eol ); + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + { + if( const auto t = Peek::peek( in ) ) { + if( test( t.data ) ) { + bump_help< ranges >( in, t.size ); + return true; + } + } + return false; + } + }; + + template< typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > + struct ranges< Peek, Lo, Hi > + : range< result_on_found::success, Peek, Lo, Hi > + {}; + + template< typename Peek, typename Peek::data_t C > + struct ranges< Peek, C > + : one< result_on_found::success, Peek, C > + {}; + + template< typename Peek > + struct ranges< Peek > + : failure + {}; + + template< typename Peek, typename Peek::data_t... Cs > + inline constexpr bool enable_control< ranges< Peek, Cs... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/rematch.hpp b/pxr/base/pegtl/pegtl/internal/rematch.hpp new file mode 100644 index 0000000000..bf8f497bc3 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/rematch.hpp @@ -0,0 +1,72 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_REMATCH_HPP +#define PXR_PEGTL_INTERNAL_REMATCH_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" + +#include "../apply_mode.hpp" +#include "../memory_input.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Head, typename... Rules > + struct rematch; + + template< typename Head > + struct rematch< Head > + { + using rule_t = rematch; + using subs_t = type_list< Head >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + return Control< Head >::template match< A, M, Action, Control >( in, st... ); + } + }; + + template< typename Head, typename Rule, typename... Rules > + struct rematch< Head, Rule, Rules... > + { + using rule_t = rematch; + using subs_t = type_list< Head, Rule, Rules... >; + + template< apply_mode A, + rewind_mode, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + auto m = in.template mark< rewind_mode::required >(); + + if( Control< Head >::template match< A, rewind_mode::active, Action, Control >( in, st... ) ) { + memory_input< ParseInput::tracking_mode_v, typename ParseInput::eol_t, typename ParseInput::source_t > i2( m.iterator(), in.current(), in.source() ); + return m( ( Control< Rule >::template match< A, rewind_mode::active, Action, Control >( i2, st... ) && ... && ( i2.restart( m ), Control< Rules >::template match< A, rewind_mode::active, Action, Control >( i2, st... ) ) ) ); + } + return false; + } + }; + + template< typename Head, typename... Rules > + inline constexpr bool enable_control< rematch< Head, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/rep.hpp b/pxr/base/pegtl/pegtl/internal/rep.hpp new file mode 100644 index 0000000000..c05a1b32cf --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/rep.hpp @@ -0,0 +1,67 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_REP_HPP +#define PXR_PEGTL_INTERNAL_REP_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< unsigned Cnt, typename... Rules > + struct rep + : rep< Cnt, seq< Rules... > > + {}; + + template< unsigned Cnt > + struct rep< Cnt > + : success + {}; + + template< typename Rule > + struct rep< 0, Rule > + : success + {}; + + template< unsigned Cnt, typename Rule > + struct rep< Cnt, Rule > + { + using rule_t = rep; + using subs_t = type_list< Rule >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + + for( unsigned i = 0; i != Cnt; ++i ) { + if( !Control< Rule >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) { + return false; + } + } + return m( true ); + } + }; + + template< unsigned Cnt, typename... Rules > + inline constexpr bool enable_control< rep< Cnt, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/rep_min.hpp b/pxr/base/pegtl/pegtl/internal/rep_min.hpp new file mode 100644 index 0000000000..126c216668 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/rep_min.hpp @@ -0,0 +1,20 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_REP_MIN_HPP +#define PXR_PEGTL_INTERNAL_REP_MIN_HPP + +#include "../config.hpp" + +#include "rep.hpp" +#include "seq.hpp" +#include "star.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< unsigned Min, typename Rule, typename... Rules > + using rep_min = seq< rep< Min, Rule, Rules... >, star< Rule, Rules... > >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/rep_min_max.hpp b/pxr/base/pegtl/pegtl/internal/rep_min_max.hpp new file mode 100644 index 0000000000..67091b4f36 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/rep_min_max.hpp @@ -0,0 +1,81 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_REP_MIN_MAX_HPP +#define PXR_PEGTL_INTERNAL_REP_MIN_MAX_HPP + +#include + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "failure.hpp" +#include "not_at.hpp" +#include "seq.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< unsigned Min, unsigned Max, typename... Rules > + struct rep_min_max + : rep_min_max< Min, Max, seq< Rules... > > + { + static_assert( Min <= Max ); + }; + + template< unsigned Min, unsigned Max > + struct rep_min_max< Min, Max > + : failure + { + static_assert( Min <= Max ); + }; + + template< typename Rule > + struct rep_min_max< 0, 0, Rule > + : not_at< Rule > + {}; + + template< unsigned Min, unsigned Max, typename Rule > + struct rep_min_max< Min, Max, Rule > + { + using rule_t = rep_min_max; + using subs_t = type_list< Rule >; + + static_assert( Min <= Max ); + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + + for( unsigned i = 0; i != Min; ++i ) { + if( !Control< Rule >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) { + return false; + } + } + for( unsigned i = Min; i != Max; ++i ) { + if( !Control< Rule >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) { + return m( true ); + } + } + return m( Control< not_at< Rule > >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ); // NOTE that not_at<> will always rewind. + } + }; + + template< unsigned Min, unsigned Max, typename... Rules > + inline constexpr bool enable_control< rep_min_max< Min, Max, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/rep_opt.hpp b/pxr/base/pegtl/pegtl/internal/rep_opt.hpp new file mode 100644 index 0000000000..a624eb03db --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/rep_opt.hpp @@ -0,0 +1,61 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_REP_OPT_HPP +#define PXR_PEGTL_INTERNAL_REP_OPT_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< unsigned Max, typename... Rules > + struct rep_opt + : rep_opt< Max, seq< Rules... > > + {}; + + template< unsigned Max > + struct rep_opt< Max > + : success + {}; + + template< typename... Rules > + struct rep_opt< 0, Rules... > + : success + {}; + + template< unsigned Max, typename Rule > + struct rep_opt< Max, Rule > + { + using rule_t = rep_opt; + using subs_t = type_list< Rule >; + + template< apply_mode A, + rewind_mode, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + for( unsigned i = 0; ( i != Max ) && Control< Rule >::template match< A, rewind_mode::required, Action, Control >( in, st... ); ++i ) { + } + return true; + } + }; + + template< unsigned Max, typename... Rules > + inline constexpr bool enable_control< rep_opt< Max, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/require.hpp b/pxr/base/pegtl/pegtl/internal/require.hpp new file mode 100644 index 0000000000..290ee9c5e8 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/require.hpp @@ -0,0 +1,42 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_REQUIRE_HPP +#define PXR_PEGTL_INTERNAL_REQUIRE_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "success.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< unsigned Amount > + struct require; + + template<> + struct require< 0 > + : success + {}; + + template< unsigned Amount > + struct require + { + using rule_t = require; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) ) + { + return in.size( Amount ) >= Amount; + } + }; + + template< unsigned Amount > + inline constexpr bool enable_control< require< Amount > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/result_on_found.hpp b/pxr/base/pegtl/pegtl/internal/result_on_found.hpp new file mode 100644 index 0000000000..669d942137 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/result_on_found.hpp @@ -0,0 +1,19 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_RESULT_ON_FOUND_HPP +#define PXR_PEGTL_INTERNAL_RESULT_ON_FOUND_HPP + +#include "../config.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + enum class result_on_found : bool + { + success = true, + failure = false + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/rules.hpp b/pxr/base/pegtl/pegtl/internal/rules.hpp new file mode 100644 index 0000000000..cee1ffd68a --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/rules.hpp @@ -0,0 +1,64 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_RULES_HPP +#define PXR_PEGTL_INTERNAL_RULES_HPP + +#include "action.hpp" +#include "any.hpp" +#include "apply.hpp" +#include "apply0.hpp" +#include "at.hpp" +#include "bof.hpp" +#include "bol.hpp" +#include "bytes.hpp" +#include "control.hpp" +#include "disable.hpp" +#include "discard.hpp" +#include "enable.hpp" +#include "enable_control.hpp" +#include "eof.hpp" +#include "eol.hpp" +#include "eolf.hpp" +#include "failure.hpp" +#include "identifier.hpp" +#include "if_apply.hpp" +#include "if_then_else.hpp" +#include "istring.hpp" +#include "list.hpp" +#include "list_tail.hpp" +#include "list_tail_pad.hpp" +#include "minus.hpp" +#include "not_at.hpp" +#include "one.hpp" +#include "opt.hpp" +#include "pad.hpp" +#include "pad_opt.hpp" +#include "plus.hpp" +#include "range.hpp" +#include "ranges.hpp" +#include "rematch.hpp" +#include "rep.hpp" +#include "rep_min.hpp" +#include "rep_min_max.hpp" +#include "rep_opt.hpp" +#include "require.hpp" +#include "seq.hpp" +#include "sor.hpp" +#include "star.hpp" +#include "state.hpp" +#include "string.hpp" +#include "success.hpp" +#include "until.hpp" + +#if defined( __cpp_exceptions ) +#include "if_must.hpp" +#include "if_must_else.hpp" +#include "list_must.hpp" +#include "must.hpp" +#include "raise.hpp" +#include "star_must.hpp" +#include "try_catch_type.hpp" +#endif + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/seq.hpp b/pxr/base/pegtl/pegtl/internal/seq.hpp new file mode 100644 index 0000000000..eb8be589f5 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/seq.hpp @@ -0,0 +1,58 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_SEQ_HPP +#define PXR_PEGTL_INTERNAL_SEQ_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... Rules > + struct seq; + + template<> + struct seq<> + : success + {}; + + template< typename... Rules > + struct seq + { + using rule_t = seq; + using subs_t = type_list< Rules... >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + if constexpr( sizeof...( Rules ) == 1 ) { + return Control< Rules... >::template match< A, M, Action, Control >( in, st... ); + } + else { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + return m( ( Control< Rules >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) && ... ) ); + } + } + }; + + template< typename... Rules > + inline constexpr bool enable_control< seq< Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/sor.hpp b/pxr/base/pegtl/pegtl/internal/sor.hpp new file mode 100644 index 0000000000..2b080213cf --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/sor.hpp @@ -0,0 +1,67 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_SOR_HPP +#define PXR_PEGTL_INTERNAL_SOR_HPP + +#include + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "failure.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename... Rules > + struct sor; + + template<> + struct sor<> + : failure + {}; + + template< typename... Rules > + struct sor + { + using rule_t = sor; + using subs_t = type_list< Rules... >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + std::size_t... Indices, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( std::index_sequence< Indices... > /*unused*/, ParseInput& in, States&&... st ) + { + return ( Control< Rules >::template match< A, ( ( Indices == ( sizeof...( Rules ) - 1 ) ) ? M : rewind_mode::required ), Action, Control >( in, st... ) || ... ); + } + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + return match< A, M, Action, Control >( std::index_sequence_for< Rules... >(), in, st... ); + } + }; + + template< typename... Rules > + inline constexpr bool enable_control< sor< Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/star.hpp b/pxr/base/pegtl/pegtl/internal/star.hpp new file mode 100644 index 0000000000..205c33571f --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/star.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_STAR_HPP +#define PXR_PEGTL_INTERNAL_STAR_HPP + +#include + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Rule, typename... Rules > + struct star + : star< seq< Rule, Rules... > > + {}; + + template< typename Rule > + struct star< Rule > + { + using rule_t = star; + using subs_t = type_list< Rule >; + + template< apply_mode A, + rewind_mode, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + while( Control< Rule >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) { + } + return true; + } + }; + + template< typename Rule, typename... Rules > + inline constexpr bool enable_control< star< Rule, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/star_must.hpp b/pxr/base/pegtl/pegtl/internal/star_must.hpp new file mode 100644 index 0000000000..d720ca9b26 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/star_must.hpp @@ -0,0 +1,24 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_STAR_MUST_HPP +#define PXR_PEGTL_INTERNAL_STAR_MUST_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/star_must.hpp" +#else + +#include "../config.hpp" + +#include "if_must.hpp" +#include "star.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Cond, typename... Rules > + using star_must = star< if_must< false, Cond, Rules... > >; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/internal/state.hpp b/pxr/base/pegtl/pegtl/internal/state.hpp new file mode 100644 index 0000000000..6b770f06b2 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/state.hpp @@ -0,0 +1,75 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_STATE_HPP +#define PXR_PEGTL_INTERNAL_STATE_HPP + +#include "../config.hpp" + +#include + +#include "dependent_false.hpp" +#include "enable_control.hpp" +#include "seq.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename NewState, typename... Rules > + struct state + : state< NewState, seq< Rules... > > + {}; + + template< typename NewState > + struct state< NewState > + : success + {}; + + template< typename NewState, typename Rule > + struct state< NewState, Rule > + { + using rule_t = state; + using subs_t = type_list< Rule >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + if constexpr( std::is_constructible_v< NewState, const ParseInput&, States... > ) { + NewState s( static_cast< const ParseInput& >( in ), st... ); + if( Control< Rule >::template match< A, M, Action, Control >( in, s ) ) { + s.success( static_cast< const ParseInput& >( in ), st... ); + return true; + } + return false; + } + else if constexpr( std::is_default_constructible_v< NewState > ) { + NewState s; + if( Control< Rule >::template match< A, M, Action, Control >( in, s ) ) { + s.success( static_cast< const ParseInput& >( in ), st... ); + return true; + } + return false; + } + else { + static_assert( internal::dependent_false< NewState >, "unable to instantiate new state" ); + } + } + }; + + template< typename NewState, typename... Rules > + inline constexpr bool enable_control< state< NewState, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/string.hpp b/pxr/base/pegtl/pegtl/internal/string.hpp new file mode 100644 index 0000000000..4515c66368 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/string.hpp @@ -0,0 +1,67 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_STRING_HPP +#define PXR_PEGTL_INTERNAL_STRING_HPP + +#include +#include + +#include "../config.hpp" + +#include "bump_help.hpp" +#include "enable_control.hpp" +#include "one.hpp" +#include "result_on_found.hpp" +#include "success.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + [[nodiscard]] inline bool unsafe_equals( const char* s, const std::initializer_list< char >& l ) noexcept + { + return std::memcmp( s, &*l.begin(), l.size() ) == 0; + } + + template< char... Cs > + struct string; + + template<> + struct string<> + : success + {}; + + // template< char C > + // struct string + // : one< C > + // {}; + + template< char... Cs > + struct string + { + using rule_t = string; + using subs_t = empty_list; + + template< int Eol > + static constexpr bool can_match_eol = one< result_on_found::success, peek_char, Cs... >::template can_match_eol< Eol >; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) ) + { + if( in.size( sizeof...( Cs ) ) >= sizeof...( Cs ) ) { + if( unsafe_equals( in.current(), { Cs... } ) ) { + bump_help< string >( in, sizeof...( Cs ) ); + return true; + } + } + return false; + } + }; + + template< char... Cs > + inline constexpr bool enable_control< string< Cs... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/success.hpp b/pxr/base/pegtl/pegtl/internal/success.hpp new file mode 100644 index 0000000000..834d6c2fac --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/success.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_SUCCESS_HPP +#define PXR_PEGTL_INTERNAL_SUCCESS_HPP + +#include "../config.hpp" + +#include "enable_control.hpp" + +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + struct success + { + using rule_t = success; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& /*unused*/ ) noexcept + { + return true; + } + }; + + template<> + inline constexpr bool enable_control< success > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/try_catch_type.hpp b/pxr/base/pegtl/pegtl/internal/try_catch_type.hpp new file mode 100644 index 0000000000..34821537f0 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/try_catch_type.hpp @@ -0,0 +1,69 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_TRY_CATCH_TYPE_HPP +#define PXR_PEGTL_INTERNAL_TRY_CATCH_TYPE_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/try_catch_type.hpp" +#else + +#include + +#include "../config.hpp" + +#include "enable_control.hpp" +#include "seq.hpp" +#include "success.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Exception, typename... Rules > + struct try_catch_type + : try_catch_type< Exception, seq< Rules... > > + {}; + + template< typename Exception > + struct try_catch_type< Exception > + : success + {}; + + template< typename Exception, typename Rule > + struct try_catch_type< Exception, Rule > + { + using rule_t = try_catch_type; + using subs_t = type_list< Rule >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + + try { + return m( Control< Rule >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ); + } + catch( const Exception& ) { + return false; + } + } + }; + + template< typename Exception, typename... Rules > + inline constexpr bool enable_control< try_catch_type< Exception, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/internal/until.hpp b/pxr/base/pegtl/pegtl/internal/until.hpp new file mode 100644 index 0000000000..0bad8903c3 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/until.hpp @@ -0,0 +1,88 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_UNTIL_HPP +#define PXR_PEGTL_INTERNAL_UNTIL_HPP + +#include "../config.hpp" + +#include "bytes.hpp" +#include "enable_control.hpp" +#include "eof.hpp" +#include "not_at.hpp" +#include "seq.hpp" +#include "star.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Cond, typename... Rules > + struct until + : until< Cond, seq< Rules... > > + {}; + + template< typename Cond > + struct until< Cond > + { + using rule_t = until; + using subs_t = type_list< Cond >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + auto m = in.template mark< M >(); + + while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) { + if( in.empty() ) { + return false; + } + in.bump(); + } + return m( true ); + } + }; + + template< typename Cond, typename Rule > + struct until< Cond, Rule > + { + using rule_t = until; + using subs_t = type_list< Cond, Rule >; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + + while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) { + if( !Control< Rule >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) { + return false; + } + } + return m( true ); + } + }; + + template< typename Cond, typename... Rules > + inline constexpr bool enable_control< until< Cond, Rules... > > = false; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/internal/unwind_guard.hpp b/pxr/base/pegtl/pegtl/internal/unwind_guard.hpp new file mode 100644 index 0000000000..e9811ae815 --- /dev/null +++ b/pxr/base/pegtl/pegtl/internal/unwind_guard.hpp @@ -0,0 +1,39 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_INTERNAL_UNWIND_GUARD_HPP +#define PXR_PEGTL_INTERNAL_UNWIND_GUARD_HPP + +#include "../config.hpp" + +#include +#include + +namespace PXR_PEGTL_NAMESPACE::internal +{ + template< typename Unwind > + struct unwind_guard + { + explicit unwind_guard( Unwind&& unwind_impl ) + : unwind( std::move( unwind_impl ) ) + {} + + ~unwind_guard() + { + if( unwind ) { + ( *unwind )(); + } + } + + unwind_guard( const unwind_guard& ) = delete; + unwind_guard( unwind_guard&& ) noexcept = delete; + + unwind_guard& operator=( const unwind_guard& ) = delete; + unwind_guard& operator=( unwind_guard&& ) noexcept = delete; + + std::optional< Unwind > unwind; + }; + +} // namespace PXR_PEGTL_NAMESPACE::internal + +#endif diff --git a/pxr/base/pegtl/pegtl/istream_input.hpp b/pxr/base/pegtl/pegtl/istream_input.hpp new file mode 100644 index 0000000000..9924677f22 --- /dev/null +++ b/pxr/base/pegtl/pegtl/istream_input.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_ISTREAM_INPUT_HPP +#define PXR_PEGTL_ISTREAM_INPUT_HPP + +#include + +#include "buffer_input.hpp" +#include "config.hpp" +#include "eol.hpp" + +#include "internal/istream_reader.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< typename Eol = eol::lf_crlf, std::size_t Chunk = 64 > + struct istream_input + : buffer_input< internal::istream_reader, Eol, std::string, Chunk > + { + template< typename T > + istream_input( std::istream& in_stream, const std::size_t in_maximum, T&& in_source ) + : buffer_input< internal::istream_reader, Eol, std::string, Chunk >( std::forward< T >( in_source ), in_maximum, in_stream ) + {} + }; + + template< typename... Ts > + istream_input( Ts&&... ) -> istream_input<>; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/match.hpp b/pxr/base/pegtl/pegtl/match.hpp new file mode 100644 index 0000000000..fc286497b8 --- /dev/null +++ b/pxr/base/pegtl/pegtl/match.hpp @@ -0,0 +1,173 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_MATCH_HPP +#define PXR_PEGTL_MATCH_HPP + +#include + +#include "apply_mode.hpp" +#include "config.hpp" +#include "nothing.hpp" +#include "require_apply.hpp" +#include "require_apply0.hpp" +#include "rewind_mode.hpp" + +#include "internal/has_apply.hpp" +#include "internal/has_apply0.hpp" +#include "internal/has_unwind.hpp" +#include "internal/marker.hpp" +#include "internal/missing_apply.hpp" +#include "internal/missing_apply0.hpp" +#include "internal/unwind_guard.hpp" + +#if defined( _MSC_VER ) +#pragma warning( push ) +#pragma warning( disable : 4702 ) +#endif + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static auto match_no_control( ParseInput& in, States&&... st ) + -> decltype( Rule::template match< A, M, Action, Control >( in, st... ) ) + { + return Rule::template match< A, M, Action, Control >( in, st... ); + } + + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static auto match_no_control( ParseInput& in, States&&... /*unused*/ ) + -> decltype( Rule::match( in ) ) + { + return Rule::match( in ); + } + + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] auto match_control_unwind( ParseInput& in, States&&... st ) + { +#if defined( __cpp_exceptions ) + if constexpr( has_unwind< Control< Rule >, void, const ParseInput&, States... > ) { + unwind_guard ug( [ & ] { + Control< Rule >::unwind( static_cast< const ParseInput& >( in ), st... ); + } ); + const auto result = match_no_control< Rule, A, M, Action, Control >( in, st... ); + ug.unwind.reset(); + return result; + } + else { + return match_no_control< Rule, A, M, Action, Control >( in, st... ); + } +#else + return match_no_control< Rule, A, M, Action, Control >( in, st... ); +#endif + } + + } // namespace internal + + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] auto match( ParseInput& in, States&&... st ) + { + if constexpr( !Control< Rule >::enable ) { + return internal::match_no_control< Rule, A, M, Action, Control >( in, st... ); + } + else { + constexpr bool enable_action = ( A == apply_mode::action ); + + using iterator_t = typename ParseInput::iterator_t; + constexpr bool has_apply_void = enable_action && internal::has_apply< Control< Rule >, void, Action, const iterator_t&, const ParseInput&, States... >; + constexpr bool has_apply_bool = enable_action && internal::has_apply< Control< Rule >, bool, Action, const iterator_t&, const ParseInput&, States... >; + constexpr bool has_apply = has_apply_void || has_apply_bool; + + constexpr bool has_apply0_void = enable_action && internal::has_apply0< Control< Rule >, void, Action, const ParseInput&, States... >; + constexpr bool has_apply0_bool = enable_action && internal::has_apply0< Control< Rule >, bool, Action, const ParseInput&, States... >; + constexpr bool has_apply0 = has_apply0_void || has_apply0_bool; + + static_assert( !( has_apply && has_apply0 ), "both apply() and apply0() defined" ); + + constexpr bool is_nothing = std::is_base_of_v< nothing< Rule >, Action< Rule > >; + static_assert( !( has_apply && is_nothing ), "unexpected apply() defined" ); + static_assert( !( has_apply0 && is_nothing ), "unexpected apply0() defined" ); + + if constexpr( !has_apply && std::is_base_of_v< require_apply, Action< Rule > > ) { + internal::missing_apply< Control< Rule >, Action >( in, st... ); + } + + if constexpr( !has_apply0 && std::is_base_of_v< require_apply0, Action< Rule > > ) { + internal::missing_apply0< Control< Rule >, Action >( in, st... ); + } + + constexpr bool validate_nothing = std::is_base_of_v< maybe_nothing, Action< void > >; + constexpr bool is_maybe_nothing = std::is_base_of_v< maybe_nothing, Action< Rule > >; + static_assert( !enable_action || !validate_nothing || is_nothing || is_maybe_nothing || has_apply || has_apply0, "either apply() or apply0() must be defined" ); + + constexpr bool use_marker = has_apply || has_apply0_bool; + + auto m = in.template mark< ( use_marker ? rewind_mode::required : rewind_mode::dontcare ) >(); + Control< Rule >::start( static_cast< const ParseInput& >( in ), st... ); + auto result = internal::match_control_unwind< Rule, A, ( use_marker ? rewind_mode::active : M ), Action, Control >( in, st... ); + if( result ) { + if constexpr( has_apply_void ) { + Control< Rule >::template apply< Action >( m.iterator(), static_cast< const ParseInput& >( in ), st... ); + } + else if constexpr( has_apply_bool ) { + result = Control< Rule >::template apply< Action >( m.iterator(), static_cast< const ParseInput& >( in ), st... ); + } + else if constexpr( has_apply0_void ) { + Control< Rule >::template apply0< Action >( static_cast< const ParseInput& >( in ), st... ); + } + else if constexpr( has_apply0_bool ) { + result = Control< Rule >::template apply0< Action >( static_cast< const ParseInput& >( in ), st... ); + } + } + if( result ) { + Control< Rule >::success( static_cast< const ParseInput& >( in ), st... ); + } + else { + Control< Rule >::failure( static_cast< const ParseInput& >( in ), st... ); + } + (void)m( result ); + return result; + } + } + +} // namespace PXR_PEGTL_NAMESPACE + +#if defined( _MSC_VER ) +#pragma warning( pop ) +#endif + +#endif diff --git a/pxr/base/pegtl/pegtl/memory_input.hpp b/pxr/base/pegtl/pegtl/memory_input.hpp new file mode 100644 index 0000000000..1213fedc00 --- /dev/null +++ b/pxr/base/pegtl/pegtl/memory_input.hpp @@ -0,0 +1,378 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_MEMORY_INPUT_HPP +#define PXR_PEGTL_MEMORY_INPUT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config.hpp" +#include "eol.hpp" +#include "normal.hpp" +#include "nothing.hpp" +#include "position.hpp" +#include "tracking_mode.hpp" + +#include "internal/action_input.hpp" +#include "internal/at.hpp" +#include "internal/bump.hpp" +#include "internal/eolf.hpp" +#include "internal/iterator.hpp" +#include "internal/marker.hpp" +#include "internal/until.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< tracking_mode, typename Eol, typename Source > + class memory_input_base; + + template< typename Eol, typename Source > + class memory_input_base< tracking_mode::eager, Eol, Source > + { + public: + using iterator_t = internal::iterator; + + template< typename T > + memory_input_base( const iterator_t& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) + : m_begin( in_begin.data ), + m_current( in_begin ), + m_end( in_end ), + m_source( std::forward< T >( in_source ) ) + {} + + template< typename T > + memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) + : m_begin( in_begin ), + m_current( in_begin ), + m_end( in_end ), + m_source( std::forward< T >( in_source ) ) + {} + + memory_input_base( const memory_input_base& ) = delete; + memory_input_base( memory_input_base&& ) = delete; + + ~memory_input_base() = default; + + memory_input_base& operator=( const memory_input_base& ) = delete; + memory_input_base& operator=( memory_input_base&& ) = delete; + + [[nodiscard]] const char* current() const noexcept + { + return m_current.data; + } + + [[nodiscard]] const char* begin() const noexcept + { + return m_begin; + } + + [[nodiscard]] const char* end( const std::size_t /*unused*/ = 0 ) const noexcept + { + return m_end; + } + + [[nodiscard]] std::size_t byte() const noexcept + { + return m_current.byte; + } + + [[nodiscard]] std::size_t line() const noexcept + { + return m_current.line; + } + + [[nodiscard]] std::size_t column() const noexcept + { + return m_current.column; + } + + void bump( const std::size_t in_count = 1 ) noexcept + { + internal::bump( m_current, in_count, Eol::ch ); + } + + void bump_in_this_line( const std::size_t in_count = 1 ) noexcept + { + internal::bump_in_this_line( m_current, in_count ); + } + + void bump_to_next_line( const std::size_t in_count = 1 ) noexcept + { + internal::bump_to_next_line( m_current, in_count ); + } + + [[nodiscard]] PXR_PEGTL_NAMESPACE::position position( const iterator_t& it ) const + { + return PXR_PEGTL_NAMESPACE::position( it, m_source ); + } + + void restart( const std::size_t in_byte = 0, const std::size_t in_line = 1, const std::size_t in_column = 1 ) + { + assert( in_line != 0 ); + assert( in_column != 0 ); + + m_current.data = m_begin; + m_current.byte = in_byte; + m_current.line = in_line; + m_current.column = in_column; + private_depth = 0; + } + + protected: + const char* const m_begin; + iterator_t m_current; + const char* m_end; + const Source m_source; + + public: + std::size_t private_depth = 0; + }; + + template< typename Eol, typename Source > + class memory_input_base< tracking_mode::lazy, Eol, Source > + { + public: + using iterator_t = const char*; + + template< typename T > + memory_input_base( const internal::iterator& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) + : m_begin( in_begin ), + m_current( in_begin.data ), + m_end( in_end ), + m_source( std::forward< T >( in_source ) ) + {} + + template< typename T > + memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) + : m_begin( in_begin ), + m_current( in_begin ), + m_end( in_end ), + m_source( std::forward< T >( in_source ) ) + {} + + memory_input_base( const memory_input_base& ) = delete; + memory_input_base( memory_input_base&& ) = delete; + + ~memory_input_base() = default; + + memory_input_base& operator=( const memory_input_base& ) = delete; + memory_input_base& operator=( memory_input_base&& ) = delete; + + [[nodiscard]] const char* current() const noexcept + { + return m_current; + } + + [[nodiscard]] const char* begin() const noexcept + { + return m_begin.data; + } + + [[nodiscard]] const char* end( const std::size_t /*unused*/ = 0 ) const noexcept + { + return m_end; + } + + [[nodiscard]] std::size_t byte() const noexcept + { + return std::size_t( current() - m_begin.data ); + } + + void bump( const std::size_t in_count = 1 ) noexcept + { + m_current += in_count; + } + + void bump_in_this_line( const std::size_t in_count = 1 ) noexcept + { + m_current += in_count; + } + + void bump_to_next_line( const std::size_t in_count = 1 ) noexcept + { + m_current += in_count; + } + + [[nodiscard]] PXR_PEGTL_NAMESPACE::position position( const iterator_t it ) const + { + internal::iterator c( m_begin ); + internal::bump( c, std::size_t( it - m_begin.data ), Eol::ch ); + return PXR_PEGTL_NAMESPACE::position( c, m_source ); + } + + void restart() + { + m_current = m_begin.data; + private_depth = 0; + } + + protected: + const internal::iterator m_begin; + iterator_t m_current; + const char* m_end; + const Source m_source; + + public: + std::size_t private_depth = 0; + }; + + } // namespace internal + + template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf, typename Source = std::string > + class memory_input + : public internal::memory_input_base< P, Eol, Source > + { + public: + static constexpr tracking_mode tracking_mode_v = P; + + using eol_t = Eol; + using source_t = Source; + + using typename internal::memory_input_base< P, Eol, Source >::iterator_t; + + using action_t = internal::action_input< memory_input >; + + using internal::memory_input_base< P, Eol, Source >::memory_input_base; + + template< typename T > + memory_input( const char* in_begin, const std::size_t in_size, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) + : memory_input( in_begin, in_begin + in_size, std::forward< T >( in_source ) ) + {} + + template< typename T > + memory_input( const std::string& in_string, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) + : memory_input( in_string.data(), in_string.size(), std::forward< T >( in_source ) ) + {} + + template< typename T > + memory_input( const std::string_view in_string, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) + : memory_input( in_string.data(), in_string.size(), std::forward< T >( in_source ) ) + {} + + template< typename T > + memory_input( std::string&&, T&& ) = delete; + + template< typename T > + memory_input( const char* in_begin, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) + : memory_input( in_begin, std::strlen( in_begin ), std::forward< T >( in_source ) ) + {} + + template< typename T > + memory_input( const char* in_begin, const char* in_end, T&& in_source, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_column ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) + : memory_input( { in_begin, in_byte, in_line, in_column }, in_end, std::forward< T >( in_source ) ) + {} + + memory_input( const memory_input& ) = delete; + memory_input( memory_input&& ) = delete; + + ~memory_input() = default; + + memory_input& operator=( const memory_input& ) = delete; + memory_input& operator=( memory_input&& ) = delete; + + [[nodiscard]] const Source& source() const noexcept + { + return this->m_source; + } + + [[nodiscard]] bool empty() const noexcept + { + return this->current() == this->end(); + } + + [[nodiscard]] std::size_t size( const std::size_t /*unused*/ = 0 ) const noexcept + { + return std::size_t( this->end() - this->current() ); + } + + [[nodiscard]] char peek_char( const std::size_t offset = 0 ) const noexcept + { + return this->current()[ offset ]; + } + + [[nodiscard]] std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept + { + return static_cast< std::uint8_t >( peek_char( offset ) ); + } + + [[nodiscard]] iterator_t& iterator() noexcept + { + return this->m_current; + } + + [[nodiscard]] const iterator_t& iterator() const noexcept + { + return this->m_current; + } + + using internal::memory_input_base< P, Eol, Source >::restart; + + template< rewind_mode M > + void restart( const internal::marker< iterator_t, M >& m ) noexcept + { + iterator() = m.iterator(); + } + + using internal::memory_input_base< P, Eol, Source >::position; + + [[nodiscard]] PXR_PEGTL_NAMESPACE::position position() const + { + return position( iterator() ); + } + + void discard() const noexcept {} + + void require( const std::size_t /*unused*/ ) const noexcept {} + + template< rewind_mode M > + [[nodiscard]] internal::marker< iterator_t, M > mark() noexcept + { + return internal::marker< iterator_t, M >( iterator() ); + } + + [[nodiscard]] const char* at( const PXR_PEGTL_NAMESPACE::position& p ) const noexcept + { + return this->begin() + p.byte; + } + + [[nodiscard]] const char* begin_of_line( const PXR_PEGTL_NAMESPACE::position& p ) const noexcept + { + return at( p ) - ( p.column - 1 ); + } + + [[nodiscard]] const char* end_of_line( const PXR_PEGTL_NAMESPACE::position& p ) const noexcept + { + using input_t = memory_input< tracking_mode::lazy, Eol, const char* >; + input_t in( at( p ), this->end(), "" ); + using grammar = internal::until< internal::at< internal::eolf > >; + (void)normal< grammar >::match< apply_mode::nothing, rewind_mode::dontcare, nothing, normal >( in ); + return in.current(); + } + + [[nodiscard]] std::string_view line_at( const PXR_PEGTL_NAMESPACE::position& p ) const noexcept + { + const char* b = begin_of_line( p ); + return std::string_view( b, static_cast< std::size_t >( end_of_line( p ) - b ) ); + } + + void private_set_end( const char* new_end ) noexcept + { + this->m_end = new_end; + } + }; + + template< typename... Ts > + memory_input( Ts&&... ) -> memory_input<>; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/mmap_input.hpp b/pxr/base/pegtl/pegtl/mmap_input.hpp new file mode 100644 index 0000000000..a927fe70a5 --- /dev/null +++ b/pxr/base/pegtl/pegtl/mmap_input.hpp @@ -0,0 +1,79 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_MMAP_INPUT_HPP +#define PXR_PEGTL_MMAP_INPUT_HPP + +#include + +#include "config.hpp" +#include "eol.hpp" +#include "memory_input.hpp" +#include "tracking_mode.hpp" + +#include "internal/filesystem.hpp" +#include "internal/path_to_string.hpp" + +#if defined( __unix__ ) || ( defined( __APPLE__ ) && defined( __MACH__ ) ) +#include // Required for _POSIX_MAPPED_FILES +#endif + +#if defined( _POSIX_MAPPED_FILES ) +#include "internal/file_mapper_posix.hpp" +#elif defined( _WIN32 ) +#include "internal/file_mapper_win32.hpp" +#else +#endif + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + struct mmap_holder + { + const file_mapper data; + + explicit mmap_holder( const internal::filesystem::path& path ) + : data( path ) + {} + + mmap_holder( const mmap_holder& ) = delete; + mmap_holder( mmap_holder&& ) = delete; + + ~mmap_holder() = default; + + mmap_holder& operator=( const mmap_holder& ) = delete; + mmap_holder& operator=( mmap_holder&& ) = delete; + }; + + } // namespace internal + + template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > + struct mmap_input + : private internal::mmap_holder, + public memory_input< P, Eol > + { + mmap_input( const internal::filesystem::path& path, const std::string& source ) + : internal::mmap_holder( path ), + memory_input< P, Eol >( data.begin(), data.end(), source ) + {} + + explicit mmap_input( const internal::filesystem::path& path ) + : mmap_input( path, internal::path_to_string( path ) ) + {} + + mmap_input( const mmap_input& ) = delete; + mmap_input( mmap_input&& ) = delete; + + ~mmap_input() = default; + + mmap_input& operator=( const mmap_input& ) = delete; + mmap_input& operator=( mmap_input&& ) = delete; + }; + + template< typename... Ts > + explicit mmap_input( Ts&&... ) -> mmap_input<>; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/must_if.hpp b/pxr/base/pegtl/pegtl/must_if.hpp new file mode 100644 index 0000000000..65ceea7fce --- /dev/null +++ b/pxr/base/pegtl/pegtl/must_if.hpp @@ -0,0 +1,69 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_MUST_IF_HPP +#define PXR_PEGTL_MUST_IF_HPP + +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/must.hpp" +#else + +#include + +#include "config.hpp" +#include "normal.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename Errors, typename Rule, typename = void > + inline constexpr bool raise_on_failure = ( Errors::template message< Rule > != nullptr ); + + template< typename Errors, typename Rule > + inline constexpr bool raise_on_failure< Errors, Rule, std::void_t< decltype( Errors::template raise_on_failure< Rule > ) > > = Errors::template raise_on_failure< Rule >; + + } // namespace internal + + template< typename Errors, template< typename... > class Base = normal, bool RequireMessage = true > + struct must_if + { + template< typename Rule > + struct control + : Base< Rule > + { + template< typename ParseInput, typename... States > + static void failure( const ParseInput& in, States&&... st ) noexcept( noexcept( Base< Rule >::failure( in, st... ) ) && !internal::raise_on_failure< Errors, Rule > ) + { + if constexpr( internal::raise_on_failure< Errors, Rule > ) { + raise( in, st... ); + } + else { + Base< Rule >::failure( in, st... ); + } + } + + template< typename ParseInput, typename... States > + [[noreturn]] static void raise( const ParseInput& in, [[maybe_unused]] States&&... st ) + { + if constexpr( RequireMessage ) { + static_assert( Errors::template message< Rule > != nullptr ); + } + if constexpr( Errors::template message< Rule > != nullptr ) { + constexpr const char* p = Errors::template message< Rule >; + throw parse_error( p, in ); +#if defined( _MSC_VER ) + ( (void)st, ... ); +#endif + } + else { + Base< Rule >::raise( in, st... ); + } + } + }; + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif +#endif diff --git a/pxr/base/pegtl/pegtl/normal.hpp b/pxr/base/pegtl/pegtl/normal.hpp new file mode 100644 index 0000000000..6983c77bec --- /dev/null +++ b/pxr/base/pegtl/pegtl/normal.hpp @@ -0,0 +1,99 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_NORMAL_HPP +#define PXR_PEGTL_NORMAL_HPP + +#include +#include +#include + +#include "apply_mode.hpp" +#include "config.hpp" +#include "match.hpp" +#include "parse_error.hpp" +#include "rewind_mode.hpp" + +#include "internal/enable_control.hpp" +#include "internal/has_match.hpp" + +#if defined( __cpp_exceptions ) +#include "demangle.hpp" +#else +#include "internal/dependent_false.hpp" +#include +#endif + +namespace PXR_PEGTL_NAMESPACE +{ + template< typename Rule > + struct normal + { + static constexpr bool enable = internal::enable_control< Rule >; + + template< typename ParseInput, typename... States > + static void start( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept + {} + + template< typename ParseInput, typename... States > + static void success( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept + {} + + template< typename ParseInput, typename... States > + static void failure( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept + {} + + template< typename ParseInput, typename... States > + [[noreturn]] static void raise( const ParseInput& in, States&&... /*unused*/ ) + { +#if defined( __cpp_exceptions ) + throw parse_error( "parse error matching " + std::string( demangle< Rule >() ), in ); +#else + static_assert( internal::dependent_false< Rule >, "exception support required for normal< Rule >::raise()" ); + (void)in; + std::terminate(); +#endif + } + + template< template< typename... > class Action, + typename Iterator, + typename ParseInput, + typename... States > + static auto apply( const Iterator& begin, const ParseInput& in, States&&... st ) noexcept( noexcept( Action< Rule >::apply( std::declval< const typename ParseInput::action_t& >(), st... ) ) ) + -> decltype( Action< Rule >::apply( std::declval< const typename ParseInput::action_t& >(), st... ) ) + { + const typename ParseInput::action_t action_input( begin, in ); + return Action< Rule >::apply( action_input, st... ); + } + + template< template< typename... > class Action, + typename ParseInput, + typename... States > + static auto apply0( const ParseInput& /*unused*/, States&&... st ) noexcept( noexcept( Action< Rule >::apply0( st... ) ) ) + -> decltype( Action< Rule >::apply0( st... ) ) + { + return Action< Rule >::apply0( st... ); + } + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + if constexpr( internal::has_match< bool, Rule, A, M, Action, Control, ParseInput, States... > ) { + return Action< Rule >::template match< Rule, A, M, Action, Control >( in, st... ); + } + else { + return PXR_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); + } + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/nothing.hpp b/pxr/base/pegtl/pegtl/nothing.hpp new file mode 100644 index 0000000000..b30d947157 --- /dev/null +++ b/pxr/base/pegtl/pegtl/nothing.hpp @@ -0,0 +1,19 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_NOTHING_HPP +#define PXR_PEGTL_NOTHING_HPP + +#include "config.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< typename Rule > + struct nothing + {}; + + using maybe_nothing = nothing< void >; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/parse.hpp b/pxr/base/pegtl/pegtl/parse.hpp new file mode 100644 index 0000000000..20b857b8f4 --- /dev/null +++ b/pxr/base/pegtl/pegtl/parse.hpp @@ -0,0 +1,72 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_PARSE_HPP +#define PXR_PEGTL_PARSE_HPP + +#include + +#include "apply_mode.hpp" +#include "config.hpp" +#include "normal.hpp" +#include "nothing.hpp" +#include "parse_error.hpp" +#include "position.hpp" +#include "rewind_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + [[nodiscard]] inline auto get_position( const position& p ) noexcept( std::is_nothrow_copy_constructible_v< position > ) + { + return p; + } + + template< typename ParseInput > + [[nodiscard]] position get_position( const ParseInput& in ) noexcept( noexcept( position( in.position() ) ) ) + { + return in.position(); + } + + } // namespace internal + + template< typename Rule, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + apply_mode A = apply_mode::action, + rewind_mode M = rewind_mode::required, + typename ParseInput, + typename... States > + auto parse( ParseInput&& in, States&&... st ) + { + return Control< Rule >::template match< A, M, Action, Control >( in, st... ); + } + + template< typename Rule, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + apply_mode A = apply_mode::action, + rewind_mode M = rewind_mode::required, + typename Outer, + typename ParseInput, + typename... States > + auto parse_nested( const Outer& o, ParseInput&& in, States&&... st ) + { +#if defined( __cpp_exceptions ) + try { + return parse< Rule, Action, Control, A, M >( in, st... ); + } + catch( parse_error& e ) { + e.add_position( internal::get_position( o ) ); + throw; + } +#else + (void)o; + return parse< Rule, Action, Control, A, M >( in, st... ); +#endif + } + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/parse_error.hpp b/pxr/base/pegtl/pegtl/parse_error.hpp new file mode 100644 index 0000000000..3e5b9175ad --- /dev/null +++ b/pxr/base/pegtl/pegtl/parse_error.hpp @@ -0,0 +1,119 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_PARSE_ERROR_HPP +#define PXR_PEGTL_PARSE_ERROR_HPP + +#include +#include +#include +#include +#include +#include +#include + +#include "config.hpp" +#include "position.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + class parse_error + { + private: + std::string m_msg; + std::size_t m_prefix = 0; + std::vector< position > m_positions; + + public: + explicit parse_error( const char* msg ) + : m_msg( msg ) + {} + + [[nodiscard]] const char* what() const noexcept + { + return m_msg.c_str(); + } + + [[nodiscard]] std::string_view message() const noexcept + { + return { m_msg.data() + m_prefix, m_msg.size() - m_prefix }; + } + + [[nodiscard]] const std::vector< position >& positions() const noexcept + { + return m_positions; + } + + void add_position( position&& p ) + { + const auto prefix = to_string( p ); + m_msg = prefix + ": " + m_msg; + m_prefix += prefix.size() + 2; + m_positions.emplace_back( std::move( p ) ); + } + }; + + } // namespace internal + + class parse_error + : public std::runtime_error + { + private: + std::shared_ptr< internal::parse_error > m_impl; + + public: + parse_error( const char* msg, position p ) + : std::runtime_error( msg ), + m_impl( std::make_shared< internal::parse_error >( msg ) ) + { + m_impl->add_position( std::move( p ) ); + } + + parse_error( const std::string& msg, position p ) + : parse_error( msg.c_str(), std::move( p ) ) + {} + + template< typename ParseInput > + parse_error( const char* msg, const ParseInput& in ) + : parse_error( msg, in.position() ) + {} + + template< typename ParseInput > + parse_error( const std::string& msg, const ParseInput& in ) + : parse_error( msg, in.position() ) + {} + + [[nodiscard]] const char* what() const noexcept override + { + return m_impl->what(); + } + + [[nodiscard]] std::string_view message() const noexcept + { + return m_impl->message(); + } + + [[nodiscard]] const std::vector< position >& positions() const noexcept + { + return m_impl->positions(); + } + + void add_position( position&& p ) + { + if( m_impl.use_count() > 1 ) { + m_impl = std::make_shared< internal::parse_error >( *m_impl ); + } + m_impl->add_position( std::move( p ) ); + } + + void add_position( const position& p ) + { + add_position( position( p ) ); + } + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/position.hpp b/pxr/base/pegtl/pegtl/position.hpp new file mode 100644 index 0000000000..7793fc5403 --- /dev/null +++ b/pxr/base/pegtl/pegtl/position.hpp @@ -0,0 +1,98 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_POSITION_HPP +#define PXR_PEGTL_POSITION_HPP + +#include +#include +#include +#include +#include + +#include "config.hpp" + +#include "internal/iterator.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + struct position + { + position() = delete; + +#if defined( __GNUC__ ) && !defined( __clang__ ) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + position( position&& p ) noexcept + : byte( p.byte ), + line( p.line ), + column( p.column ), + source( std::move( p.source ) ) + {} +#if defined( __GNUC__ ) && !defined( __clang__ ) +#pragma GCC diagnostic pop +#endif + + position( const position& ) = default; + + position& operator=( position&& p ) noexcept + { + byte = p.byte; + line = p.line; + column = p.column; + source = std::move( p.source ); + return *this; + } + + position& operator=( const position& ) = default; + + template< typename T > + position( const internal::iterator& in_iter, T&& in_source ) + : byte( in_iter.byte ), + line( in_iter.line ), + column( in_iter.column ), + source( std::forward< T >( in_source ) ) + {} + + template< typename T > + position( const std::size_t in_byte, const std::size_t in_line, const std::size_t in_column, T&& in_source ) + : byte( in_byte ), + line( in_line ), + column( in_column ), + source( in_source ) + {} + + ~position() = default; + + std::size_t byte; + std::size_t line; + std::size_t column; + std::string source; + }; + + inline bool operator==( const position& lhs, const position& rhs ) noexcept + { + return ( lhs.byte == rhs.byte ) && ( lhs.source == rhs.source ); + } + + inline bool operator!=( const position& lhs, const position& rhs ) noexcept + { + return !( lhs == rhs ); + } + + inline std::ostream& operator<<( std::ostream& os, const position& p ) + { + return os << p.source << ':' << p.line << ':' << p.column; + } + + [[nodiscard]] inline std::string to_string( const position& p ) + { + std::ostringstream oss; + oss << p; + return std::move( oss ).str(); + } + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/read_input.hpp b/pxr/base/pegtl/pegtl/read_input.hpp new file mode 100644 index 0000000000..a899cbd072 --- /dev/null +++ b/pxr/base/pegtl/pegtl/read_input.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_READ_INPUT_HPP +#define PXR_PEGTL_READ_INPUT_HPP + +#include + +#include "config.hpp" +#include "eol.hpp" +#include "string_input.hpp" +#include "tracking_mode.hpp" + +#include "internal/file_reader.hpp" +#include "internal/filesystem.hpp" +#include "internal/path_to_string.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > + struct read_input + : string_input< P, Eol > + { + read_input( const internal::filesystem::path& path, const std::string& source ) + : string_input< P, Eol >( internal::file_reader( path ).read(), source ) + {} + + explicit read_input( const internal::filesystem::path& path ) + : read_input( path, internal::path_to_string( path ) ) + {} + + read_input( FILE* file, const internal::filesystem::path& path, const std::string& source ) + : string_input< P, Eol >( internal::file_reader( file, path ).read(), source ) + {} + + read_input( FILE* file, const internal::filesystem::path& path ) + : read_input( file, path, internal::path_to_string( path ) ) + {} + + read_input( const read_input& ) = delete; + read_input( read_input&& ) = delete; + + ~read_input() = default; + + read_input& operator=( const read_input& ) = delete; + read_input& operator=( read_input&& ) = delete; + }; + + template< typename... Ts > + explicit read_input( Ts&&... ) -> read_input<>; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/require_apply.hpp b/pxr/base/pegtl/pegtl/require_apply.hpp new file mode 100644 index 0000000000..8eb3a52476 --- /dev/null +++ b/pxr/base/pegtl/pegtl/require_apply.hpp @@ -0,0 +1,16 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_REQUIRE_APPLY_HPP +#define PXR_PEGTL_REQUIRE_APPLY_HPP + +#include "config.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + struct require_apply + {}; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/require_apply0.hpp b/pxr/base/pegtl/pegtl/require_apply0.hpp new file mode 100644 index 0000000000..93c849d521 --- /dev/null +++ b/pxr/base/pegtl/pegtl/require_apply0.hpp @@ -0,0 +1,16 @@ +// Copyright (c) 2019-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_REQUIRE_APPLY0_HPP +#define PXR_PEGTL_REQUIRE_APPLY0_HPP + +#include "config.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + struct require_apply0 + {}; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/rewind_mode.hpp b/pxr/base/pegtl/pegtl/rewind_mode.hpp new file mode 100644 index 0000000000..904ebff51f --- /dev/null +++ b/pxr/base/pegtl/pegtl/rewind_mode.hpp @@ -0,0 +1,20 @@ +// Copyright (c) 2016-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_REWIND_MODE_HPP +#define PXR_PEGTL_REWIND_MODE_HPP + +#include "config.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + enum class rewind_mode : char + { + active, + required, + dontcare + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/rules.hpp b/pxr/base/pegtl/pegtl/rules.hpp new file mode 100644 index 0000000000..8e5ee7b9d8 --- /dev/null +++ b/pxr/base/pegtl/pegtl/rules.hpp @@ -0,0 +1,71 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_RULES_HPP +#define PXR_PEGTL_RULES_HPP + +#include "config.hpp" +#include "parse_error.hpp" + +#include "internal/rules.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + // clang-format off + template< template< typename... > class Action, typename... Rules > struct action : internal::action< Action, Rules... > {}; + template< typename... Actions > struct apply : internal::apply< Actions... > {}; + template< typename... Actions > struct apply0 : internal::apply0< Actions... > {}; + template< typename... Rules > struct at : internal::at< Rules... > {}; + struct bof : internal::bof {}; + struct bol : internal::bol {}; + template< unsigned Num > struct bytes : internal::bytes< Num > {}; + template< template< typename... > class Control, typename... Rules > struct control : internal::control< Control, Rules... > {}; + template< typename... Rules > struct disable : internal::disable< Rules... > {}; + struct discard : internal::discard {}; + template< typename... Rules > struct enable : internal::enable< Rules... > {}; + struct eof : internal::eof {}; + struct eolf : internal::eolf {}; + struct failure : internal::failure {}; + template< typename Rule, typename... Actions > struct if_apply : internal::if_apply< Rule, Actions... > {}; + template< typename Cond, typename Then, typename Else > struct if_then_else : internal::if_then_else< Cond, Then, Else > {}; + template< typename Rule, typename Sep, typename Pad = void > struct list : internal::list< Rule, internal::pad< Sep, Pad > > {}; + template< typename Rule, typename Sep > struct list< Rule, Sep, void > : internal::list< Rule, Sep > {}; + template< typename Rule, typename Sep, typename Pad = void > struct list_tail : internal::list_tail_pad< Rule, Sep, Pad > {}; + template< typename Rule, typename Sep > struct list_tail< Rule, Sep, void > : internal::list_tail< Rule, Sep > {}; + template< typename M, typename S > struct minus : internal::minus< M, S > {}; + template< typename... Rules > struct not_at : internal::not_at< Rules... > {}; + template< typename... Rules > struct opt : internal::opt< Rules... > {}; + template< typename Rule, typename Pad1, typename Pad2 = Pad1 > struct pad : internal::pad< Rule, Pad1, Pad2 > {}; + template< typename Rule, typename Pad > struct pad_opt : internal::pad_opt< Rule, Pad > {}; + template< typename Rule, typename... Rules > struct plus : internal::plus< Rule, Rules... > {}; + template< typename Head, typename... Rules > struct rematch : internal::rematch< Head, Rules... > {}; + template< unsigned Num, typename... Rules > struct rep : internal::rep< Num, Rules... > {}; + template< unsigned Max, typename... Rules > struct rep_max : internal::rep_min_max< 0, Max, Rules... > {}; + template< unsigned Min, typename Rule, typename... Rules > struct rep_min : internal::rep_min< Min, Rule, Rules... > {}; + template< unsigned Min, unsigned Max, typename... Rules > struct rep_min_max : internal::rep_min_max< Min, Max, Rules... > {}; + template< unsigned Max, typename... Rules > struct rep_opt : internal::rep_opt< Max, Rules... > {}; + template< unsigned Amount > struct require : internal::require< Amount > {}; + template< typename... Rules > struct seq : internal::seq< Rules... > {}; + template< typename... Rules > struct sor : internal::sor< Rules... > {}; + template< typename Rule, typename... Rules > struct star : internal::star< Rule, Rules... > {}; + template< typename State, typename... Rules > struct state : internal::state< State, Rules... > {}; + struct success : internal::success {}; + template< typename Cond, typename... Rules > struct until : internal::until< Cond, Rules... > {}; + +#if defined( __cpp_exceptions ) + template< typename Cond, typename... Thens > struct if_must : internal::if_must< false, Cond, Thens... > {}; + template< typename Cond, typename Then, typename Else > struct if_must_else : internal::if_must_else< Cond, Then, Else > {}; + template< typename Rule, typename Sep, typename Pad = void > struct list_must : internal::list_must< Rule, internal::pad< Sep, Pad > > {}; + template< typename Rule, typename Sep > struct list_must< Rule, Sep, void > : internal::list_must< Rule, Sep > {}; + template< typename... Rules > struct must : internal::must< Rules... > {}; + template< typename Cond, typename... Rules > struct opt_must : internal::if_must< true, Cond, Rules... > {}; + template< typename Exception > struct raise : internal::raise< Exception > {}; + template< typename Cond, typename... Rules > struct star_must : internal::star_must< Cond, Rules... > {}; + template< typename... Rules > struct try_catch : internal::try_catch_type< parse_error, Rules... > {}; + template< typename Exception, typename... Rules > struct try_catch_type : internal::seq< internal::try_catch_type< Exception, Rules... > > {}; +#endif + // clang-format on + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/string_input.hpp b/pxr/base/pegtl/pegtl/string_input.hpp new file mode 100644 index 0000000000..7ee8e4e3c1 --- /dev/null +++ b/pxr/base/pegtl/pegtl/string_input.hpp @@ -0,0 +1,64 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_STRING_INPUT_HPP +#define PXR_PEGTL_STRING_INPUT_HPP + +#include +#include + +#include "config.hpp" +#include "eol.hpp" +#include "memory_input.hpp" +#include "tracking_mode.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + struct string_holder + { + const std::string data; + + template< typename T > + explicit string_holder( T&& in_data ) + : data( std::forward< T >( in_data ) ) + {} + + string_holder( const string_holder& ) = delete; + string_holder( string_holder&& ) = delete; + + ~string_holder() = default; + + string_holder& operator=( const string_holder& ) = delete; + string_holder& operator=( string_holder&& ) = delete; + }; + + } // namespace internal + + template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf, typename Source = std::string > + struct string_input + : private internal::string_holder, + public memory_input< P, Eol, Source > + { + template< typename V, typename T, typename... Ts > + explicit string_input( V&& in_data, T&& in_source, Ts&&... ts ) + : internal::string_holder( std::forward< V >( in_data ) ), + memory_input< P, Eol, Source >( data.data(), data.size(), std::forward< T >( in_source ), std::forward< Ts >( ts )... ) + {} + + string_input( const string_input& ) = delete; + string_input( string_input&& ) = delete; + + ~string_input() = default; + + string_input& operator=( const string_input& ) = delete; + string_input& operator=( string_input&& ) = delete; + }; + + template< typename... Ts > + explicit string_input( Ts&&... ) -> string_input<>; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/tracking_mode.hpp b/pxr/base/pegtl/pegtl/tracking_mode.hpp new file mode 100644 index 0000000000..9a35812a8b --- /dev/null +++ b/pxr/base/pegtl/pegtl/tracking_mode.hpp @@ -0,0 +1,19 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_TRACKING_MODE_HPP +#define PXR_PEGTL_TRACKING_MODE_HPP + +#include "config.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + enum class tracking_mode : bool + { + eager, + lazy + }; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/type_list.hpp b/pxr/base/pegtl/pegtl/type_list.hpp new file mode 100644 index 0000000000..d5e5d782be --- /dev/null +++ b/pxr/base/pegtl/pegtl/type_list.hpp @@ -0,0 +1,46 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_TYPE_LIST_HPP +#define PXR_PEGTL_TYPE_LIST_HPP + +#include + +#include "config.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + template< typename... Ts > + struct type_list + { + static constexpr std::size_t size = sizeof...( Ts ); + }; + + using empty_list = type_list<>; + + template< typename... > + struct type_list_concat; + + template<> + struct type_list_concat<> + { + using type = empty_list; + }; + + template< typename... Ts > + struct type_list_concat< type_list< Ts... > > + { + using type = type_list< Ts... >; + }; + + template< typename... T0s, typename... T1s, typename... Ts > + struct type_list_concat< type_list< T0s... >, type_list< T1s... >, Ts... > + : type_list_concat< type_list< T0s..., T1s... >, Ts... > + {}; + + template< typename... Ts > + using type_list_concat_t = typename type_list_concat< Ts... >::type; + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/pegtl/pegtl/utf8.hpp b/pxr/base/pegtl/pegtl/utf8.hpp new file mode 100644 index 0000000000..e7dc3d81b1 --- /dev/null +++ b/pxr/base/pegtl/pegtl/utf8.hpp @@ -0,0 +1,28 @@ +// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_UTF8_HPP +#define PXR_PEGTL_UTF8_HPP + +#include "config.hpp" + +#include "internal/peek_utf8.hpp" +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace PXR_PEGTL_NAMESPACE::utf8 +{ + // clang-format off + struct any : internal::any< internal::peek_utf8 > {}; + struct bom : internal::one< internal::result_on_found::success, internal::peek_utf8, 0xfeff > {}; // Lemon curry? + template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf8, Cs... > {}; + template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf8, Lo, Hi > {}; + template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf8, Cs... > {}; + template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_utf8, Lo, Hi > {}; + template< char32_t... Cs > struct ranges : internal::ranges< internal::peek_utf8, Cs... > {}; + template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_utf8, Cs >... > {}; + // clang-format on + +} // namespace PXR_PEGTL_NAMESPACE::utf8 + +#endif diff --git a/pxr/base/pegtl/pegtl/version.hpp b/pxr/base/pegtl/pegtl/version.hpp new file mode 100644 index 0000000000..a6ae6aee09 --- /dev/null +++ b/pxr/base/pegtl/pegtl/version.hpp @@ -0,0 +1,13 @@ +// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_VERSION_HPP +#define PXR_PEGTL_VERSION_HPP + +#define PXR_PEGTL_VERSION "3.2.7" + +#define PXR_PEGTL_VERSION_MAJOR 3 +#define PXR_PEGTL_VERSION_MINOR 2 +#define PXR_PEGTL_VERSION_PATCH 7 + +#endif diff --git a/pxr/base/pegtl/pegtl/visit.hpp b/pxr/base/pegtl/pegtl/visit.hpp new file mode 100644 index 0000000000..dc0a6f61e8 --- /dev/null +++ b/pxr/base/pegtl/pegtl/visit.hpp @@ -0,0 +1,80 @@ +// Copyright (c) 2020-2022 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef PXR_PEGTL_VISIT_HPP +#define PXR_PEGTL_VISIT_HPP + +#include + +#include "config.hpp" +#include "type_list.hpp" + +namespace PXR_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename Type, typename... Types > + inline constexpr bool contains_v = ( std::is_same_v< Type, Types > || ... ); + + template< typename Type, typename... Types > + struct contains + : std::bool_constant< contains_v< Type, Types... > > + {}; + + template< typename Type, typename... Types > + struct contains< Type, type_list< Types... > > + : contains< Type, Types... > + {}; + + template< typename Rules, typename Todo, typename Done > + struct filter + { + using type = Todo; + }; + + template< typename Rule, typename... Rules, typename... Todo, typename... Done > + struct filter< type_list< Rule, Rules... >, type_list< Todo... >, type_list< Done... > > + : filter< type_list< Rules... >, std::conditional_t< contains_v< Rule, Todo..., Done... >, type_list< Todo... >, type_list< Rule, Todo... > >, type_list< Done... > > + {}; + + template< typename Rules, typename Todo, typename Done > + using filter_t = typename filter< Rules, Todo, Done >::type; + + template< typename Done, typename... Rules > + struct visit_list + { + using NextDone = type_list_concat_t< type_list< Rules... >, Done >; + using NextSubs = type_list_concat_t< typename Rules::subs_t... >; + using NextTodo = filter_t< NextSubs, empty_list, NextDone >; + + using type = typename std::conditional_t< std::is_same_v< NextTodo, empty_list >, type_list_concat< NextDone >, visit_list< NextDone, NextTodo > >::type; + }; + + template< typename Done, typename... Rules > + struct visit_list< Done, type_list< Rules... > > + : visit_list< Done, Rules... > + {}; + + template< template< typename... > class Func, typename... Args, typename... Rules > + void visit( type_list< Rules... > /*unused*/, Args&&... args ) + { + ( Func< Rules >::visit( args... ), ... ); + } + + } // namespace internal + + template< typename Grammar > + using rule_list_t = typename internal::visit_list< empty_list, Grammar >::type; + + template< typename Grammar, typename Rule > + inline constexpr bool contains_v = internal::contains< Rule, rule_list_t< Grammar > >::value; + + template< typename Rule, template< typename... > class Func, typename... Args > + void visit( Args&&... args ) + { + internal::visit< Func >( rule_list_t< Rule >(), args... ); + } + +} // namespace PXR_PEGTL_NAMESPACE + +#endif diff --git a/pxr/base/tf/CMakeLists.txt b/pxr/base/tf/CMakeLists.txt index 88176f68f0..ab1b4a109b 100644 --- a/pxr/base/tf/CMakeLists.txt +++ b/pxr/base/tf/CMakeLists.txt @@ -237,7 +237,6 @@ pxr_library(tf instantiateType.h meta.h pxrCLI11/CLI11.h - pxrPEGTL/pegtl.h pxrTslRobinMap/robin_growth_policy.h pxrTslRobinMap/robin_hash.h pxrTslRobinMap/robin_map.h diff --git a/pxr/base/tf/pxrPEGTL/README.md b/pxr/base/tf/pxrPEGTL/README.md deleted file mode 100644 index 30f37bc4b9..0000000000 --- a/pxr/base/tf/pxrPEGTL/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# The Art of C++ : PEGTL (Parsing Expression Grammar Template Library) - -[PEGTL](https://github.com/taocpp/PEGTL) is a library for creating -parsers according to a Parsing Expression Grammar. - -## Version - -v2.8.3 ( 64af78c6a7959cd5753ad165ec9f65591aa96f2d ) - -## Setup - -Refer to the [Installing and Using](https://github.com/taocpp/PEGTL/blob/2.x/doc/Installing-and-Using.md) -documentation for instructions on how to generate this header. - -1. Follow the instructions in the "Single Header Version" section to generate - a single pegtl.hpp file. - -2. Rename the pegtl.hpp file to pegtl.h - -3. Apply the pxr-pegtl.patch file to apply Pixar-specific patches. diff --git a/pxr/base/tf/pxrPEGTL/pegtl.h b/pxr/base/tf/pxrPEGTL/pegtl.h deleted file mode 100644 index 300466e059..0000000000 --- a/pxr/base/tf/pxrPEGTL/pegtl.h +++ /dev/null @@ -1,12483 +0,0 @@ -/* - -Welcome to the Parsing Expression Grammar Template Library (PEGTL). -See https://github.com/taocpp/PEGTL/ for more information, documentation, etc. - -The library is licensed as follows: - -The MIT License (MIT) - -Copyright (c) 2007-2020 Dr. Colin Hirsch and Daniel Frey - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -// PIXAR: -// This header is not meant to be included in a .h file, to guard against -// conflicts if a program includes their own pegtl header and then transitively -// includes this header. -#ifdef PXR_PEGTL_H -#error This file should only be included once in any given source (.cpp) file. -#endif -#define PXR_PEGTL_H - -// PIXAR: -// Define TAO_PEGTL_NAMESPACE based on internal namespace to isolate -// it from other versions of USD/PEGTL in client code. -// -// This would typically be done by wrapping the contents of this header in -// PXR_NAMESPACE_OPEN_SCOPE and PXR_NAMESPACE_CLOSE_SCOPE, but that would -// require more invasive changes to this header since there are STL header -// includes scattered throughout. -#include "pxr/pxr.h" - -#if PXR_USE_NAMESPACES -#define TAO_PEGTL_NAMESPACE PXR_INTERNAL_NS ## _pegtl -#else -#define TAO_PEGTL_NAMESPACE pxr_pegtl -#endif - -#line 1 "amalgamated.hpp" -#line 1 "" -#line 1 "" -#line 1 "amalgamated.hpp" -#line 1 "tao/pegtl.hpp" - -#line 1 "tao/pegtl.hpp" - - - -#ifndef TAO_PEGTL_HPP -#define TAO_PEGTL_HPP - -#line 1 "tao/pegtl/config.hpp" - -#line 1 "tao/pegtl/config.hpp" - - - -#ifndef TAO_PEGTL_CONFIG_HPP -#define TAO_PEGTL_CONFIG_HPP - -// Compatibility, remove with 3.0.0 -#ifdef TAOCPP_PEGTL_NAMESPACE -#define TAO_PEGTL_NAMESPACE TAOCPP_PEGTL_NAMESPACE -#endif - -#ifndef TAO_PEGTL_NAMESPACE -#define TAO_PEGTL_NAMESPACE pegtl -#endif - -// Enable some improvements to the readability of -// demangled type names under some circumstances. -// #define TAO_PEGTL_PRETTY_DEMANGLE - -#endif -#line 8 "tao/pegtl.hpp" -#line 1 "tao/pegtl/version.hpp" - -#line 1 "tao/pegtl/version.hpp" - - - -#ifndef TAO_PEGTL_VERSION_HPP -#define TAO_PEGTL_VERSION_HPP - -#define TAO_PEGTL_VERSION "2.8.3" - -#define TAO_PEGTL_VERSION_MAJOR 2 -#define TAO_PEGTL_VERSION_MINOR 8 -#define TAO_PEGTL_VERSION_PATCH 3 - -// Compatibility, remove with 3.0.0 -#define TAOCPP_PEGTL_VERSION TAO_PEGTL_VERSION -#define TAOCPP_PEGTL_VERSION_MAJOR TAO_PEGTL_VERSION_MAJOR -#define TAOCPP_PEGTL_VERSION_MINOR TAO_PEGTL_VERSION_MINOR -#define TAOCPP_PEGTL_VERSION_PATCH TAO_PEGTL_VERSION_PATCH - -#endif -#line 9 "tao/pegtl.hpp" - -#line 1 "tao/pegtl/parse.hpp" - -#line 1 "tao/pegtl/parse.hpp" - - - -#ifndef TAO_PEGTL_PARSE_HPP -#define TAO_PEGTL_PARSE_HPP - -#include - -#line 1 "tao/pegtl/apply_mode.hpp" - -#line 1 "tao/pegtl/apply_mode.hpp" - - - -#ifndef TAO_PEGTL_APPLY_MODE_HPP -#define TAO_PEGTL_APPLY_MODE_HPP - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - enum class apply_mode : bool - { - action = true, - nothing = false, - - // Compatibility, remove with 3.0.0 - ACTION = action, - NOTHING = nothing - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/parse.hpp" - -#line 1 "tao/pegtl/normal.hpp" - -#line 1 "tao/pegtl/normal.hpp" - - - -#ifndef TAO_PEGTL_NORMAL_HPP -#define TAO_PEGTL_NORMAL_HPP - -#include -#include - - - -#line 1 "tao/pegtl/match.hpp" - -#line 1 "tao/pegtl/match.hpp" - - - -#ifndef TAO_PEGTL_MATCH_HPP -#define TAO_PEGTL_MATCH_HPP - -#include - - - -#line 1 "tao/pegtl/nothing.hpp" - -#line 1 "tao/pegtl/nothing.hpp" - - - -#ifndef TAO_PEGTL_NOTHING_HPP -#define TAO_PEGTL_NOTHING_HPP - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< typename Rule > - struct nothing - { - }; - - using maybe_nothing = nothing< void >; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/match.hpp" -#line 1 "tao/pegtl/require_apply.hpp" - -#line 1 "tao/pegtl/require_apply.hpp" - - - -#ifndef TAO_PEGTL_REQUIRE_APPLY_HPP -#define TAO_PEGTL_REQUIRE_APPLY_HPP - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - struct require_apply - {}; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 13 "tao/pegtl/match.hpp" -#line 1 "tao/pegtl/require_apply0.hpp" - -#line 1 "tao/pegtl/require_apply0.hpp" - - - -#ifndef TAO_PEGTL_REQUIRE_APPLY0_HPP -#define TAO_PEGTL_REQUIRE_APPLY0_HPP - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - struct require_apply0 - {}; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 14 "tao/pegtl/match.hpp" -#line 1 "tao/pegtl/rewind_mode.hpp" - -#line 1 "tao/pegtl/rewind_mode.hpp" - - - -#ifndef TAO_PEGTL_REWIND_MODE_HPP -#define TAO_PEGTL_REWIND_MODE_HPP - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - enum class rewind_mode : char - { - active, - required, - dontcare, - - // Compatibility, remove with 3.0.0 - ACTIVE = active, - REQUIRED = required, - DONTCARE = dontcare - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 15 "tao/pegtl/match.hpp" - -#line 1 "tao/pegtl/internal/dusel_mode.hpp" - -#line 1 "tao/pegtl/internal/dusel_mode.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_DUSEL_MODE_HPP -#define TAO_PEGTL_INTERNAL_DUSEL_MODE_HPP - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - enum class dusel_mode : char - { - nothing = 0, - control = 1, - control_and_apply_void = 2, - control_and_apply_bool = 3, - control_and_apply0_void = 4, - control_and_apply0_bool = 5, - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 17 "tao/pegtl/match.hpp" -#line 1 "tao/pegtl/internal/duseltronik.hpp" - -#line 1 "tao/pegtl/internal/duseltronik.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_DUSELTRONIK_HPP -#define TAO_PEGTL_INTERNAL_DUSELTRONIK_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - dusel_mode = dusel_mode::nothing > - struct duseltronik; - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control > - struct duseltronik< Rule, A, M, Action, Control, dusel_mode::nothing > - { - template< typename Input, typename... States > - static auto match( Input& in, States&&... st ) - -> decltype( Rule::template match< A, M, Action, Control >( in, st... ), true ) - { - return Rule::template match< A, M, Action, Control >( in, st... ); - } - - // NOTE: The additional "int = 0" is a work-around for missing expression SFINAE in VS2015. - - template< typename Input, typename... States, int = 0 > - static auto match( Input& in, States&&... /*unused*/ ) - -> decltype( Rule::match( in ), true ) - { - return Rule::match( in ); - } - }; - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control > - struct duseltronik< Rule, A, M, Action, Control, dusel_mode::control > - { - template< typename Input, typename... States > - static bool match( Input& in, States&&... st ) - { - Control< Rule >::start( static_cast< const Input& >( in ), st... ); - - if( duseltronik< Rule, A, M, Action, Control, dusel_mode::nothing >::match( in, st... ) ) { - Control< Rule >::success( static_cast< const Input& >( in ), st... ); - return true; - } - Control< Rule >::failure( static_cast< const Input& >( in ), st... ); - return false; - } - }; - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control > - struct duseltronik< Rule, A, M, Action, Control, dusel_mode::control_and_apply_void > - { - template< typename Input, typename... States > - static bool match( Input& in, States&&... st ) - { - auto m = in.template mark< rewind_mode::required >(); - - Control< Rule >::start( static_cast< const Input& >( in ), st... ); - - if( duseltronik< Rule, A, rewind_mode::active, Action, Control, dusel_mode::nothing >::match( in, st... ) ) { - Control< Rule >::template apply< Action >( m.iterator(), static_cast< const Input& >( in ), st... ); - Control< Rule >::success( static_cast< const Input& >( in ), st... ); - return m( true ); - } - Control< Rule >::failure( static_cast< const Input& >( in ), st... ); - return false; - } - }; - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control > - struct duseltronik< Rule, A, M, Action, Control, dusel_mode::control_and_apply_bool > - { - template< typename Input, typename... States > - static bool match( Input& in, States&&... st ) - { - auto m = in.template mark< rewind_mode::required >(); - - Control< Rule >::start( static_cast< const Input& >( in ), st... ); - - if( duseltronik< Rule, A, rewind_mode::active, Action, Control, dusel_mode::nothing >::match( in, st... ) ) { - if( Control< Rule >::template apply< Action >( m.iterator(), static_cast< const Input& >( in ), st... ) ) { - Control< Rule >::success( static_cast< const Input& >( in ), st... ); - return m( true ); - } - } - Control< Rule >::failure( static_cast< const Input& >( in ), st... ); - return false; - } - }; - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control > - struct duseltronik< Rule, A, M, Action, Control, dusel_mode::control_and_apply0_void > - { - template< typename Input, typename... States > - static bool match( Input& in, States&&... st ) - { - Control< Rule >::start( static_cast< const Input& >( in ), st... ); - - if( duseltronik< Rule, A, M, Action, Control, dusel_mode::nothing >::match( in, st... ) ) { - Control< Rule >::template apply0< Action >( static_cast< const Input& >( in ), st... ); - Control< Rule >::success( static_cast< const Input& >( in ), st... ); - return true; - } - Control< Rule >::failure( static_cast< const Input& >( in ), st... ); - return false; - } - }; - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control > - struct duseltronik< Rule, A, M, Action, Control, dusel_mode::control_and_apply0_bool > - { - template< typename Input, typename... States > - static bool match( Input& in, States&&... st ) - { - auto m = in.template mark< rewind_mode::required >(); - - Control< Rule >::start( static_cast< const Input& >( in ), st... ); - - if( duseltronik< Rule, A, rewind_mode::active, Action, Control, dusel_mode::nothing >::match( in, st... ) ) { - if( Control< Rule >::template apply0< Action >( static_cast< const Input& >( in ), st... ) ) { - Control< Rule >::success( static_cast< const Input& >( in ), st... ); - return m( true ); - } - } - Control< Rule >::failure( static_cast< const Input& >( in ), st... ); - return false; - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 18 "tao/pegtl/match.hpp" -#line 1 "tao/pegtl/internal/has_apply.hpp" - -#line 1 "tao/pegtl/internal/has_apply.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_HAS_APPLY_HPP -#define TAO_PEGTL_INTERNAL_HAS_APPLY_HPP - -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename, typename, template< typename... > class, typename... > - struct has_apply - : std::false_type - {}; - - template< typename C, template< typename... > class Action, typename... S > - struct has_apply< C, decltype( C::template apply< Action >( std::declval< S >()... ) ), Action, S... > - : std::true_type - {}; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 19 "tao/pegtl/match.hpp" -#line 1 "tao/pegtl/internal/has_apply0.hpp" - -#line 1 "tao/pegtl/internal/has_apply0.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_HAS_APPLY0_HPP -#define TAO_PEGTL_INTERNAL_HAS_APPLY0_HPP - -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename, typename, template< typename... > class, typename... > - struct has_apply0 - : std::false_type - {}; - - template< typename C, template< typename... > class Action, typename... S > - struct has_apply0< C, decltype( C::template apply0< Action >( std::declval< S >()... ) ), Action, S... > - : std::true_type - {}; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 20 "tao/pegtl/match.hpp" -#line 1 "tao/pegtl/internal/if_missing.hpp" - -#line 1 "tao/pegtl/internal/if_missing.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_IF_MISSING_HPP -#define TAO_PEGTL_INTERNAL_IF_MISSING_HPP - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< bool > - struct if_missing; - - template<> - struct if_missing< true > - { - template< typename Control, - template< typename... > - class Action, - typename Input, - typename... States > - static void apply( Input& in, States&&... st ) - { - auto m = in.template mark< rewind_mode::required >(); - Control::template apply< Action >( m.iterator(), in, st... ); - } - - template< typename Control, - template< typename... > - class Action, - typename Input, - typename... States > - static void apply0( Input& in, States&&... st ) - { - Control::template apply0< Action >( in, st... ); - } - }; - - template<> - struct if_missing< false > - { - template< typename Control, - template< typename... > - class Action, - typename Input, - typename... States > - static void apply( Input& /*unused*/, States&&... /*unused*/ ) - { - } - - template< typename Control, - template< typename... > - class Action, - typename Input, - typename... States > - static void apply0( Input& /*unused*/, States&&... /*unused*/ ) - { - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 21 "tao/pegtl/match.hpp" -#line 1 "tao/pegtl/internal/skip_control.hpp" - -#line 1 "tao/pegtl/internal/skip_control.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_SKIP_CONTROL_HPP -#define TAO_PEGTL_INTERNAL_SKIP_CONTROL_HPP - -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - // This class is a simple tagging mechanism. - // By default, skip_control< Rule >::value - // is 'false'. Each internal (!) rule that should - // be hidden from the control and action class' - // callbacks simply specializes skip_control<> - // to return 'true' for the above expression. - - template< typename Rule > - struct skip_control : std::false_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 22 "tao/pegtl/match.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - bool match( Input& in, States&&... st ) - { - constexpr bool enable_control = !internal::skip_control< Rule >::value; - constexpr bool enable_action = enable_control && ( A == apply_mode::action ); - - using iterator_t = typename Input::iterator_t; - constexpr bool has_apply_void = enable_action && internal::has_apply< Control< Rule >, void, Action, const iterator_t&, const Input&, States... >::value; - constexpr bool has_apply_bool = enable_action && internal::has_apply< Control< Rule >, bool, Action, const iterator_t&, const Input&, States... >::value; - constexpr bool has_apply = has_apply_void || has_apply_bool; - - constexpr bool has_apply0_void = enable_action && internal::has_apply0< Control< Rule >, void, Action, const Input&, States... >::value; - constexpr bool has_apply0_bool = enable_action && internal::has_apply0< Control< Rule >, bool, Action, const Input&, States... >::value; - constexpr bool has_apply0 = has_apply0_void || has_apply0_bool; - - static_assert( !( has_apply && has_apply0 ), "both apply() and apply0() defined" ); - - constexpr bool is_nothing = std::is_base_of< nothing< Rule >, Action< Rule > >::value; - static_assert( !( has_apply && is_nothing ), "unexpected apply() defined" ); - static_assert( !( has_apply0 && is_nothing ), "unexpected apply0() defined" ); - - internal::if_missing< !has_apply && std::is_base_of< require_apply, Action< Rule > >::value >::template apply< Control< Rule >, Action >( in, st... ); - internal::if_missing< !has_apply0 && std::is_base_of< require_apply0, Action< Rule > >::value >::template apply0< Control< Rule >, Action >( in, st... ); - - constexpr bool validate_nothing = std::is_base_of< maybe_nothing, Action< void > >::value; - constexpr bool is_maybe_nothing = std::is_base_of< maybe_nothing, Action< Rule > >::value; - static_assert( !enable_action || !validate_nothing || is_nothing || is_maybe_nothing || has_apply || has_apply0, "either apply() or apply0() must be defined" ); - - constexpr auto mode = static_cast< internal::dusel_mode >( enable_control + has_apply_void + 2 * has_apply_bool + 3 * has_apply0_void + 4 * has_apply0_bool ); - return internal::duseltronik< Rule, A, M, Action, Control, mode >::match( in, st... ); - } - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 13 "tao/pegtl/normal.hpp" -#line 1 "tao/pegtl/parse_error.hpp" - -#line 1 "tao/pegtl/parse_error.hpp" - - - -#ifndef TAO_PEGTL_PARSE_ERROR_HPP -#define TAO_PEGTL_PARSE_ERROR_HPP - -#include -#include - - -#line 1 "tao/pegtl/position.hpp" - -#line 1 "tao/pegtl/position.hpp" - - - -#ifndef TAO_PEGTL_POSITION_HPP -#define TAO_PEGTL_POSITION_HPP - -#include -#include -#include -#include -#include - - - -#line 1 "tao/pegtl/internal/iterator.hpp" - -#line 1 "tao/pegtl/internal/iterator.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ITERATOR_HPP -#define TAO_PEGTL_INTERNAL_ITERATOR_HPP - -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct iterator - { - iterator() noexcept = default; - - explicit iterator( const char* in_data ) noexcept - : data( in_data ) - { - } - - iterator( const char* in_data, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_byte_in_line ) noexcept - : data( in_data ), - byte( in_byte ), - line( in_line ), - byte_in_line( in_byte_in_line ) - { - } - - iterator( const iterator& ) = default; - iterator( iterator&& ) = default; - - ~iterator() = default; - - iterator& operator=( const iterator& ) = default; - iterator& operator=( iterator&& ) = default; - - void reset() noexcept - { - *this = iterator(); - } - - const char* data = nullptr; - - std::size_t byte = 0; - std::size_t line = 1; - std::size_t byte_in_line = 0; - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 16 "tao/pegtl/position.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - struct position - { - template< typename T > - position( const internal::iterator& in_iter, T&& in_source ) - : byte( in_iter.byte ), - line( in_iter.line ), - byte_in_line( in_iter.byte_in_line ), - source( std::forward< T >( in_source ) ) - { - } - - std::size_t byte; - std::size_t line; - std::size_t byte_in_line; - std::string source; - }; - - inline std::ostream& operator<<( std::ostream& o, const position& p ) - { - return o << p.source << ':' << p.line << ':' << p.byte_in_line << '(' << p.byte << ')'; - } - - inline std::string to_string( const position& p ) - { - std::ostringstream o; - o << p; - return o.str(); - } - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/parse_error.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - struct parse_error - : public std::runtime_error - { - parse_error( const std::string& msg, std::vector< position >&& in_positions ) - : std::runtime_error( msg ), - positions( std::move( in_positions ) ) - { - } - - template< typename Input > - parse_error( const std::string& msg, const Input& in ) - : parse_error( msg, in.position() ) - { - } - - parse_error( const std::string& msg, const position& pos ) - : std::runtime_error( to_string( pos ) + ": " + msg ), - positions( 1, pos ) - { - } - - parse_error( const std::string& msg, position&& pos ) - : std::runtime_error( to_string( pos ) + ": " + msg ) - { - positions.emplace_back( std::move( pos ) ); - } - - std::vector< position > positions; - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 14 "tao/pegtl/normal.hpp" - - -#line 1 "tao/pegtl/internal/demangle.hpp" - -#line 1 "tao/pegtl/internal/demangle.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_DEMANGLE_HPP -#define TAO_PEGTL_INTERNAL_DEMANGLE_HPP - -#include -#include - - - -#if defined( __clang__ ) -#if __has_feature( cxx_rtti ) -#define TAO_PEGTL_RTTI_ENABLED -#endif -#elif defined( __GNUC__ ) -#if defined( __GXX_RTTI ) -#define TAO_PEGTL_RTTI_ENABLED -#endif -#elif defined( _MSC_VER ) -#if defined( _CPPRTTI ) -#define TAO_PEGTL_RTTI_ENABLED -#endif -#else -#define TAO_PEGTL_RTTI_ENABLED -#endif - -#if !defined( TAO_PEGTL_RTTI_ENABLED ) -#include -#include -#endif - -#if defined( TAO_PEGTL_RTTI_ENABLED ) -#if defined( __GLIBCXX__ ) -#define TAO_PEGTL_USE_CXXABI_DEMANGLE -#elif defined( __has_include ) -#if __has_include( ) -#define TAO_PEGTL_USE_CXXABI_DEMANGLE -#endif -#endif -#endif - -#if defined( TAO_PEGTL_USE_CXXABI_DEMANGLE ) -#line 1 "tao/pegtl/internal/demangle_cxxabi.hpp" - -#line 1 "tao/pegtl/internal/demangle_cxxabi.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_DEMANGLE_CXXABI_HPP -#define TAO_PEGTL_INTERNAL_DEMANGLE_CXXABI_HPP - -#include -#include -#include -#include - - - -#line 1 "tao/pegtl/internal/demangle_sanitise.hpp" - -#line 1 "tao/pegtl/internal/demangle_sanitise.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_DEMANGLE_SANITISE_HPP -#define TAO_PEGTL_INTERNAL_DEMANGLE_SANITISE_HPP - -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - inline void demangle_sanitise_chars( std::string& s ) - { - std::string::size_type p; - while( ( p = s.find( "(char)" ) ) != std::string::npos ) { - int c = 0; - std::string::size_type q; - for( q = p + 6; ( q < s.size() ) && ( s[ q ] >= '0' ) && ( s[ q ] <= '9' ); ++q ) { - c *= 10; - c += s[ q ] - '0'; - } - if( c == '\'' ) { - s.replace( p, q - p, "'\\''" ); - } - else if( c == '\\' ) { - s.replace( p, q - p, "'\\\\'" ); - } - else if( ( c < 32 ) || ( c > 126 ) ) { - s.replace( p, 6, std::string() ); - } - else { - s.replace( p, q - p, std::string( 1, '\'' ) + char( c ) + '\'' ); - } - } - } - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 15 "tao/pegtl/internal/demangle_cxxabi.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - inline std::string demangle( const char* symbol ) - { - const std::unique_ptr< char, decltype( &std::free ) > demangled( abi::__cxa_demangle( symbol, nullptr, nullptr, nullptr ), &std::free ); - if( !demangled ) { - return symbol; - } - std::string result( demangled.get() ); -#ifdef TAO_PEGTL_PRETTY_DEMANGLE - demangle_sanitise_chars( result ); // LCOV_EXCL_LINE -#endif - return result; - } - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 45 "tao/pegtl/internal/demangle.hpp" -#undef TAO_PEGTL_USE_CXXABI_DEMANGLE -#else -#line 1 "tao/pegtl/internal/demangle_nop.hpp" - -#line 1 "tao/pegtl/internal/demangle_nop.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_DEMANGLE_NOP_HPP -#define TAO_PEGTL_INTERNAL_DEMANGLE_NOP_HPP - -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - inline std::string demangle( const char* symbol ) - { - return symbol; - } - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 48 "tao/pegtl/internal/demangle.hpp" -#endif - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename T > - std::string demangle() - { -#if defined( TAO_PEGTL_RTTI_ENABLED ) - return demangle( typeid( T ).name() ); -#else - const char* start = nullptr; - const char* stop = nullptr; -#if defined( __clang__ ) || defined( __GNUC__ ) - start = std::strchr( __PRETTY_FUNCTION__, '=' ) + 2; - stop = std::strrchr( start, ';' ); -#elif defined( _MSC_VER ) - start = std::strstr( __FUNCSIG__, "demangle<" ) + ( sizeof( "demangle<" ) - 1 ); - stop = std::strrchr( start, '>' ); -#else - static_assert( false, "expected to use rtti with this compiler" ); -#endif - assert( start != nullptr ); - assert( stop != nullptr ); - return { start, std::size_t( stop - start ) }; -#endif - } - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 17 "tao/pegtl/normal.hpp" -#line 1 "tao/pegtl/internal/has_match.hpp" - -#line 1 "tao/pegtl/internal/has_match.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_HAS_MATCH_HPP -#define TAO_PEGTL_INTERNAL_HAS_MATCH_HPP - -#include -#include - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename, - typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - struct has_match - : std::false_type - {}; - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - struct has_match< decltype( Action< Rule >::template match< Rule, A, M, Action, Control >( std::declval< Input& >(), std::declval< States&& >()... ), void() ), Rule, A, M, Action, Control, Input, States... > - : std::true_type - {}; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 18 "tao/pegtl/normal.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< typename Rule > - struct normal - { - template< typename Input, typename... States > - static void start( const Input& /*unused*/, States&&... /*unused*/ ) noexcept - { - } - - template< typename Input, typename... States > - static void success( const Input& /*unused*/, States&&... /*unused*/ ) noexcept - { - } - - template< typename Input, typename... States > - static void failure( const Input& /*unused*/, States&&... /*unused*/ ) noexcept - { - } - - template< typename Input, typename... States > - static void raise( const Input& in, States&&... /*unused*/ ) - { - throw parse_error( "parse error matching " + internal::demangle< Rule >(), in ); - } - - template< template< typename... > class Action, typename Input, typename... States > - static auto apply0( const Input& /*unused*/, States&&... st ) - -> decltype( Action< Rule >::apply0( st... ) ) - { - return Action< Rule >::apply0( st... ); - } - - template< template< typename... > class Action, typename Iterator, typename Input, typename... States > - static auto apply( const Iterator& begin, const Input& in, States&&... st ) - -> decltype( Action< Rule >::apply( std::declval< typename Input::action_t >(), st... ) ) - { - const typename Input::action_t action_input( begin, in ); - return Action< Rule >::apply( action_input, st... ); - } - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static auto match( Input& in, States&&... st ) - -> typename std::enable_if< internal::has_match< void, Rule, A, M, Action, Control, Input, States... >::value, bool >::type - { - return Action< Rule >::template match< Rule, A, M, Action, Control >( in, st... ); - } - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States, - int = 1 > - static auto match( Input& in, States&&... st ) - -> typename std::enable_if< !internal::has_match< void, Rule, A, M, Action, Control, Input, States... >::value, bool >::type - { - return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/parse.hpp" - - - - -#line 1 "tao/pegtl/internal/action_input.hpp" - -#line 1 "tao/pegtl/internal/action_input.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ACTION_INPUT_HPP -#define TAO_PEGTL_INTERNAL_ACTION_INPUT_HPP - -#include -#include -#include - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - inline const char* begin_c_ptr( const char* p ) noexcept - { - return p; - } - - inline const char* begin_c_ptr( const iterator& it ) noexcept - { - return it.data; - } - - template< typename Input > - class action_input - { - public: - using input_t = Input; - using iterator_t = typename Input::iterator_t; - - action_input( const iterator_t& in_begin, const Input& in_input ) noexcept - : m_begin( in_begin ), - m_input( in_input ) - { - } - - action_input( const action_input& ) = delete; - action_input( action_input&& ) = delete; - - ~action_input() = default; - - action_input& operator=( const action_input& ) = delete; - action_input& operator=( action_input&& ) = delete; - - const iterator_t& iterator() const noexcept - { - return m_begin; - } - - const Input& input() const noexcept - { - return m_input; - } - - const char* begin() const noexcept - { - return begin_c_ptr( iterator() ); - } - - const char* end() const noexcept - { - return input().current(); - } - - bool empty() const noexcept - { - return begin() == end(); - } - - std::size_t size() const noexcept - { - return std::size_t( end() - begin() ); - } - - std::string string() const - { - return std::string( begin(), end() ); - } - - char peek_char( const std::size_t offset = 0 ) const noexcept - { - return begin()[ offset ]; - } - - std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept - { - return static_cast< std::uint8_t >( peek_char( offset ) ); - } - - // Compatibility, remove with 3.0.0 - std::uint8_t peek_byte( const std::size_t offset = 0 ) const noexcept - { - return static_cast< std::uint8_t >( peek_char( offset ) ); - } - - TAO_PEGTL_NAMESPACE::position position() const - { - return input().position( iterator() ); // NOTE: Not efficient with lazy inputs. - } - - protected: - const iterator_t m_begin; - const Input& m_input; - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 17 "tao/pegtl/parse.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< typename Rule, - template< typename... > class Action = nothing, - template< typename... > class Control = normal, - apply_mode A = apply_mode::action, - rewind_mode M = rewind_mode::required, - typename Input, - typename... States > - bool parse( Input&& in, States&&... st ) - { - return Control< Rule >::template match< A, M, Action, Control >( in, st... ); - } - - template< typename Rule, - template< typename... > class Action = nothing, - template< typename... > class Control = normal, - apply_mode A = apply_mode::action, - rewind_mode M = rewind_mode::required, - typename Outer, - typename Input, - typename... States > - bool parse_nested( const Outer& oi, Input&& in, States&&... st ) - { - try { - return parse< Rule, Action, Control, A, M >( in, st... ); - } - catch( parse_error& e ) { - e.positions.push_back( oi.position() ); - throw; - } - } - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 11 "tao/pegtl.hpp" - -#line 1 "tao/pegtl/ascii.hpp" - -#line 1 "tao/pegtl/ascii.hpp" - - - -#ifndef TAO_PEGTL_ASCII_HPP -#define TAO_PEGTL_ASCII_HPP - - -#line 1 "tao/pegtl/eol.hpp" - -#line 1 "tao/pegtl/eol.hpp" - - - -#ifndef TAO_PEGTL_EOL_HPP -#define TAO_PEGTL_EOL_HPP - - - -#line 1 "tao/pegtl/internal/eol.hpp" - -#line 1 "tao/pegtl/internal/eol.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_EOL_HPP -#define TAO_PEGTL_INTERNAL_EOL_HPP - - - - - -#line 1 "tao/pegtl/internal/../analysis/generic.hpp" - -#line 1 "tao/pegtl/internal/../analysis/generic.hpp" - - - -#ifndef TAO_PEGTL_ANALYSIS_GENERIC_HPP -#define TAO_PEGTL_ANALYSIS_GENERIC_HPP - - - -#line 1 "tao/pegtl/internal/../analysis/grammar_info.hpp" - -#line 1 "tao/pegtl/internal/../analysis/grammar_info.hpp" - - - -#ifndef TAO_PEGTL_ANALYSIS_GRAMMAR_INFO_HPP -#define TAO_PEGTL_ANALYSIS_GRAMMAR_INFO_HPP - -#include -#include -#include - - - - -#line 1 "tao/pegtl/internal/../analysis/rule_info.hpp" - -#line 1 "tao/pegtl/internal/../analysis/rule_info.hpp" - - - -#ifndef TAO_PEGTL_ANALYSIS_RULE_INFO_HPP -#define TAO_PEGTL_ANALYSIS_RULE_INFO_HPP - -#include -#include - - - -#line 1 "tao/pegtl/internal/../analysis/rule_type.hpp" - -#line 1 "tao/pegtl/internal/../analysis/rule_type.hpp" - - - -#ifndef TAO_PEGTL_ANALYSIS_RULE_TYPE_HPP -#define TAO_PEGTL_ANALYSIS_RULE_TYPE_HPP - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace analysis - { - enum class rule_type : char - { - any, // Consumption-on-success is always true; assumes bounded repetition of conjunction of sub-rules. - opt, // Consumption-on-success not necessarily true; assumes bounded repetition of conjunction of sub-rules. - seq, // Consumption-on-success depends on consumption of (non-zero bounded repetition of) conjunction of sub-rules. - sor, // Consumption-on-success depends on consumption of (non-zero bounded repetition of) disjunction of sub-rules. - - // Compatibility, remove with 3.0.0 - ANY = any, - OPT = opt, - SEQ = seq, - SOR = sor - }; - - } // namespace analysis - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 13 "tao/pegtl/internal/../analysis/rule_info.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace analysis - { - struct rule_info - { - explicit rule_info( const rule_type in_type ) noexcept - : type( in_type ) - { - } - - rule_type type; - std::vector< std::string > rules; - }; - - } // namespace analysis - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 15 "tao/pegtl/internal/../analysis/grammar_info.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace analysis - { - struct grammar_info - { - using map_t = std::map< std::string, rule_info >; - map_t map; - - template< typename Name > - std::pair< map_t::iterator, bool > insert( const rule_type type ) - { - return map.insert( map_t::value_type( internal::demangle< Name >(), rule_info( type ) ) ); - } - }; - - } // namespace analysis - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/../analysis/generic.hpp" - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace analysis - { - template< rule_type Type, typename... Rules > - struct generic - { - template< typename Name > - static std::string insert( grammar_info& g ) - { - const auto r = g.insert< Name >( Type ); - if( r.second ) { -#ifdef __cpp_fold_expressions - ( r.first->second.rules.push_back( Rules::analyze_t::template insert< Rules >( g ) ), ... ); -#else - using swallow = bool[]; - (void)swallow{ ( r.first->second.rules.push_back( Rules::analyze_t::template insert< Rules >( g ) ), true )..., true }; -#endif - } - return r.first->first; - } - }; - - } // namespace analysis - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/internal/eol.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct eol - { - using analyze_t = analysis::generic< analysis::rule_type::any >; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( Input::eol_t::match( in ) ) ) - { - return Input::eol_t::match( in ).first; - } - }; - - template<> - struct skip_control< eol > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/eol.hpp" - -#line 1 "tao/pegtl/internal/cr_crlf_eol.hpp" - -#line 1 "tao/pegtl/internal/cr_crlf_eol.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_CR_CRLF_EOL_HPP -#define TAO_PEGTL_INTERNAL_CR_CRLF_EOL_HPP - - -#line 1 "tao/pegtl/internal/../eol_pair.hpp" - -#line 1 "tao/pegtl/internal/../eol_pair.hpp" - - - -#ifndef TAO_PEGTL_EOL_PAIR_HPP -#define TAO_PEGTL_EOL_PAIR_HPP - -#include -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - using eol_pair = std::pair< bool, std::size_t >; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 9 "tao/pegtl/internal/cr_crlf_eol.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct cr_crlf_eol - { - static constexpr int ch = '\r'; - - template< typename Input > - static eol_pair match( Input& in ) noexcept( noexcept( in.size( 2 ) ) ) - { - eol_pair p = { false, in.size( 2 ) }; - if( p.second ) { - if( in.peek_char() == '\r' ) { - in.bump_to_next_line( 1 + ( ( p.second > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) ); - p.first = true; - } - } - return p; - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/eol.hpp" -#line 1 "tao/pegtl/internal/cr_eol.hpp" - -#line 1 "tao/pegtl/internal/cr_eol.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_CR_EOL_HPP -#define TAO_PEGTL_INTERNAL_CR_EOL_HPP - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct cr_eol - { - static constexpr int ch = '\r'; - - template< typename Input > - static eol_pair match( Input& in ) noexcept( noexcept( in.size( 1 ) ) ) - { - eol_pair p = { false, in.size( 1 ) }; - if( p.second ) { - if( in.peek_char() == '\r' ) { - in.bump_to_next_line(); - p.first = true; - } - } - return p; - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 13 "tao/pegtl/eol.hpp" -#line 1 "tao/pegtl/internal/crlf_eol.hpp" - -#line 1 "tao/pegtl/internal/crlf_eol.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_CRLF_EOL_HPP -#define TAO_PEGTL_INTERNAL_CRLF_EOL_HPP - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct crlf_eol - { - static constexpr int ch = '\n'; - - template< typename Input > - static eol_pair match( Input& in ) noexcept( noexcept( in.size( 2 ) ) ) - { - eol_pair p = { false, in.size( 2 ) }; - if( p.second > 1 ) { - if( ( in.peek_char() == '\r' ) && ( in.peek_char( 1 ) == '\n' ) ) { - in.bump_to_next_line( 2 ); - p.first = true; - } - } - return p; - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 14 "tao/pegtl/eol.hpp" -#line 1 "tao/pegtl/internal/lf_crlf_eol.hpp" - -#line 1 "tao/pegtl/internal/lf_crlf_eol.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_LF_CRLF_EOL_HPP -#define TAO_PEGTL_INTERNAL_LF_CRLF_EOL_HPP - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct lf_crlf_eol - { - static constexpr int ch = '\n'; - - template< typename Input > - static eol_pair match( Input& in ) noexcept( noexcept( in.size( 2 ) ) ) - { - eol_pair p = { false, in.size( 2 ) }; - if( p.second ) { - const auto a = in.peek_char(); - if( a == '\n' ) { - in.bump_to_next_line(); - p.first = true; - } - else if( ( a == '\r' ) && ( p.second > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) { - in.bump_to_next_line( 2 ); - p.first = true; - } - } - return p; - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 15 "tao/pegtl/eol.hpp" -#line 1 "tao/pegtl/internal/lf_eol.hpp" - -#line 1 "tao/pegtl/internal/lf_eol.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_LF_EOL_HPP -#define TAO_PEGTL_INTERNAL_LF_EOL_HPP - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct lf_eol - { - static constexpr int ch = '\n'; - - template< typename Input > - static eol_pair match( Input& in ) noexcept( noexcept( in.size( 1 ) ) ) - { - eol_pair p = { false, in.size( 1 ) }; - if( p.second ) { - if( in.peek_char() == '\n' ) { - in.bump_to_next_line(); - p.first = true; - } - } - return p; - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 16 "tao/pegtl/eol.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - inline namespace ascii - { - // this is both a rule and a pseudo-namespace for eol::cr, ... - struct eol : internal::eol - { - // clang-format off - struct cr : internal::cr_eol {}; - struct cr_crlf : internal::cr_crlf_eol {}; - struct crlf : internal::crlf_eol {}; - struct lf : internal::lf_eol {}; - struct lf_crlf : internal::lf_crlf_eol {}; - // clang-format on - }; - - } // namespace ascii - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 9 "tao/pegtl/ascii.hpp" - -#line 1 "tao/pegtl/internal/always_false.hpp" - -#line 1 "tao/pegtl/internal/always_false.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ALWAYS_FALSE_HPP -#define TAO_PEGTL_INTERNAL_ALWAYS_FALSE_HPP - - - -#include - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename... > - struct always_false - : std::false_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 11 "tao/pegtl/ascii.hpp" -#line 1 "tao/pegtl/internal/result_on_found.hpp" - -#line 1 "tao/pegtl/internal/result_on_found.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_RESULT_ON_FOUND_HPP -#define TAO_PEGTL_INTERNAL_RESULT_ON_FOUND_HPP - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - enum class result_on_found : bool - { - success = true, - failure = false, - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/ascii.hpp" -#line 1 "tao/pegtl/internal/rules.hpp" - -#line 1 "tao/pegtl/internal/rules.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_RULES_HPP -#define TAO_PEGTL_INTERNAL_RULES_HPP - -#line 1 "tao/pegtl/internal/action.hpp" - -#line 1 "tao/pegtl/internal/action.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ACTION_HPP -#define TAO_PEGTL_INTERNAL_ACTION_HPP - - - -#line 1 "tao/pegtl/internal/seq.hpp" - -#line 1 "tao/pegtl/internal/seq.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_SEQ_HPP -#define TAO_PEGTL_INTERNAL_SEQ_HPP - - - - -#line 1 "tao/pegtl/internal/trivial.hpp" - -#line 1 "tao/pegtl/internal/trivial.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_TRIVIAL_HPP -#define TAO_PEGTL_INTERNAL_TRIVIAL_HPP - - - - - -#line 1 "tao/pegtl/internal/../analysis/counted.hpp" - -#line 1 "tao/pegtl/internal/../analysis/counted.hpp" - - - -#ifndef TAO_PEGTL_ANALYSIS_COUNTED_HPP -#define TAO_PEGTL_ANALYSIS_COUNTED_HPP - - - -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace analysis - { - template< rule_type Type, std::size_t Count, typename... Rules > - struct counted - : generic< ( Count != 0 ) ? Type : rule_type::opt, Rules... > - { - }; - - } // namespace analysis - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/internal/trivial.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< bool Result > - struct trivial - { - using analyze_t = analysis::counted< analysis::rule_type::any, unsigned( !Result ) >; - - template< typename Input > - static bool match( Input& /*unused*/ ) noexcept - { - return Result; - } - }; - - template< bool Result > - struct skip_control< trivial< Result > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 11 "tao/pegtl/internal/seq.hpp" - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename... Rules > - struct seq; - - template<> - struct seq<> - : trivial< true > - { - }; - - template< typename Rule > - struct seq< Rule > - { - using analyze_t = typename Rule::analyze_t; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return Control< Rule >::template match< A, M, Action, Control >( in, st... ); - } - }; - - template< typename... Rules > - struct seq - { - using analyze_t = analysis::generic< analysis::rule_type::seq, Rules... >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - auto m = in.template mark< M >(); - using m_t = decltype( m ); -#ifdef __cpp_fold_expressions - return m( ( Control< Rules >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) && ... ) ); -#else - bool result = true; - using swallow = bool[]; - (void)swallow{ result = result && Control< Rules >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... )... }; - return m( result ); -#endif - } - - }; // namespace internal - - template< typename... Rules > - struct skip_control< seq< Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/action.hpp" - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< template< typename... > class Action, typename... Rules > - struct action - : action< Action, seq< Rules... > > - { - }; - - template< template< typename... > class Action, typename Rule > - struct action< Action, Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::seq, Rule >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return Control< Rule >::template match< A, M, Action, Control >( in, st... ); - } - }; - - template< template< typename... > class Action, typename... Rules > - struct skip_control< action< Action, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 8 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/alnum.hpp" - -#line 1 "tao/pegtl/internal/alnum.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ALNUM_HPP -#define TAO_PEGTL_INTERNAL_ALNUM_HPP - - - -#line 1 "tao/pegtl/internal/peek_char.hpp" - -#line 1 "tao/pegtl/internal/peek_char.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PEEK_CHAR_HPP -#define TAO_PEGTL_INTERNAL_PEEK_CHAR_HPP - -#include - - - -#line 1 "tao/pegtl/internal/input_pair.hpp" - -#line 1 "tao/pegtl/internal/input_pair.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_INPUT_PAIR_HPP -#define TAO_PEGTL_INTERNAL_INPUT_PAIR_HPP - -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Data > - struct input_pair - { - Data data; - std::uint8_t size; - - using data_t = Data; - - explicit operator bool() const noexcept - { - return size > 0; - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/internal/peek_char.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct peek_char - { - using data_t = char; - using pair_t = input_pair< char >; - - template< typename Input > - static pair_t peek( Input& in ) noexcept( noexcept( in.empty() ) ) - { - if( in.empty() ) { - return { 0, 0 }; - } - return { in.peek_char(), 1 }; - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/alnum.hpp" -#line 1 "tao/pegtl/internal/ranges.hpp" - -#line 1 "tao/pegtl/internal/ranges.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_RANGES_HPP -#define TAO_PEGTL_INTERNAL_RANGES_HPP - - - -#line 1 "tao/pegtl/internal/bump_help.hpp" - -#line 1 "tao/pegtl/internal/bump_help.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_BUMP_HELP_HPP -#define TAO_PEGTL_INTERNAL_BUMP_HELP_HPP - -#include -#include - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< bool > - struct bump_impl; - - template<> - struct bump_impl< true > - { - template< typename Input > - static void bump( Input& in, const std::size_t count ) noexcept - { - in.bump( count ); - } - }; - - template<> - struct bump_impl< false > - { - template< typename Input > - static void bump( Input& in, const std::size_t count ) noexcept - { - in.bump_in_this_line( count ); - } - }; - - template< bool... > - struct bool_list - { - }; - - template< bool... Bs > - using bool_and = std::is_same< bool_list< Bs..., true >, bool_list< true, Bs... > >; - - template< result_on_found R, typename Input, typename Char, Char... Cs > - void bump_help( Input& in, const std::size_t count ) noexcept - { - bump_impl< bool_and< ( Cs != Input::eol_t::ch )... >::value != bool( R ) >::bump( in, count ); - } - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/ranges.hpp" -#line 1 "tao/pegtl/internal/range.hpp" - -#line 1 "tao/pegtl/internal/range.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_RANGE_HPP -#define TAO_PEGTL_INTERNAL_RANGE_HPP -#line 15 "tao/pegtl/internal/range.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< result_on_found R, typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > - struct range - { - static_assert( Lo <= Hi, "invalid range detected" ); - - using analyze_t = analysis::generic< analysis::rule_type::any >; - - template< int Eol > - struct can_match_eol - { - static constexpr bool value = ( ( ( Lo <= Eol ) && ( Eol <= Hi ) ) == bool( R ) ); - }; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( Peek::peek( in ) ) ) - { - if( const auto t = Peek::peek( in ) ) { - if( ( ( Lo <= t.data ) && ( t.data <= Hi ) ) == bool( R ) ) { - bump_impl< can_match_eol< Input::eol_t::ch >::value >::bump( in, t.size ); - return true; - } - } - return false; - } - }; - - template< result_on_found R, typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > - struct skip_control< range< R, Peek, Lo, Hi > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 11 "tao/pegtl/internal/ranges.hpp" - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< int Eol, typename Char, Char... Cs > - struct ranges_impl; - - template< int Eol, typename Char > - struct ranges_impl< Eol, Char > - { - static constexpr bool can_match_eol = false; - - static bool match( const Char /*unused*/ ) noexcept - { - return false; - } - }; - - template< int Eol, typename Char, Char Eq > - struct ranges_impl< Eol, Char, Eq > - { - static constexpr bool can_match_eol = ( Eq == Eol ); - - static bool match( const Char c ) noexcept - { - return c == Eq; - } - }; - - template< int Eol, typename Char, Char Lo, Char Hi, Char... Cs > - struct ranges_impl< Eol, Char, Lo, Hi, Cs... > - { - static_assert( Lo <= Hi, "invalid range detected" ); - - static constexpr bool can_match_eol = ( ( ( Lo <= Eol ) && ( Eol <= Hi ) ) || ranges_impl< Eol, Char, Cs... >::can_match_eol ); - - static bool match( const Char c ) noexcept - { - return ( ( Lo <= c ) && ( c <= Hi ) ) || ranges_impl< Eol, Char, Cs... >::match( c ); - } - }; - - template< typename Peek, typename Peek::data_t... Cs > - struct ranges - { - using analyze_t = analysis::generic< analysis::rule_type::any >; - - template< int Eol > - struct can_match_eol - { - static constexpr bool value = ranges_impl< Eol, typename Peek::data_t, Cs... >::can_match_eol; - }; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( Peek::peek( in ) ) ) - { - if( const auto t = Peek::peek( in ) ) { - if( ranges_impl< Input::eol_t::ch, typename Peek::data_t, Cs... >::match( t.data ) ) { - bump_impl< can_match_eol< Input::eol_t::ch >::value >::bump( in, t.size ); - return true; - } - } - return false; - } - }; - - template< typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > - struct ranges< Peek, Lo, Hi > - : range< result_on_found::success, Peek, Lo, Hi > - { - }; - - template< typename Peek, typename Peek::data_t... Cs > - struct skip_control< ranges< Peek, Cs... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 11 "tao/pegtl/internal/alnum.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - using alnum = ranges< peek_char, 'a', 'z', 'A', 'Z', '0', '9' >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 9 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/alpha.hpp" - -#line 1 "tao/pegtl/internal/alpha.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ALPHA_HPP -#define TAO_PEGTL_INTERNAL_ALPHA_HPP - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - using alpha = ranges< peek_char, 'a', 'z', 'A', 'Z' >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/any.hpp" - -#line 1 "tao/pegtl/internal/any.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ANY_HPP -#define TAO_PEGTL_INTERNAL_ANY_HPP -#line 14 "tao/pegtl/internal/any.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Peek > - struct any; - - template<> - struct any< peek_char > - { - using analyze_t = analysis::generic< analysis::rule_type::any >; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( in.empty() ) ) - { - if( !in.empty() ) { - in.bump(); - return true; - } - return false; - } - }; - - template< typename Peek > - struct any - { - using analyze_t = analysis::generic< analysis::rule_type::any >; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( Peek::peek( in ) ) ) - { - if( const auto t = Peek::peek( in ) ) { - in.bump( t.size ); - return true; - } - return false; - } - }; - - template< typename Peek > - struct skip_control< any< Peek > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 11 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/apply.hpp" - -#line 1 "tao/pegtl/internal/apply.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_APPLY_HPP -#define TAO_PEGTL_INTERNAL_APPLY_HPP - - - -#line 1 "tao/pegtl/internal/apply_single.hpp" - -#line 1 "tao/pegtl/internal/apply_single.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_APPLY_SINGLE_HPP -#define TAO_PEGTL_INTERNAL_APPLY_SINGLE_HPP - - - -#include - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Action > - struct apply_single - { - template< typename Input, typename... States > - static auto match( const Input& i2, States&&... st ) - -> typename std::enable_if< std::is_same< decltype( Action::apply( i2, st... ) ), void >::value, bool >::type - { - Action::apply( i2, st... ); - return true; - } - - template< typename Input, typename... States > - static auto match( const Input& i2, States&&... st ) - -> typename std::enable_if< std::is_same< decltype( Action::apply( i2, st... ) ), bool >::value, bool >::type - { - return Action::apply( i2, st... ); - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/apply.hpp" - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< apply_mode A, typename... Actions > - struct apply_impl; - - template<> - struct apply_impl< apply_mode::action > - { - template< typename Input, typename... States > - static bool match( Input& /*unused*/, States&&... /*unused*/ ) - { - return true; - } - }; - - template< typename... Actions > - struct apply_impl< apply_mode::action, Actions... > - { - template< typename Input, typename... States > - static bool match( Input& in, States&&... st ) - { - using action_t = typename Input::action_t; - const action_t i2( in.iterator(), in ); // No data -- range is from begin to begin. -#ifdef __cpp_fold_expressions - return ( apply_single< Actions >::match( i2, st... ) && ... ); -#else - bool result = true; - using swallow = bool[]; - (void)swallow{ result = result && apply_single< Actions >::match( i2, st... )... }; - return result; -#endif - } - }; - - template< typename... Actions > - struct apply_impl< apply_mode::nothing, Actions... > - { - template< typename Input, typename... States > - static bool match( Input& /*unused*/, States&&... /*unused*/ ) - { - return true; - } - }; - - template< typename... Actions > - struct apply - { - using analyze_t = analysis::counted< analysis::rule_type::any, 0 >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return apply_impl< A, Actions... >::match( in, st... ); - } - }; - - template< typename... Actions > - struct skip_control< apply< Actions... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/apply0.hpp" - -#line 1 "tao/pegtl/internal/apply0.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_APPLY0_HPP -#define TAO_PEGTL_INTERNAL_APPLY0_HPP - - - -#line 1 "tao/pegtl/internal/apply0_single.hpp" - -#line 1 "tao/pegtl/internal/apply0_single.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_APPLY0_SINGLE_HPP -#define TAO_PEGTL_INTERNAL_APPLY0_SINGLE_HPP - - - -#include - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Action > - struct apply0_single - { - template< typename... States > - static auto match( States&&... st ) - -> typename std::enable_if< std::is_same< decltype( Action::apply0( st... ) ), void >::value, bool >::type - { - Action::apply0( st... ); - return true; - } - - template< typename... States > - static auto match( States&&... st ) - -> typename std::enable_if< std::is_same< decltype( Action::apply0( st... ) ), bool >::value, bool >::type - { - return Action::apply0( st... ); - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/apply0.hpp" - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< apply_mode A, typename... Actions > - struct apply0_impl; - - template<> - struct apply0_impl< apply_mode::action > - { - template< typename... States > - static bool match( States&&... /*unused*/ ) noexcept - { - return true; - } - }; - - template< typename... Actions > - struct apply0_impl< apply_mode::action, Actions... > - { - template< typename... States > - static bool match( States&&... st ) - { -#ifdef __cpp_fold_expressions - return ( apply0_single< Actions >::match( st... ) && ... ); -#else - bool result = true; - using swallow = bool[]; - (void)swallow{ result = result && apply0_single< Actions >::match( st... )... }; - return result; -#endif - } - }; - - template< typename... Actions > - struct apply0_impl< apply_mode::nothing, Actions... > - { - template< typename... States > - static bool match( States&&... /*unused*/ ) noexcept - { - return true; - } - }; - - template< typename... Actions > - struct apply0 - { - using analyze_t = analysis::counted< analysis::rule_type::any, 0 >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& /*unused*/, States&&... st ) - { - return apply0_impl< A, Actions... >::match( st... ); - } - }; - - template< typename... Actions > - struct skip_control< apply0< Actions... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 13 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/at.hpp" - -#line 1 "tao/pegtl/internal/at.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_AT_HPP -#define TAO_PEGTL_INTERNAL_AT_HPP -#line 18 "tao/pegtl/internal/at.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename... Rules > - struct at - : at< seq< Rules... > > - { - }; - - template<> - struct at<> - : trivial< true > - { - }; - - template< typename Rule > - struct at< Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::opt, Rule >; - - template< apply_mode, - rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - const auto m = in.template mark< rewind_mode::required >(); - return Control< Rule >::template match< apply_mode::nothing, rewind_mode::active, Action, Control >( in, st... ); - } - }; - - template< typename... Rules > - struct skip_control< at< Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 14 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/bof.hpp" - -#line 1 "tao/pegtl/internal/bof.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_BOF_HPP -#define TAO_PEGTL_INTERNAL_BOF_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct bof - { - using analyze_t = analysis::generic< analysis::rule_type::opt >; - - template< typename Input > - static bool match( Input& in ) noexcept - { - return in.byte() == 0; - } - }; - - template<> - struct skip_control< bof > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 15 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/bol.hpp" - -#line 1 "tao/pegtl/internal/bol.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_BOL_HPP -#define TAO_PEGTL_INTERNAL_BOL_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct bol - { - using analyze_t = analysis::generic< analysis::rule_type::opt >; - - template< typename Input > - static bool match( Input& in ) noexcept - { - return in.byte_in_line() == 0; - } - }; - - template<> - struct skip_control< bol > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 16 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/bytes.hpp" - -#line 1 "tao/pegtl/internal/bytes.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_BYTES_HPP -#define TAO_PEGTL_INTERNAL_BYTES_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< unsigned Num > - struct bytes - { - using analyze_t = analysis::counted< analysis::rule_type::any, Num >; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( in.size( 0 ) ) ) - { - if( in.size( Num ) >= Num ) { - in.bump( Num ); - return true; - } - return false; - } - }; - - template< unsigned Num > - struct skip_control< bytes< Num > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 17 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/control.hpp" - -#line 1 "tao/pegtl/internal/control.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_CONTROL_HPP -#define TAO_PEGTL_INTERNAL_CONTROL_HPP -#line 17 "tao/pegtl/internal/control.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< template< typename... > class Control, typename... Rules > - struct control - : control< Control, seq< Rules... > > - { - }; - - template< template< typename... > class Control, typename Rule > - struct control< Control, Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::seq, Rule >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return Control< Rule >::template match< A, M, Action, Control >( in, st... ); - } - }; - - template< template< typename... > class Control, typename... Rules > - struct skip_control< control< Control, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 18 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/disable.hpp" - -#line 1 "tao/pegtl/internal/disable.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_DISABLE_HPP -#define TAO_PEGTL_INTERNAL_DISABLE_HPP -#line 17 "tao/pegtl/internal/disable.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename... Rules > - struct disable - : disable< seq< Rules... > > - { - }; - - template< typename Rule > - struct disable< Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::seq, Rule >; - - template< apply_mode, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return Control< Rule >::template match< apply_mode::nothing, M, Action, Control >( in, st... ); - } - }; - - template< typename... Rules > - struct skip_control< disable< Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 19 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/discard.hpp" - -#line 1 "tao/pegtl/internal/discard.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_DISCARD_HPP -#define TAO_PEGTL_INTERNAL_DISCARD_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct discard - { - using analyze_t = analysis::generic< analysis::rule_type::opt >; - - template< typename Input > - static bool match( Input& in ) noexcept - { - static_assert( noexcept( in.discard() ), "an input's discard()-method must be noexcept" ); - in.discard(); - return true; - } - }; - - template<> - struct skip_control< discard > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 20 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/enable.hpp" - -#line 1 "tao/pegtl/internal/enable.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ENABLE_HPP -#define TAO_PEGTL_INTERNAL_ENABLE_HPP -#line 17 "tao/pegtl/internal/enable.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename... Rules > - struct enable - : enable< seq< Rules... > > - { - }; - - template< typename Rule > - struct enable< Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::seq, Rule >; - - template< apply_mode, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return Control< Rule >::template match< apply_mode::action, M, Action, Control >( in, st... ); - } - }; - - template< typename... Rules > - struct skip_control< enable< Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 21 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/eof.hpp" - -#line 1 "tao/pegtl/internal/eof.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_EOF_HPP -#define TAO_PEGTL_INTERNAL_EOF_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct eof - { - using analyze_t = analysis::generic< analysis::rule_type::opt >; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( in.empty() ) ) - { - return in.empty(); - } - }; - - template<> - struct skip_control< eof > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 22 "tao/pegtl/internal/rules.hpp" - -#line 1 "tao/pegtl/internal/eolf.hpp" - -#line 1 "tao/pegtl/internal/eolf.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_EOLF_HPP -#define TAO_PEGTL_INTERNAL_EOLF_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct eolf - { - using analyze_t = analysis::generic< analysis::rule_type::opt >; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( Input::eol_t::match( in ) ) ) - { - const auto p = Input::eol_t::match( in ); - return p.first || ( !p.second ); - } - }; - - template<> - struct skip_control< eolf > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 24 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/identifier.hpp" - -#line 1 "tao/pegtl/internal/identifier.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_IDENTIFIER_HPP -#define TAO_PEGTL_INTERNAL_IDENTIFIER_HPP - - - - - - -#line 1 "tao/pegtl/internal/star.hpp" - -#line 1 "tao/pegtl/internal/star.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_STAR_HPP -#define TAO_PEGTL_INTERNAL_STAR_HPP - -#include -#line 19 "tao/pegtl/internal/star.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Rule, typename... Rules > - struct star - : star< seq< Rule, Rules... > > - {}; - - template< typename Rule > - struct star< Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::opt, Rule, star >; - - template< apply_mode A, - rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - while( Control< Rule >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) { - } - return true; - } - }; - - template< typename Rule, typename... Rules > - struct skip_control< star< Rule, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 13 "tao/pegtl/internal/identifier.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - using identifier_first = ranges< peek_char, 'a', 'z', 'A', 'Z', '_' >; - using identifier_other = ranges< peek_char, 'a', 'z', 'A', 'Z', '0', '9', '_' >; - using identifier = seq< identifier_first, star< identifier_other > >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 25 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/if_apply.hpp" - -#line 1 "tao/pegtl/internal/if_apply.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_IF_APPLY_HPP -#define TAO_PEGTL_INTERNAL_IF_APPLY_HPP -#line 16 "tao/pegtl/internal/if_apply.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< apply_mode A, typename Rule, typename... Actions > - struct if_apply_impl; - - template< typename Rule > - struct if_apply_impl< apply_mode::action, Rule > - { - template< rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return Control< Rule >::template match< apply_mode::action, M, Action, Control >( in, st... ); - } - }; - - template< typename Rule, typename... Actions > - struct if_apply_impl< apply_mode::action, Rule, Actions... > - { - template< rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - using action_t = typename Input::action_t; - - auto m = in.template mark< rewind_mode::required >(); - - if( Control< Rule >::template match< apply_mode::action, rewind_mode::active, Action, Control >( in, st... ) ) { - const action_t i2( m.iterator(), in ); -#ifdef __cpp_fold_expressions - return m( ( apply_single< Actions >::match( i2, st... ) && ... ) ); -#else - bool result = true; - using swallow = bool[]; - (void)swallow{ result = result && apply_single< Actions >::match( i2, st... )... }; - return m( result ); -#endif - } - return false; - } - }; - - template< typename Rule, typename... Actions > - struct if_apply_impl< apply_mode::nothing, Rule, Actions... > - { - template< rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return Control< Rule >::template match< apply_mode::nothing, M, Action, Control >( in, st... ); - } - }; - - template< typename Rule, typename... Actions > - struct if_apply - { - using analyze_t = typename Rule::analyze_t; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return if_apply_impl< A, Rule, Actions... >::template match< M, Action, Control >( in, st... ); - } - }; - - template< typename Rule, typename... Actions > - struct skip_control< if_apply< Rule, Actions... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 26 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/if_must.hpp" - -#line 1 "tao/pegtl/internal/if_must.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_IF_MUST_HPP -#define TAO_PEGTL_INTERNAL_IF_MUST_HPP - - - -#line 1 "tao/pegtl/internal/must.hpp" - -#line 1 "tao/pegtl/internal/must.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_MUST_HPP -#define TAO_PEGTL_INTERNAL_MUST_HPP - - - -#line 1 "tao/pegtl/internal/raise.hpp" - -#line 1 "tao/pegtl/internal/raise.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_RAISE_HPP -#define TAO_PEGTL_INTERNAL_RAISE_HPP - -#include -#include -#include -#line 19 "tao/pegtl/internal/raise.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename T > - struct raise - { - using analyze_t = analysis::generic< analysis::rule_type::any >; - -#ifdef _MSC_VER -#pragma warning( push ) -#pragma warning( disable : 4702 ) -#endif - template< apply_mode, - rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - Control< T >::raise( static_cast< const Input& >( in ), st... ); - throw std::logic_error( "code should be unreachable: Control< T >::raise() did not throw an exception" ); // NOLINT, LCOV_EXCL_LINE -#ifdef _MSC_VER -#pragma warning( pop ) -#endif - } - }; - - template< typename T > - struct skip_control< raise< T > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/must.hpp" -#line 18 "tao/pegtl/internal/must.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - // The general case applies must<> to each of the - // rules in the 'Rules' parameter pack individually. - - template< typename... Rules > - struct must - : seq< must< Rules >... > - { - }; - - // While in theory the implementation for a single rule could - // be simplified to must< Rule > = sor< Rule, raise< Rule > >, this - // would result in some unnecessary run-time overhead. - - template< typename Rule > - struct must< Rule > - { - using analyze_t = typename Rule::analyze_t; - - template< apply_mode A, - rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - if( !Control< Rule >::template match< A, rewind_mode::dontcare, Action, Control >( in, st... ) ) { - raise< Rule >::template match< A, rewind_mode::dontcare, Action, Control >( in, st... ); - } - return true; - } - }; - - template< typename... Rules > - struct skip_control< must< Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/if_must.hpp" -#line 18 "tao/pegtl/internal/if_must.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< bool Default, typename Cond, typename... Rules > - struct if_must - { - using analyze_t = analysis::counted< analysis::rule_type::seq, Default ? 0 : 1, Cond, must< Rules... > >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - if( Control< Cond >::template match< A, M, Action, Control >( in, st... ) ) { - Control< must< Rules... > >::template match< A, M, Action, Control >( in, st... ); - return true; - } - return Default; - } - }; - - template< bool Default, typename Cond, typename... Rules > - struct skip_control< if_must< Default, Cond, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 27 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/if_must_else.hpp" - -#line 1 "tao/pegtl/internal/if_must_else.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_IF_MUST_ELSE_HPP -#define TAO_PEGTL_INTERNAL_IF_MUST_ELSE_HPP - - - -#line 1 "tao/pegtl/internal/if_then_else.hpp" - -#line 1 "tao/pegtl/internal/if_then_else.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_IF_THEN_ELSE_HPP -#define TAO_PEGTL_INTERNAL_IF_THEN_ELSE_HPP - - - -#line 1 "tao/pegtl/internal/not_at.hpp" - -#line 1 "tao/pegtl/internal/not_at.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_NOT_AT_HPP -#define TAO_PEGTL_INTERNAL_NOT_AT_HPP -#line 18 "tao/pegtl/internal/not_at.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename... Rules > - struct not_at - : not_at< seq< Rules... > > - { - }; - - template<> - struct not_at<> - : trivial< false > - { - }; - - template< typename Rule > - struct not_at< Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::opt, Rule >; - - template< apply_mode, - rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - const auto m = in.template mark< rewind_mode::required >(); - return !Control< Rule >::template match< apply_mode::nothing, rewind_mode::active, Action, Control >( in, st... ); - } - }; - - template< typename... Rules > - struct skip_control< not_at< Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/if_then_else.hpp" - - -#line 1 "tao/pegtl/internal/sor.hpp" - -#line 1 "tao/pegtl/internal/sor.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_SOR_HPP -#define TAO_PEGTL_INTERNAL_SOR_HPP - - - -#line 1 "tao/pegtl/internal/integer_sequence.hpp" - -#line 1 "tao/pegtl/internal/integer_sequence.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_INTEGER_SEQUENCE_HPP -#define TAO_PEGTL_INTERNAL_INTEGER_SEQUENCE_HPP - -#include -#include -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename T, T... Ns > - struct integer_sequence - { - using value_type = T; - - static constexpr std::size_t size() noexcept - { - return sizeof...( Ns ); - } - }; - - template< std::size_t... Ns > - using index_sequence = integer_sequence< std::size_t, Ns... >; - - template< bool V, bool E > - struct generate_sequence; - - template<> - struct generate_sequence< false, true > - { - template< typename T, T M, T N, std::size_t S, T... Ns > - using f = integer_sequence< T, Ns... >; - }; - - template<> - struct generate_sequence< true, true > - { - template< typename T, T M, T N, std::size_t S, T... Ns > - using f = integer_sequence< T, Ns..., S >; - }; - - template<> - struct generate_sequence< false, false > - { - template< typename T, T M, T N, std::size_t S, T... Ns > - using f = typename generate_sequence< ( N & ( M / 2 ) ) != 0, ( M / 2 ) == 0 >::template f< T, M / 2, N, 2 * S, Ns..., ( Ns + S )... >; - }; - - template<> - struct generate_sequence< true, false > - { - template< typename T, T M, T N, std::size_t S, T... Ns > - using f = typename generate_sequence< ( N & ( M / 2 ) ) != 0, ( M / 2 ) == 0 >::template f< T, M / 2, N, 2 * S + 1, Ns..., ( Ns + S )..., 2 * S >; - }; - - template< typename T, T N > - struct memoize_sequence - { - static_assert( N < T( 1 << 20 ), "N too large" ); - using type = typename generate_sequence< false, false >::template f< T, ( N < T( 1 << 1 ) ) ? T( 1 << 1 ) : ( N < T( 1 << 2 ) ) ? T( 1 << 2 ) : ( N < T( 1 << 3 ) ) ? T( 1 << 3 ) : ( N < T( 1 << 4 ) ) ? T( 1 << 4 ) : ( N < T( 1 << 5 ) ) ? T( 1 << 5 ) : ( N < T( 1 << 6 ) ) ? T( 1 << 6 ) : ( N < T( 1 << 7 ) ) ? T( 1 << 7 ) : ( N < T( 1 << 8 ) ) ? T( 1 << 8 ) : ( N < T( 1 << 9 ) ) ? T( 1 << 9 ) : ( N < T( 1 << 10 ) ) ? T( 1 << 10 ) : ( N < T( 1 << 11 ) ) ? T( 1 << 11 ) : ( N < T( 1 << 12 ) ) ? T( 1 << 12 ) : ( N < T( 1 << 13 ) ) ? T( 1 << 13 ) : ( N < T( 1 << 14 ) ) ? T( 1 << 14 ) : ( N < T( 1 << 15 ) ) ? T( 1 << 15 ) : ( N < T( 1 << 16 ) ) ? T( 1 << 16 ) : ( N < T( 1 << 17 ) ) ? T( 1 << 17 ) : ( N < T( 1 << 18 ) ) ? T( 1 << 18 ) : ( N < T( 1 << 19 ) ) ? T( 1 << 19 ) : T( 1 << 20 ), N, 0 >; - }; - - template< typename T, T N > - using make_integer_sequence = typename memoize_sequence< T, N >::type; - - template< std::size_t N > - using make_index_sequence = make_integer_sequence< std::size_t, N >; - - template< typename... Ts > - using index_sequence_for = make_index_sequence< sizeof...( Ts ) >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/sor.hpp" -#line 18 "tao/pegtl/internal/sor.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename... Rules > - struct sor; - - template<> - struct sor<> - : trivial< false > - { - }; - - template< typename... Rules > - struct sor - : sor< index_sequence_for< Rules... >, Rules... > - { - }; - - template< std::size_t... Indices, typename... Rules > - struct sor< index_sequence< Indices... >, Rules... > - { - using analyze_t = analysis::generic< analysis::rule_type::sor, Rules... >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { -#ifdef __cpp_fold_expressions - return ( Control< Rules >::template match < A, ( Indices == ( sizeof...( Rules ) - 1 ) ) ? M : rewind_mode::required, Action, Control > ( in, st... ) || ... ); -#else - bool result = false; - using swallow = bool[]; - (void)swallow{ result = result || Control< Rules >::template match < A, ( Indices == ( sizeof...( Rules ) - 1 ) ) ? M : rewind_mode::required, Action, Control > ( in, st... )... }; - return result; -#endif - } - }; - - template< typename... Rules > - struct skip_control< sor< Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 13 "tao/pegtl/internal/if_then_else.hpp" - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Cond, typename Then, typename Else > - struct if_then_else - { - using analyze_t = analysis::generic< analysis::rule_type::sor, seq< Cond, Then >, seq< not_at< Cond >, Else > >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - auto m = in.template mark< M >(); - using m_t = decltype( m ); - - if( Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) { - return m( Control< Then >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ); - } - return m( Control< Else >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ); - } - }; - - template< typename Cond, typename Then, typename Else > - struct skip_control< if_then_else< Cond, Then, Else > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/internal/if_must_else.hpp" - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Cond, typename Then, typename Else > - using if_must_else = if_then_else< Cond, must< Then >, must< Else > >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 28 "tao/pegtl/internal/rules.hpp" - -#line 1 "tao/pegtl/internal/istring.hpp" - -#line 1 "tao/pegtl/internal/istring.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ISTRING_HPP -#define TAO_PEGTL_INTERNAL_ISTRING_HPP - -#include -#line 18 "tao/pegtl/internal/istring.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< char C > - using is_alpha = std::integral_constant< bool, ( ( 'a' <= C ) && ( C <= 'z' ) ) || ( ( 'A' <= C ) && ( C <= 'Z' ) ) >; - - template< char C, bool A = is_alpha< C >::value > - struct ichar_equal; - - template< char C > - struct ichar_equal< C, true > - { - static bool match( const char c ) noexcept - { - return ( C | 0x20 ) == ( c | 0x20 ); - } - }; - - template< char C > - struct ichar_equal< C, false > - { - static bool match( const char c ) noexcept - { - return c == C; - } - }; - - template< char... Cs > - struct istring_equal; - - template<> - struct istring_equal<> - { - static bool match( const char* /*unused*/ ) noexcept - { - return true; - } - }; - - template< char C, char... Cs > - struct istring_equal< C, Cs... > - { - static bool match( const char* r ) noexcept - { - return ichar_equal< C >::match( *r ) && istring_equal< Cs... >::match( r + 1 ); - } - }; - - template< char... Cs > - struct istring; - - template<> - struct istring<> - : trivial< true > - { - }; - - template< char... Cs > - struct istring - { - using analyze_t = analysis::counted< analysis::rule_type::any, sizeof...( Cs ) >; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( in.size( 0 ) ) ) - { - if( in.size( sizeof...( Cs ) ) >= sizeof...( Cs ) ) { - if( istring_equal< Cs... >::match( in.current() ) ) { - bump_help< result_on_found::success, Input, char, Cs... >( in, sizeof...( Cs ) ); - return true; - } - } - return false; - } - }; - - template< char... Cs > - struct skip_control< istring< Cs... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 30 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/list.hpp" - -#line 1 "tao/pegtl/internal/list.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_LIST_HPP -#define TAO_PEGTL_INTERNAL_LIST_HPP - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Rule, typename Sep > - using list = seq< Rule, star< Sep, Rule > >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 31 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/list_must.hpp" - -#line 1 "tao/pegtl/internal/list_must.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_LIST_MUST_HPP -#define TAO_PEGTL_INTERNAL_LIST_MUST_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Rule, typename Sep > - using list_must = seq< Rule, star< Sep, must< Rule > > >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 32 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/list_tail.hpp" - -#line 1 "tao/pegtl/internal/list_tail.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_LIST_TAIL_HPP -#define TAO_PEGTL_INTERNAL_LIST_TAIL_HPP - - - - -#line 1 "tao/pegtl/internal/opt.hpp" - -#line 1 "tao/pegtl/internal/opt.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_OPT_HPP -#define TAO_PEGTL_INTERNAL_OPT_HPP - -#include -#line 20 "tao/pegtl/internal/opt.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename... Rules > - struct opt - : opt< seq< Rules... > > - { - }; - - template<> - struct opt<> - : trivial< true > - { - }; - - template< typename Rule > - struct opt< Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::opt, Rule >; - - template< apply_mode A, - rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - Control< Rule >::template match< A, rewind_mode::required, Action, Control >( in, st... ); - return true; - } - }; - - template< typename... Rules > - struct skip_control< opt< Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 11 "tao/pegtl/internal/list_tail.hpp" - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Rule, typename Sep > - using list_tail = seq< list< Rule, Sep >, opt< Sep > >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 33 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/list_tail_pad.hpp" - -#line 1 "tao/pegtl/internal/list_tail_pad.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_LIST_TAIL_PAD_HPP -#define TAO_PEGTL_INTERNAL_LIST_TAIL_PAD_HPP - - - - - -#line 1 "tao/pegtl/internal/pad.hpp" - -#line 1 "tao/pegtl/internal/pad.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PAD_HPP -#define TAO_PEGTL_INTERNAL_PAD_HPP - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Rule, typename Pad1, typename Pad2 = Pad1 > - using pad = seq< star< Pad1 >, Rule, star< Pad2 > >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/internal/list_tail_pad.hpp" - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Rule, typename Sep, typename Pad > - using list_tail_pad = seq< list< Rule, pad< Sep, Pad > >, opt< star< Pad >, Sep > >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 34 "tao/pegtl/internal/rules.hpp" - - -#line 1 "tao/pegtl/internal/one.hpp" - -#line 1 "tao/pegtl/internal/one.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ONE_HPP -#define TAO_PEGTL_INTERNAL_ONE_HPP - -#include -#include -#line 18 "tao/pegtl/internal/one.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Char > - bool contains( const Char c, const std::initializer_list< Char >& l ) noexcept - { - return std::find( l.begin(), l.end(), c ) != l.end(); - } - - template< result_on_found R, typename Peek, typename Peek::data_t... Cs > - struct one - { - using analyze_t = analysis::generic< analysis::rule_type::any >; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( Peek::peek( in ) ) ) - { - if( const auto t = Peek::peek( in ) ) { - if( contains( t.data, { Cs... } ) == bool( R ) ) { - bump_help< R, Input, typename Peek::data_t, Cs... >( in, t.size ); - return true; - } - } - return false; - } - }; - - template< result_on_found R, typename Peek, typename Peek::data_t C > - struct one< R, Peek, C > - { - using analyze_t = analysis::generic< analysis::rule_type::any >; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( Peek::peek( in ) ) ) - { - if( const auto t = Peek::peek( in ) ) { - if( ( t.data == C ) == bool( R ) ) { - bump_help< R, Input, typename Peek::data_t, C >( in, t.size ); - return true; - } - } - return false; - } - }; - - template< result_on_found R, typename Peek, typename Peek::data_t... Cs > - struct skip_control< one< R, Peek, Cs... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 37 "tao/pegtl/internal/rules.hpp" - - -#line 1 "tao/pegtl/internal/pad_opt.hpp" - -#line 1 "tao/pegtl/internal/pad_opt.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PAD_OPT_HPP -#define TAO_PEGTL_INTERNAL_PAD_OPT_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Rule, typename Pad > - using pad_opt = seq< star< Pad >, opt< Rule, star< Pad > > >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 40 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/plus.hpp" - -#line 1 "tao/pegtl/internal/plus.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PLUS_HPP -#define TAO_PEGTL_INTERNAL_PLUS_HPP - -#include -#line 21 "tao/pegtl/internal/plus.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - // While plus<> could easily be implemented with - // seq< Rule, Rules ..., star< Rule, Rules ... > > we - // provide an explicit implementation to optimise away - // the otherwise created input mark. - - template< typename Rule, typename... Rules > - struct plus - : plus< seq< Rule, Rules... > > - { - }; - - template< typename Rule > - struct plus< Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::seq, Rule, opt< plus > >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return Control< Rule >::template match< A, M, Action, Control >( in, st... ) && Control< star< Rule > >::template match< A, M, Action, Control >( in, st... ); - } - }; - - template< typename Rule, typename... Rules > - struct skip_control< plus< Rule, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 41 "tao/pegtl/internal/rules.hpp" - - - -#line 1 "tao/pegtl/internal/rematch.hpp" - -#line 1 "tao/pegtl/internal/rematch.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_REMATCH_HPP -#define TAO_PEGTL_INTERNAL_REMATCH_HPP - - - - - - -#line 1 "tao/pegtl/internal/../memory_input.hpp" - -#line 1 "tao/pegtl/internal/../memory_input.hpp" - - - -#ifndef TAO_PEGTL_MEMORY_INPUT_HPP -#define TAO_PEGTL_MEMORY_INPUT_HPP - -#include -#include -#include -#include -#include -#include - - - - - - -#line 1 "tao/pegtl/internal/../tracking_mode.hpp" - -#line 1 "tao/pegtl/internal/../tracking_mode.hpp" - - - -#ifndef TAO_PEGTL_TRACKING_MODE_HPP -#define TAO_PEGTL_TRACKING_MODE_HPP - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - enum class tracking_mode : bool - { - eager, - lazy, - - // Compatibility, remove with 3.0.0 - IMMEDIATE = eager, - LAZY = lazy - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 20 "tao/pegtl/internal/../memory_input.hpp" - - - -#line 1 "tao/pegtl/internal/../internal/bump.hpp" - -#line 1 "tao/pegtl/internal/../internal/bump.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_BUMP_HPP -#define TAO_PEGTL_INTERNAL_BUMP_HPP - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - inline void bump( iterator& iter, const std::size_t count, const int ch ) noexcept - { - for( std::size_t i = 0; i < count; ++i ) { - if( iter.data[ i ] == ch ) { - ++iter.line; - iter.byte_in_line = 0; - } - else { - ++iter.byte_in_line; - } - } - iter.byte += count; - iter.data += count; - } - - inline void bump_in_this_line( iterator& iter, const std::size_t count ) noexcept - { - iter.data += count; - iter.byte += count; - iter.byte_in_line += count; - } - - inline void bump_to_next_line( iterator& iter, const std::size_t count ) noexcept - { - ++iter.line; - iter.byte += count; - iter.byte_in_line = 0; - iter.data += count; - } - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 24 "tao/pegtl/internal/../memory_input.hpp" - - -#line 1 "tao/pegtl/internal/../internal/marker.hpp" - -#line 1 "tao/pegtl/internal/../internal/marker.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_MARKER_HPP -#define TAO_PEGTL_INTERNAL_MARKER_HPP - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Iterator, rewind_mode M > - class marker - { - public: - static constexpr rewind_mode next_rewind_mode = M; - - explicit marker( const Iterator& /*unused*/ ) noexcept - { - } - - marker( const marker& ) = delete; - - marker( marker&& /*unused*/ ) noexcept - { - } - - ~marker() = default; - - void operator=( const marker& ) = delete; - void operator=( marker&& ) = delete; - - bool operator()( const bool result ) const noexcept - { - return result; - } - }; - - template< typename Iterator > - class marker< Iterator, rewind_mode::required > - { - public: - static constexpr rewind_mode next_rewind_mode = rewind_mode::active; - - explicit marker( Iterator& i ) noexcept - : m_saved( i ), - m_input( &i ) - { - } - - marker( const marker& ) = delete; - - marker( marker&& i ) noexcept - : m_saved( i.m_saved ), - m_input( i.m_input ) - { - i.m_input = nullptr; - } - - ~marker() noexcept - { - if( m_input != nullptr ) { - ( *m_input ) = m_saved; - } - } - - void operator=( const marker& ) = delete; - void operator=( marker&& ) = delete; - - bool operator()( const bool result ) noexcept - { - if( result ) { - m_input = nullptr; - return true; - } - return false; - } - - const Iterator& iterator() const noexcept - { - return m_saved; - } - - private: - const Iterator m_saved; - Iterator* m_input; - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 27 "tao/pegtl/internal/../memory_input.hpp" -#line 1 "tao/pegtl/internal/../internal/until.hpp" - -#line 1 "tao/pegtl/internal/../internal/until.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_UNTIL_HPP -#define TAO_PEGTL_INTERNAL_UNTIL_HPP -#line 21 "tao/pegtl/internal/../internal/until.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Cond, typename... Rules > - struct until - : until< Cond, seq< Rules... > > - { - }; - - template< typename Cond > - struct until< Cond > - { - using analyze_t = analysis::generic< analysis::rule_type::seq, star< not_at< Cond >, not_at< eof >, bytes< 1 > >, Cond >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - auto m = in.template mark< M >(); - - while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) { - if( in.empty() ) { - return false; - } - in.bump(); - } - return m( true ); - } - }; - - template< typename Cond, typename Rule > - struct until< Cond, Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::seq, star< not_at< Cond >, not_at< eof >, Rule >, Cond >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - auto m = in.template mark< M >(); - using m_t = decltype( m ); - - while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) { - if( !Control< Rule >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) { - return false; - } - } - return m( true ); - } - }; - - template< typename Cond, typename... Rules > - struct skip_control< until< Cond, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 28 "tao/pegtl/internal/../memory_input.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< tracking_mode, typename Eol, typename Source > - class memory_input_base; - - template< typename Eol, typename Source > - class memory_input_base< tracking_mode::eager, Eol, Source > - { - public: - using iterator_t = internal::iterator; - - template< typename T > - memory_input_base( const iterator_t& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) - : m_begin( in_begin.data ), - m_current( in_begin ), - m_end( in_end ), - m_source( std::forward< T >( in_source ) ) - { - } - - template< typename T > - memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) - : m_begin( in_begin ), - m_current( in_begin ), - m_end( in_end ), - m_source( std::forward< T >( in_source ) ) - { - } - - memory_input_base( const memory_input_base& ) = delete; - memory_input_base( memory_input_base&& ) = delete; - - ~memory_input_base() = default; - - memory_input_base operator=( const memory_input_base& ) = delete; - memory_input_base operator=( memory_input_base&& ) = delete; - - const char* current() const noexcept - { - return m_current.data; - } - - const char* begin() const noexcept - { - return m_begin; - } - - const char* end( const std::size_t /*unused*/ = 0 ) const noexcept - { - return m_end; - } - - std::size_t byte() const noexcept - { - return m_current.byte; - } - - std::size_t line() const noexcept - { - return m_current.line; - } - - std::size_t byte_in_line() const noexcept - { - return m_current.byte_in_line; - } - - void bump( const std::size_t in_count = 1 ) noexcept - { - internal::bump( m_current, in_count, Eol::ch ); - } - - void bump_in_this_line( const std::size_t in_count = 1 ) noexcept - { - internal::bump_in_this_line( m_current, in_count ); - } - - void bump_to_next_line( const std::size_t in_count = 1 ) noexcept - { - internal::bump_to_next_line( m_current, in_count ); - } - - TAO_PEGTL_NAMESPACE::position position( const iterator_t& it ) const - { - return TAO_PEGTL_NAMESPACE::position( it, m_source ); - } - - void restart( const std::size_t in_byte = 0, const std::size_t in_line = 1, const std::size_t in_byte_in_line = 0 ) - { - m_current.data = m_begin; - m_current.byte = in_byte; - m_current.line = in_line; - m_current.byte_in_line = in_byte_in_line; - } - - protected: - const char* const m_begin; - iterator_t m_current; - const char* const m_end; - const Source m_source; - }; - - template< typename Eol, typename Source > - class memory_input_base< tracking_mode::lazy, Eol, Source > - { - public: - using iterator_t = const char*; - - template< typename T > - memory_input_base( const internal::iterator& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) - : m_begin( in_begin ), - m_current( in_begin.data ), - m_end( in_end ), - m_source( std::forward< T >( in_source ) ) - { - } - - template< typename T > - memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) - : m_begin( in_begin ), - m_current( in_begin ), - m_end( in_end ), - m_source( std::forward< T >( in_source ) ) - { - } - - memory_input_base( const memory_input_base& ) = delete; - memory_input_base( memory_input_base&& ) = delete; - - ~memory_input_base() = default; - - memory_input_base operator=( const memory_input_base& ) = delete; - memory_input_base operator=( memory_input_base&& ) = delete; - - const char* current() const noexcept - { - return m_current; - } - - const char* begin() const noexcept - { - return m_begin.data; - } - - const char* end( const std::size_t /*unused*/ = 0 ) const noexcept - { - return m_end; - } - - std::size_t byte() const noexcept - { - return std::size_t( current() - m_begin.data ); - } - - void bump( const std::size_t in_count = 1 ) noexcept - { - m_current += in_count; - } - - void bump_in_this_line( const std::size_t in_count = 1 ) noexcept - { - m_current += in_count; - } - - void bump_to_next_line( const std::size_t in_count = 1 ) noexcept - { - m_current += in_count; - } - - TAO_PEGTL_NAMESPACE::position position( const iterator_t it ) const - { - internal::iterator c( m_begin ); - internal::bump( c, std::size_t( it - m_begin.data ), Eol::ch ); - return TAO_PEGTL_NAMESPACE::position( c, m_source ); - } - - void restart() - { - m_current = m_begin.data; - } - - protected: - const internal::iterator m_begin; - iterator_t m_current; - const char* const m_end; - const Source m_source; - }; - - } // namespace internal - - template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf, typename Source = std::string > - class memory_input - : public internal::memory_input_base< P, Eol, Source > - { - public: - static constexpr tracking_mode tracking_mode_v = P; - - using eol_t = Eol; - using source_t = Source; - - using typename internal::memory_input_base< P, Eol, Source >::iterator_t; - - using action_t = internal::action_input< memory_input >; - - using internal::memory_input_base< P, Eol, Source >::memory_input_base; - - template< typename T > - memory_input( const char* in_begin, const std::size_t in_size, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) - : memory_input( in_begin, in_begin + in_size, std::forward< T >( in_source ) ) - { - } - - template< typename T > - memory_input( const std::string& in_string, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) - : memory_input( in_string.data(), in_string.size(), std::forward< T >( in_source ) ) - { - } - - template< typename T > - memory_input( std::string&&, T&& ) = delete; - - template< typename T > - memory_input( const char* in_begin, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) - : memory_input( in_begin, std::strlen( in_begin ), std::forward< T >( in_source ) ) - { - } - - template< typename T > - memory_input( const char* in_begin, const char* in_end, T&& in_source, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_byte_in_line ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) - : memory_input( { in_begin, in_byte, in_line, in_byte_in_line }, in_end, std::forward< T >( in_source ) ) - { - } - - memory_input( const memory_input& ) = delete; - memory_input( memory_input&& ) = delete; - - ~memory_input() = default; - - memory_input operator=( const memory_input& ) = delete; - memory_input operator=( memory_input&& ) = delete; - - const Source& source() const noexcept - { - return this->m_source; - } - - bool empty() const noexcept - { - return this->current() == this->end(); - } - - std::size_t size( const std::size_t /*unused*/ = 0 ) const noexcept - { - return std::size_t( this->end() - this->current() ); - } - - char peek_char( const std::size_t offset = 0 ) const noexcept - { - return this->current()[ offset ]; - } - - std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept - { - return static_cast< std::uint8_t >( peek_char( offset ) ); - } - - // Compatibility, remove with 3.0.0 - std::uint8_t peek_byte( const std::size_t offset = 0 ) const noexcept - { - return static_cast< std::uint8_t >( peek_char( offset ) ); - } - - iterator_t& iterator() noexcept - { - return this->m_current; - } - - const iterator_t& iterator() const noexcept - { - return this->m_current; - } - - using internal::memory_input_base< P, Eol, Source >::restart; - - template< rewind_mode M > - void restart( const internal::marker< iterator_t, M >& m ) - { - iterator() = m.iterator(); - } - - using internal::memory_input_base< P, Eol, Source >::position; - - TAO_PEGTL_NAMESPACE::position position() const - { - return position( iterator() ); - } - - void discard() const noexcept - { - } - - void require( const std::size_t /*unused*/ ) const noexcept - { - } - - template< rewind_mode M > - internal::marker< iterator_t, M > mark() noexcept - { - return internal::marker< iterator_t, M >( iterator() ); - } - - const char* at( const TAO_PEGTL_NAMESPACE::position& p ) const noexcept - { - return this->begin() + p.byte; - } - - const char* begin_of_line( const TAO_PEGTL_NAMESPACE::position& p ) const noexcept - { - return at( p ) - p.byte_in_line; - } - - const char* end_of_line( const TAO_PEGTL_NAMESPACE::position& p ) const noexcept - { - using input_t = memory_input< tracking_mode::lazy, Eol, const char* >; - input_t in( at( p ), this->end(), "" ); - using grammar = internal::until< internal::at< internal::eolf > >; - normal< grammar >::match< apply_mode::nothing, rewind_mode::dontcare, nothing, normal >( in ); - return in.current(); - } - - std::string line_at( const TAO_PEGTL_NAMESPACE::position& p ) const - { - return std::string( begin_of_line( p ), end_of_line( p ) ); - } - }; - -#ifdef __cpp_deduction_guides - template< typename... Ts > - memory_input( Ts&&... )->memory_input<>; -#endif - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 13 "tao/pegtl/internal/rematch.hpp" - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Head, typename... Rules > - struct rematch; - - template< typename Head > - struct rematch< Head > - { - using analyze_t = typename Head::analyze_t; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return Control< Head >::template match< A, M, Action, Control >( in, st... ); - } - }; - - template< typename Head, typename Rule, typename... Rules > - struct rematch< Head, Rule, Rules... > - { - using analyze_t = typename Head::analyze_t; // NOTE: Rule and Rules are ignored for analyze(). - - template< apply_mode A, - rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - auto m = in.template mark< rewind_mode::required >(); - - if( Control< Head >::template match< A, rewind_mode::active, Action, Control >( in, st... ) ) { - memory_input< Input::tracking_mode_v, typename Input::eol_t, typename Input::source_t > i2( m.iterator(), in.current(), in.source() ); -#ifdef __cpp_fold_expressions - return m( ( Control< Rule >::template match< A, rewind_mode::active, Action, Control >( i2, st... ) && ... && ( i2.restart( m ), Control< Rules >::template match< A, rewind_mode::active, Action, Control >( i2, st... ) ) ) ); -#else - bool result = Control< Rule >::template match< A, rewind_mode::active, Action, Control >( i2, st... ); - using swallow = bool[]; - (void)swallow{ result = result && ( i2.restart( m ), Control< Rules >::template match< A, rewind_mode::active, Action, Control >( i2, st... ) )..., true }; - return m( result ); -#endif - } - return false; - } - }; - - template< typename Head, typename... Rules > - struct skip_control< rematch< Head, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 45 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/rep.hpp" - -#line 1 "tao/pegtl/internal/rep.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_REP_HPP -#define TAO_PEGTL_INTERNAL_REP_HPP -#line 18 "tao/pegtl/internal/rep.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< unsigned Num, typename... Rules > - struct rep - : rep< Num, seq< Rules... > > - { - }; - - template< unsigned Num > - struct rep< Num > - : trivial< true > - { - }; - - template< typename Rule > - struct rep< 0, Rule > - : trivial< true > - { - }; - - template< unsigned Num, typename Rule > - struct rep< Num, Rule > - { - using analyze_t = analysis::counted< analysis::rule_type::seq, Num, Rule >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - auto m = in.template mark< M >(); - using m_t = decltype( m ); - - for( unsigned i = 0; i != Num; ++i ) { - if( !Control< Rule >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) { - return false; - } - } - return m( true ); - } - }; - - template< unsigned Num, typename... Rules > - struct skip_control< rep< Num, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 46 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/rep_min.hpp" - -#line 1 "tao/pegtl/internal/rep_min.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_REP_MIN_HPP -#define TAO_PEGTL_INTERNAL_REP_MIN_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< unsigned Min, typename Rule, typename... Rules > - using rep_min = seq< rep< Min, Rule, Rules... >, star< Rule, Rules... > >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 47 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/rep_min_max.hpp" - -#line 1 "tao/pegtl/internal/rep_min_max.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_REP_MIN_MAX_HPP -#define TAO_PEGTL_INTERNAL_REP_MIN_MAX_HPP - -#include -#line 21 "tao/pegtl/internal/rep_min_max.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< unsigned Min, unsigned Max, typename... Rules > - struct rep_min_max - : rep_min_max< Min, Max, seq< Rules... > > - { - }; - - template< unsigned Min, unsigned Max > - struct rep_min_max< Min, Max > - : trivial< false > - { - static_assert( Min <= Max, "invalid rep_min_max rule (maximum number of repetitions smaller than minimum)" ); - }; - - template< typename Rule > - struct rep_min_max< 0, 0, Rule > - : not_at< Rule > - { - }; - - template< unsigned Min, unsigned Max, typename Rule > - struct rep_min_max< Min, Max, Rule > - { - using analyze_t = analysis::counted< analysis::rule_type::seq, Min, Rule >; - - static_assert( Min <= Max, "invalid rep_min_max rule (maximum number of repetitions smaller than minimum)" ); - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - auto m = in.template mark< M >(); - using m_t = decltype( m ); - - for( unsigned i = 0; i != Min; ++i ) { - if( !Control< Rule >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) { - return false; - } - } - for( unsigned i = Min; i != Max; ++i ) { - if( !Control< Rule >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) { - return m( true ); - } - } - return m( Control< not_at< Rule > >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ); // NOTE that not_at<> will always rewind. - } - }; - - template< unsigned Min, unsigned Max, typename... Rules > - struct skip_control< rep_min_max< Min, Max, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 48 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/rep_opt.hpp" - -#line 1 "tao/pegtl/internal/rep_opt.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_REP_OPT_HPP -#define TAO_PEGTL_INTERNAL_REP_OPT_HPP -#line 17 "tao/pegtl/internal/rep_opt.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< unsigned Max, typename... Rules > - struct rep_opt - : rep_opt< Max, seq< Rules... > > - { - }; - - template< unsigned Max, typename Rule > - struct rep_opt< Max, Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::opt, Rule >; - - template< apply_mode A, - rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - for( unsigned i = 0; ( i != Max ) && Control< Rule >::template match< A, rewind_mode::required, Action, Control >( in, st... ); ++i ) { - } - return true; - } - }; - - template< unsigned Max, typename... Rules > - struct skip_control< rep_opt< Max, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 49 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/require.hpp" - -#line 1 "tao/pegtl/internal/require.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_REQUIRE_HPP -#define TAO_PEGTL_INTERNAL_REQUIRE_HPP -#line 14 "tao/pegtl/internal/require.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< unsigned Amount > - struct require; - - template<> - struct require< 0 > - : trivial< true > - { - }; - - template< unsigned Amount > - struct require - { - using analyze_t = analysis::generic< analysis::rule_type::opt >; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( in.size( 0 ) ) ) - { - return in.size( Amount ) >= Amount; - } - }; - - template< unsigned Amount > - struct skip_control< require< Amount > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 50 "tao/pegtl/internal/rules.hpp" - - - - -#line 1 "tao/pegtl/internal/star_must.hpp" - -#line 1 "tao/pegtl/internal/star_must.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_STAR_MUST_HPP -#define TAO_PEGTL_INTERNAL_STAR_MUST_HPP - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Cond, typename... Rules > - using star_must = star< if_must< false, Cond, Rules... > >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 55 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/state.hpp" - -#line 1 "tao/pegtl/internal/state.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_STATE_HPP -#define TAO_PEGTL_INTERNAL_STATE_HPP -#line 17 "tao/pegtl/internal/state.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename State, typename... Rules > - struct state - : state< State, seq< Rules... > > - { - }; - - template< typename State, typename Rule > - struct state< State, Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::seq, Rule >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static auto success( State& s, const Input& in, States&&... st ) - -> decltype( s.template success< A, M, Action, Control >( in, st... ), void() ) - { - s.template success< A, M, Action, Control >( in, st... ); - } - - // NOTE: The additional "int = 0" is a work-around for missing expression SFINAE in VS2015. - - template< apply_mode, - rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States, - int = 0 > - static auto success( State& s, const Input& in, States&&... st ) - -> decltype( s.success( in, st... ), void() ) - { - s.success( in, st... ); - } - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - State s( static_cast< const Input& >( in ), st... ); - - if( Control< Rule >::template match< A, M, Action, Control >( in, s ) ) { - success< A, M, Action, Control >( s, in, st... ); - return true; - } - return false; - } - }; - - template< typename State, typename... Rules > - struct skip_control< state< State, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 56 "tao/pegtl/internal/rules.hpp" -#line 1 "tao/pegtl/internal/string.hpp" - -#line 1 "tao/pegtl/internal/string.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_STRING_HPP -#define TAO_PEGTL_INTERNAL_STRING_HPP - -#include -#include -#line 19 "tao/pegtl/internal/string.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - inline bool unsafe_equals( const char* s, const std::initializer_list< char >& l ) noexcept - { - return std::memcmp( s, &*l.begin(), l.size() ) == 0; - } - - template< char... Cs > - struct string; - - template<> - struct string<> - : trivial< true > - { - }; - - template< char... Cs > - struct string - { - using analyze_t = analysis::counted< analysis::rule_type::any, sizeof...( Cs ) >; - - template< typename Input > - static bool match( Input& in ) noexcept( noexcept( in.size( 0 ) ) ) - { - if( in.size( sizeof...( Cs ) ) >= sizeof...( Cs ) ) { - if( unsafe_equals( in.current(), { Cs... } ) ) { - bump_help< result_on_found::success, Input, char, Cs... >( in, sizeof...( Cs ) ); - return true; - } - } - return false; - } - }; - - template< char... Cs > - struct skip_control< string< Cs... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 57 "tao/pegtl/internal/rules.hpp" - -#line 1 "tao/pegtl/internal/try_catch_type.hpp" - -#line 1 "tao/pegtl/internal/try_catch_type.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_TRY_CATCH_TYPE_HPP -#define TAO_PEGTL_INTERNAL_TRY_CATCH_TYPE_HPP - -#include -#line 20 "tao/pegtl/internal/try_catch_type.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Exception, typename... Rules > - struct try_catch_type - : try_catch_type< Exception, seq< Rules... > > - { - }; - - template< typename Exception > - struct try_catch_type< Exception > - : trivial< true > - { - }; - - template< typename Exception, typename Rule > - struct try_catch_type< Exception, Rule > - { - using analyze_t = analysis::generic< analysis::rule_type::seq, Rule >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - auto m = in.template mark< M >(); - using m_t = decltype( m ); - - try { - return m( Control< Rule >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ); - } - catch( const Exception& ) { - return false; - } - } - }; - - template< typename Exception, typename... Rules > - struct skip_control< try_catch_type< Exception, Rules... > > : std::true_type - { - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 59 "tao/pegtl/internal/rules.hpp" - - -#endif -#line 13 "tao/pegtl/ascii.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - inline namespace ascii - { - // clang-format off - struct alnum : internal::alnum {}; - struct alpha : internal::alpha {}; - struct any : internal::any< internal::peek_char > {}; - struct blank : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > {}; - struct digit : internal::range< internal::result_on_found::success, internal::peek_char, '0', '9' > {}; - struct ellipsis : internal::string< '.', '.', '.' > {}; - struct eolf : internal::eolf {}; - template< char... Cs > struct forty_two : internal::rep< 42, internal::one< internal::result_on_found::success, internal::peek_char, Cs... > > {}; - struct identifier_first : internal::identifier_first {}; - struct identifier_other : internal::identifier_other {}; - struct identifier : internal::identifier {}; - template< char... Cs > struct istring : internal::istring< Cs... > {}; - template< char... Cs > struct keyword : internal::seq< internal::string< Cs... >, internal::not_at< internal::identifier_other > > {}; - struct lower : internal::range< internal::result_on_found::success, internal::peek_char, 'a', 'z' > {}; - template< char... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_char, Cs... > {}; - template< char Lo, char Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_char, Lo, Hi > {}; - struct nul : internal::one< internal::result_on_found::success, internal::peek_char, char( 0 ) > {}; - template< char... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_char, Cs... > {}; - struct print : internal::range< internal::result_on_found::success, internal::peek_char, char( 32 ), char( 126 ) > {}; - template< char Lo, char Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_char, Lo, Hi > {}; - template< char... Cs > struct ranges : internal::ranges< internal::peek_char, Cs... > {}; - struct seven : internal::range< internal::result_on_found::success, internal::peek_char, char( 0 ), char( 127 ) > {}; - struct shebang : internal::if_must< false, internal::string< '#', '!' >, internal::until< internal::eolf > > {}; - struct space : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\n', '\r', '\t', '\v', '\f' > {}; - template< char... Cs > struct string : internal::string< Cs... > {}; - template< char C > struct three : internal::string< C, C, C > {}; - template< char C > struct two : internal::string< C, C > {}; - struct upper : internal::range< internal::result_on_found::success, internal::peek_char, 'A', 'Z' > {}; - struct xdigit : internal::ranges< internal::peek_char, '0', '9', 'a', 'f', 'A', 'F' > {}; - // clang-format on - - template<> - struct keyword<> - { - template< typename Input > - static bool match( Input& /*unused*/ ) noexcept - { - static_assert( internal::always_false< Input >::value, "empty keywords not allowed" ); - return false; - } - }; - - } // namespace ascii - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#line 1 "tao/pegtl/internal/pegtl_string.hpp" - -#line 1 "tao/pegtl/internal/pegtl_string.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PEGTL_STRING_HPP -#define TAO_PEGTL_INTERNAL_PEGTL_STRING_HPP - -#include -#include - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - // Inspired by https://github.com/irrequietus/typestring - // Rewritten and reduced to what is needed for the PEGTL - // and to work with Visual Studio 2015. - - namespace internal - { - template< typename, typename, typename, typename, typename, typename, typename, typename > - struct string_join; - - template< template< char... > class S, char... C0s, char... C1s, char... C2s, char... C3s, char... C4s, char... C5s, char... C6s, char... C7s > - struct string_join< S< C0s... >, S< C1s... >, S< C2s... >, S< C3s... >, S< C4s... >, S< C5s... >, S< C6s... >, S< C7s... > > - { - using type = S< C0s..., C1s..., C2s..., C3s..., C4s..., C5s..., C6s..., C7s... >; - }; - - template< template< char... > class S, char, bool > - struct string_at - { - using type = S<>; - }; - - template< template< char... > class S, char C > - struct string_at< S, C, true > - { - using type = S< C >; - }; - - template< typename T, std::size_t S > - struct string_max_length - { - static_assert( S <= 512, "String longer than 512 (excluding terminating \\0)!" ); - using type = T; - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#define TAO_PEGTL_INTERNAL_EMPTY() -#define TAO_PEGTL_INTERNAL_DEFER( X ) X TAO_PEGTL_INTERNAL_EMPTY() -#define TAO_PEGTL_INTERNAL_EXPAND( ... ) __VA_ARGS__ - -#define TAO_PEGTL_INTERNAL_STRING_AT( S, x, n ) tao::TAO_PEGTL_NAMESPACE::internal::string_at< S, ( 0##n < ( sizeof( x ) / sizeof( char ) ) ) ? ( x )[ 0##n ] : 0, ( 0##n < ( sizeof( x ) / sizeof( char ) ) - 1 ) >::type - - -#define TAO_PEGTL_INTERNAL_JOIN_8( M, S, x, n ) tao::TAO_PEGTL_NAMESPACE::internal::string_join< TAO_PEGTL_INTERNAL_DEFER( M )( S, x, n##0 ), TAO_PEGTL_INTERNAL_DEFER( M )( S, x, n##1 ), TAO_PEGTL_INTERNAL_DEFER( M )( S, x, n##2 ), TAO_PEGTL_INTERNAL_DEFER( M )( S, x, n##3 ), TAO_PEGTL_INTERNAL_DEFER( M )( S, x, n##4 ), TAO_PEGTL_INTERNAL_DEFER( M )( S, x, n##5 ), TAO_PEGTL_INTERNAL_DEFER( M )( S, x, n##6 ), TAO_PEGTL_INTERNAL_DEFER( M )( S, x, n##7 ) >::type -#line 74 "tao/pegtl/internal/pegtl_string.hpp" -#define TAO_PEGTL_INTERNAL_STRING_8( S, x, n ) TAO_PEGTL_INTERNAL_JOIN_8( TAO_PEGTL_INTERNAL_STRING_AT, S, x, n ) - - -#define TAO_PEGTL_INTERNAL_STRING_64( S, x, n ) TAO_PEGTL_INTERNAL_JOIN_8( TAO_PEGTL_INTERNAL_STRING_8, S, x, n ) - - -#define TAO_PEGTL_INTERNAL_STRING_512( S, x, n ) TAO_PEGTL_INTERNAL_JOIN_8( TAO_PEGTL_INTERNAL_STRING_64, S, x, n ) - - -#define TAO_PEGTL_INTERNAL_STRING( S, x ) TAO_PEGTL_INTERNAL_EXPAND( TAO_PEGTL_INTERNAL_EXPAND( TAO_PEGTL_INTERNAL_EXPAND( tao::TAO_PEGTL_NAMESPACE::internal::string_max_length< TAO_PEGTL_INTERNAL_STRING_512( S, x, ), sizeof( x ) - 1 >::type ) ) ) - - - - - -#define TAO_PEGTL_STRING( x ) TAO_PEGTL_INTERNAL_STRING( tao::TAO_PEGTL_NAMESPACE::ascii::string, x ) - - -#define TAO_PEGTL_ISTRING( x ) TAO_PEGTL_INTERNAL_STRING( tao::TAO_PEGTL_NAMESPACE::ascii::istring, x ) - - -#define TAO_PEGTL_KEYWORD( x ) TAO_PEGTL_INTERNAL_STRING( tao::TAO_PEGTL_NAMESPACE::ascii::keyword, x ) - - -// Compatibility, remove with 3.0.0 -#define TAOCPP_PEGTL_STRING( x ) TAO_PEGTL_STRING( x ) -#define TAOCPP_PEGTL_ISTRING( x ) TAO_PEGTL_ISTRING( x ) -#define TAOCPP_PEGTL_KEYWORD( x ) TAO_PEGTL_KEYWORD( x ) - -#endif -#line 70 "tao/pegtl/ascii.hpp" - -#endif -#line 13 "tao/pegtl.hpp" -#line 1 "tao/pegtl/rules.hpp" - -#line 1 "tao/pegtl/rules.hpp" - - - -#ifndef TAO_PEGTL_RULES_HPP -#define TAO_PEGTL_RULES_HPP - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - // clang-format off - template< typename... Actions > struct apply : internal::apply< Actions... > {}; - template< typename... Actions > struct apply0 : internal::apply0< Actions... > {}; - template< template< typename... > class Action, typename... Rules > struct action : internal::action< Action, Rules... > {}; - template< typename... Rules > struct at : internal::at< Rules... > {}; - struct bof : internal::bof {}; - struct bol : internal::bol {}; - template< unsigned Num > struct bytes : internal::bytes< Num > {}; - template< template< typename... > class Control, typename... Rules > struct control : internal::control< Control, Rules... > {}; - template< typename... Rules > struct disable : internal::disable< Rules... > {}; - struct discard : internal::discard {}; - template< typename... Rules > struct enable : internal::enable< Rules... > {}; - struct eof : internal::eof {}; - struct failure : internal::trivial< false > {}; - template< typename Rule, typename... Actions > struct if_apply : internal::if_apply< Rule, Actions... > {}; - template< typename Cond, typename... Thens > struct if_must : internal::if_must< false, Cond, Thens... > {}; - template< typename Cond, typename Then, typename Else > struct if_must_else : internal::if_must_else< Cond, Then, Else > {}; - template< typename Cond, typename Then, typename Else > struct if_then_else : internal::if_then_else< Cond, Then, Else > {}; - template< typename Rule, typename Sep, typename Pad = void > struct list : internal::list< Rule, internal::pad< Sep, Pad > > {}; - template< typename Rule, typename Sep > struct list< Rule, Sep, void > : internal::list< Rule, Sep > {}; - template< typename Rule, typename Sep, typename Pad = void > struct list_must : internal::list_must< Rule, internal::pad< Sep, Pad > > {}; - template< typename Rule, typename Sep > struct list_must< Rule, Sep, void > : internal::list_must< Rule, Sep > {}; - template< typename Rule, typename Sep, typename Pad = void > struct list_tail : internal::list_tail_pad< Rule, Sep, Pad > {}; - template< typename Rule, typename Sep > struct list_tail< Rule, Sep, void > : internal::list_tail< Rule, Sep > {}; - template< typename M, typename S > struct minus : internal::rematch< M, internal::not_at< S, internal::eof > > {}; - template< typename... Rules > struct must : internal::must< Rules... > {}; - template< typename... Rules > struct not_at : internal::not_at< Rules... > {}; - template< typename... Rules > struct opt : internal::opt< Rules... > {}; - template< typename Cond, typename... Rules > struct opt_must : internal::if_must< true, Cond, Rules... > {}; - template< typename Rule, typename Pad1, typename Pad2 = Pad1 > struct pad : internal::pad< Rule, Pad1, Pad2 > {}; - template< typename Rule, typename Pad > struct pad_opt : internal::pad_opt< Rule, Pad > {}; - template< typename Rule, typename... Rules > struct plus : internal::plus< Rule, Rules... > {}; - template< typename Exception > struct raise : internal::raise< Exception > {}; - template< typename Head, typename... Rules > struct rematch : internal::rematch< Head, Rules... > {}; - template< unsigned Num, typename... Rules > struct rep : internal::rep< Num, Rules... > {}; - template< unsigned Max, typename... Rules > struct rep_max : internal::rep_min_max< 0, Max, Rules... > {}; - template< unsigned Min, typename Rule, typename... Rules > struct rep_min : internal::rep_min< Min, Rule, Rules... > {}; - template< unsigned Min, unsigned Max, typename... Rules > struct rep_min_max : internal::rep_min_max< Min, Max, Rules... > {}; - template< unsigned Max, typename... Rules > struct rep_opt : internal::rep_opt< Max, Rules... > {}; - template< unsigned Amount > struct require : internal::require< Amount > {}; - template< typename... Rules > struct seq : internal::seq< Rules... > {}; - template< typename... Rules > struct sor : internal::sor< Rules... > {}; - template< typename Rule, typename... Rules > struct star : internal::star< Rule, Rules... > {}; - template< typename Cond, typename... Rules > struct star_must : internal::star_must< Cond, Rules... > {}; - template< typename State, typename... Rules > struct state : internal::state< State, Rules... > {}; - struct success : internal::trivial< true > {}; - template< typename... Rules > struct try_catch : internal::seq< internal::try_catch_type< parse_error, Rules... > > {}; - template< typename Exception, typename... Rules > struct try_catch_type : internal::seq< internal::try_catch_type< Exception, Rules... > > {}; - template< typename Cond, typename... Rules > struct until : internal::until< Cond, Rules... > {}; - // clang-format on - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 14 "tao/pegtl.hpp" -#line 1 "tao/pegtl/uint16.hpp" - -#line 1 "tao/pegtl/uint16.hpp" - - - -#ifndef TAO_PEGTL_UINT16_HPP -#define TAO_PEGTL_UINT16_HPP - - - -#line 1 "tao/pegtl/internal/peek_mask_uint.hpp" - -#line 1 "tao/pegtl/internal/peek_mask_uint.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PEEK_MASK_UINT_HPP -#define TAO_PEGTL_INTERNAL_PEEK_MASK_UINT_HPP - -#include -#include - - - - -#line 1 "tao/pegtl/internal/read_uint.hpp" - -#line 1 "tao/pegtl/internal/read_uint.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_READ_UINT_HPP -#define TAO_PEGTL_INTERNAL_READ_UINT_HPP - -#include - - - -#line 1 "tao/pegtl/internal/endian.hpp" - -#line 1 "tao/pegtl/internal/endian.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ENDIAN_HPP -#define TAO_PEGTL_INTERNAL_ENDIAN_HPP - -#include -#include - - - -#if defined( _WIN32 ) && !defined( __MINGW32__ ) -#line 1 "tao/pegtl/internal/endian_win.hpp" - -#line 1 "tao/pegtl/internal/endian_win.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ENDIAN_WIN_HPP -#define TAO_PEGTL_INTERNAL_ENDIAN_WIN_HPP - -#include -#include - -#include - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< std::size_t S > - struct to_and_from_le - { - template< typename T > - static T convert( const T t ) noexcept - { - return t; - } - }; - - template< std::size_t S > - struct to_and_from_be; - - template<> - struct to_and_from_be< 1 > - { - static std::int8_t convert( const std::int8_t n ) noexcept - { - return n; - } - - static std::uint8_t convert( const std::uint8_t n ) noexcept - { - return n; - } - }; - - template<> - struct to_and_from_be< 2 > - { - static std::int16_t convert( const std::int16_t n ) noexcept - { - return std::int16_t( _byteswap_ushort( std::uint16_t( n ) ) ); - } - - static std::uint16_t convert( const std::uint16_t n ) noexcept - { - return _byteswap_ushort( n ); - } - }; - - template<> - struct to_and_from_be< 4 > - { - static float convert( float n ) noexcept - { - std::uint32_t u; - std::memcpy( &u, &n, 4 ); - u = convert( u ); - std::memcpy( &n, &u, 4 ); - return n; - } - - static std::int32_t convert( const std::int32_t n ) noexcept - { - return std::int32_t( _byteswap_ulong( std::uint32_t( n ) ) ); - } - - static std::uint32_t convert( const std::uint32_t n ) noexcept - { - return _byteswap_ulong( n ); - } - }; - - template<> - struct to_and_from_be< 8 > - { - static double convert( double n ) noexcept - { - std::uint64_t u; - std::memcpy( &u, &n, 8 ); - u = convert( u ); - std::memcpy( &n, &u, 8 ); - return n; - } - - static std::int64_t convert( const std::int64_t n ) noexcept - { - return std::int64_t( _byteswap_uint64( std::uint64_t( n ) ) ); - } - - static std::uint64_t convert( const std::uint64_t n ) noexcept - { - return _byteswap_uint64( n ); - } - }; - -#define TAO_PEGTL_NATIVE_ORDER le -#define TAO_PEGTL_NATIVE_UTF16 utf16_le -#define TAO_PEGTL_NATIVE_UTF32 utf32_le - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 14 "tao/pegtl/internal/endian.hpp" -#else -#line 1 "tao/pegtl/internal/endian_gcc.hpp" - -#line 1 "tao/pegtl/internal/endian_gcc.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ENDIAN_GCC_HPP -#define TAO_PEGTL_INTERNAL_ENDIAN_GCC_HPP - -#include -#include - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { -#if !defined( __BYTE_ORDER__ ) -#error No byte order defined! -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - - template< std::size_t S > - struct to_and_from_be - { - template< typename T > - static T convert( const T n ) noexcept - { - return n; - } - }; - - template< std::size_t S > - struct to_and_from_le; - - template<> - struct to_and_from_le< 1 > - { - static std::uint8_t convert( const std::uint8_t n ) noexcept - { - return n; - } - - static std::int8_t convert( const std::int8_t n ) noexcept - { - return n; - } - }; - - template<> - struct to_and_from_le< 2 > - { - static std::int16_t convert( const std::int16_t n ) noexcept - { - return static_cast< std::int16_t >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) ); - } - - static std::uint16_t convert( const std::uint16_t n ) noexcept - { - return __builtin_bswap16( n ); - } - }; - - template<> - struct to_and_from_le< 4 > - { - static float convert( float n ) noexcept - { - std::uint32_t u; - std::memcpy( &u, &n, 4 ); - u = convert( u ); - std::memcpy( &n, &u, 4 ); - return n; - } - - static std::int32_t convert( const std::int32_t n ) noexcept - { - return static_cast< std::int32_t >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) ); - } - - static std::uint32_t convert( const std::uint32_t n ) noexcept - { - return __builtin_bswap32( n ); - } - }; - - template<> - struct to_and_from_le< 8 > - { - static double convert( double n ) noexcept - { - std::uint64_t u; - std::memcpy( &u, &n, 8 ); - u = convert( u ); - std::memcpy( &n, &u, 8 ); - return n; - } - - static std::int64_t convert( const std::int64_t n ) noexcept - { - return static_cast< std::int64_t >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) ); - } - - static std::uint64_t convert( const std::uint64_t n ) noexcept - { - return __builtin_bswap64( n ); - } - }; - -#define TAO_PEGTL_NATIVE_ORDER be -#define TAO_PEGTL_NATIVE_UTF16 utf16_be -#define TAO_PEGTL_NATIVE_UTF32 utf32_be - -#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - - template< std::size_t S > - struct to_and_from_le - { - template< typename T > - static T convert( const T n ) noexcept - { - return n; - } - }; - - template< std::size_t S > - struct to_and_from_be; - - template<> - struct to_and_from_be< 1 > - { - static std::int8_t convert( const std::int8_t n ) noexcept - { - return n; - } - - static std::uint8_t convert( const std::uint8_t n ) noexcept - { - return n; - } - }; - - template<> - struct to_and_from_be< 2 > - { - static std::int16_t convert( const std::int16_t n ) noexcept - { - return static_cast< std::int16_t >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) ); - } - - static std::uint16_t convert( const std::uint16_t n ) noexcept - { - return __builtin_bswap16( n ); - } - }; - - template<> - struct to_and_from_be< 4 > - { - static float convert( float n ) noexcept - { - std::uint32_t u; - std::memcpy( &u, &n, 4 ); - u = convert( u ); - std::memcpy( &n, &u, 4 ); - return n; - } - - static std::int32_t convert( const std::int32_t n ) noexcept - { - return static_cast< std::int32_t >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) ); - } - - static std::uint32_t convert( const std::uint32_t n ) noexcept - { - return __builtin_bswap32( n ); - } - }; - - template<> - struct to_and_from_be< 8 > - { - static double convert( double n ) noexcept - { - std::uint64_t u; - std::memcpy( &u, &n, 8 ); - u = convert( u ); - std::memcpy( &n, &u, 8 ); - return n; - } - - static std::int64_t convert( const std::int64_t n ) noexcept - { - return static_cast< std::int64_t >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) ); - } - - static std::uint64_t convert( const std::uint64_t n ) noexcept - { - return __builtin_bswap64( n ); - } - }; - -#define TAO_PEGTL_NATIVE_ORDER le -#define TAO_PEGTL_NATIVE_UTF16 utf16_le -#define TAO_PEGTL_NATIVE_UTF32 utf32_le - -#else -#error Unknown host byte order! -#endif - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 16 "tao/pegtl/internal/endian.hpp" -#endif - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename N > - N h_to_be( const N n ) noexcept - { - return N( to_and_from_be< sizeof( N ) >::convert( n ) ); - } - - template< typename N > - N be_to_h( const N n ) noexcept - { - return h_to_be( n ); - } - - template< typename N > - N be_to_h( const void* p ) noexcept - { - N n; - std::memcpy( &n, p, sizeof( n ) ); - return internal::be_to_h( n ); - } - - template< typename N > - N h_to_le( const N n ) noexcept - { - return N( to_and_from_le< sizeof( N ) >::convert( n ) ); - } - - template< typename N > - N le_to_h( const N n ) noexcept - { - return h_to_le( n ); - } - - template< typename N > - N le_to_h( const void* p ) noexcept - { - N n; - std::memcpy( &n, p, sizeof( n ) ); - return internal::le_to_h( n ); - } - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/internal/read_uint.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct read_uint16_be - { - using type = std::uint16_t; - - static std::uint16_t read( const void* d ) noexcept - { - return be_to_h< std::uint16_t >( d ); - } - }; - - struct read_uint16_le - { - using type = std::uint16_t; - - static std::uint16_t read( const void* d ) noexcept - { - return le_to_h< std::uint16_t >( d ); - } - }; - - struct read_uint32_be - { - using type = std::uint32_t; - - static std::uint32_t read( const void* d ) noexcept - { - return be_to_h< std::uint32_t >( d ); - } - }; - - struct read_uint32_le - { - using type = std::uint32_t; - - static std::uint32_t read( const void* d ) noexcept - { - return le_to_h< std::uint32_t >( d ); - } - }; - - struct read_uint64_be - { - using type = std::uint64_t; - - static std::uint64_t read( const void* d ) noexcept - { - return be_to_h< std::uint64_t >( d ); - } - }; - - struct read_uint64_le - { - using type = std::uint64_t; - - static std::uint64_t read( const void* d ) noexcept - { - return le_to_h< std::uint64_t >( d ); - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 14 "tao/pegtl/internal/peek_mask_uint.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename R, typename R::type M > - struct peek_mask_uint_impl - { - using data_t = typename R::type; - using pair_t = input_pair< data_t >; - - template< typename Input > - static pair_t peek( Input& in ) noexcept( noexcept( in.size( sizeof( data_t ) ) ) ) - { - if( in.size( sizeof( data_t ) ) < sizeof( data_t ) ) { - return { 0, 0 }; - } - const data_t data = R::read( in.current() ) & M; - return { data, sizeof( data_t ) }; - } - }; - - template< std::uint16_t M > - using peek_mask_uint16_be = peek_mask_uint_impl< read_uint16_be, M >; - - template< std::uint16_t M > - using peek_mask_uint16_le = peek_mask_uint_impl< read_uint16_le, M >; - - template< std::uint32_t M > - using peek_mask_uint32_be = peek_mask_uint_impl< read_uint32_be, M >; - - template< std::uint32_t M > - using peek_mask_uint32_le = peek_mask_uint_impl< read_uint32_le, M >; - - template< std::uint64_t M > - using peek_mask_uint64_be = peek_mask_uint_impl< read_uint64_be, M >; - - template< std::uint64_t M > - using peek_mask_uint64_le = peek_mask_uint_impl< read_uint64_le, M >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/uint16.hpp" -#line 1 "tao/pegtl/internal/peek_uint.hpp" - -#line 1 "tao/pegtl/internal/peek_uint.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PEEK_UINT_HPP -#define TAO_PEGTL_INTERNAL_PEEK_UINT_HPP - -#include -#include - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename R > - struct peek_uint_impl - { - using data_t = typename R::type; - using pair_t = input_pair< data_t >; - - template< typename Input > - static pair_t peek( Input& in ) noexcept( noexcept( in.size( sizeof( data_t ) ) ) ) - { - if( in.size( sizeof( data_t ) ) < sizeof( data_t ) ) { - return { 0, 0 }; - } - const data_t data = R::read( in.current() ); - return { data, sizeof( data_t ) }; - } - }; - - using peek_uint16_be = peek_uint_impl< read_uint16_be >; - using peek_uint16_le = peek_uint_impl< read_uint16_le >; - - using peek_uint32_be = peek_uint_impl< read_uint32_be >; - using peek_uint32_le = peek_uint_impl< read_uint32_le >; - - using peek_uint64_be = peek_uint_impl< read_uint64_be >; - using peek_uint64_le = peek_uint_impl< read_uint64_le >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 11 "tao/pegtl/uint16.hpp" - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace uint16_be - { - // clang-format off - struct any : internal::any< internal::peek_uint16_be > {}; - - template< std::uint16_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint16_be, Cs... > {}; - template< std::uint16_t Lo, std::uint16_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint16_be, Lo, Hi > {}; - template< std::uint16_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint16_be, Cs... > {}; - template< std::uint16_t Lo, std::uint16_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint16_be, Lo, Hi > {}; - template< std::uint16_t... Cs > struct ranges : internal::ranges< internal::peek_uint16_be, Cs... > {}; - template< std::uint16_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint16_be, Cs >... > {}; - - template< std::uint16_t M, std::uint16_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint16_be< M >, Cs... > {}; - template< std::uint16_t M, std::uint16_t Lo, std::uint16_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint16_be< M >, Lo, Hi > {}; - template< std::uint16_t M, std::uint16_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint16_be< M >, Cs... > {}; - template< std::uint16_t M, std::uint16_t Lo, std::uint16_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint16_be< M >, Lo, Hi > {}; - template< std::uint16_t M, std::uint16_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint16_be< M >, Cs... > {}; - template< std::uint16_t M, std::uint16_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint16_be< M >, Cs >... > {}; - // clang-format on - - } // namespace uint16_be - - namespace uint16_le - { - // clang-format off - struct any : internal::any< internal::peek_uint16_le > {}; - - template< std::uint16_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint16_le, Cs... > {}; - template< std::uint16_t Lo, std::uint16_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint16_le, Lo, Hi > {}; - template< std::uint16_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint16_le, Cs... > {}; - template< std::uint16_t Lo, std::uint16_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint16_le, Lo, Hi > {}; - template< std::uint16_t... Cs > struct ranges : internal::ranges< internal::peek_uint16_le, Cs... > {}; - template< std::uint16_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint16_le, Cs >... > {}; - - template< std::uint16_t M, std::uint16_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint16_le< M >, Cs... > {}; - template< std::uint16_t M, std::uint16_t Lo, std::uint16_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint16_le< M >, Lo, Hi > {}; - template< std::uint16_t M, std::uint16_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint16_le< M >, Cs... > {}; - template< std::uint16_t M, std::uint16_t Lo, std::uint16_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint16_le< M >, Lo, Hi > {}; - template< std::uint16_t M, std::uint16_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint16_le< M >, Cs... > {}; - template< std::uint16_t M, std::uint16_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint16_le< M >, Cs >... > {}; - // clang-format on - - } // namespace uint16_le - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 15 "tao/pegtl.hpp" -#line 1 "tao/pegtl/uint32.hpp" - -#line 1 "tao/pegtl/uint32.hpp" - - - -#ifndef TAO_PEGTL_UINT32_HPP -#define TAO_PEGTL_UINT32_HPP -#line 14 "tao/pegtl/uint32.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace uint32_be - { - // clang-format off - struct any : internal::any< internal::peek_uint32_be > {}; - - template< std::uint32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint32_be, Cs... > {}; - template< std::uint32_t Lo, std::uint32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint32_be, Lo, Hi > {}; - template< std::uint32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint32_be, Cs... > {}; - template< std::uint32_t Lo, std::uint32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint32_be, Lo, Hi > {}; - template< std::uint32_t... Cs > struct ranges : internal::ranges< internal::peek_uint32_be, Cs... > {}; - template< std::uint32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint32_be, Cs >... > {}; - - template< std::uint32_t M, std::uint32_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint32_be< M >, Cs... > {}; - template< std::uint32_t M, std::uint32_t Lo, std::uint32_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint32_be< M >, Lo, Hi > {}; - template< std::uint32_t M, std::uint32_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint32_be< M >, Cs... > {}; - template< std::uint32_t M, std::uint32_t Lo, std::uint32_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint32_be< M >, Lo, Hi > {}; - template< std::uint32_t M, std::uint32_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint32_be< M >, Cs... > {}; - template< std::uint32_t M, std::uint32_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint32_be< M >, Cs >... > {}; - // clang-format on - - } // namespace uint32_be - - namespace uint32_le - { - // clang-format off - struct any : internal::any< internal::peek_uint32_le > {}; - - template< std::uint32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint32_le, Cs... > {}; - template< std::uint32_t Lo, std::uint32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint32_le, Lo, Hi > {}; - template< std::uint32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint32_le, Cs... > {}; - template< std::uint32_t Lo, std::uint32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint32_le, Lo, Hi > {}; - template< std::uint32_t... Cs > struct ranges : internal::ranges< internal::peek_uint32_le, Cs... > {}; - template< std::uint32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint32_le, Cs >... > {}; - - template< std::uint32_t M, std::uint32_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint32_le< M >, Cs... > {}; - template< std::uint32_t M, std::uint32_t Lo, std::uint32_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint32_le< M >, Lo, Hi > {}; - template< std::uint32_t M, std::uint32_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint32_le< M >, Cs... > {}; - template< std::uint32_t M, std::uint32_t Lo, std::uint32_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint32_le< M >, Lo, Hi > {}; - template< std::uint32_t M, std::uint32_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint32_le< M >, Cs... > {}; - template< std::uint32_t M, std::uint32_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint32_le< M >, Cs >... > {}; - // clang-format on - - } // namespace uint32_le - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 16 "tao/pegtl.hpp" -#line 1 "tao/pegtl/uint64.hpp" - -#line 1 "tao/pegtl/uint64.hpp" - - - -#ifndef TAO_PEGTL_UINT64_HPP -#define TAO_PEGTL_UINT64_HPP -#line 14 "tao/pegtl/uint64.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace uint64_be - { - // clang-format off - struct any : internal::any< internal::peek_uint64_be > {}; - - template< std::uint64_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint64_be, Cs... > {}; - template< std::uint64_t Lo, std::uint64_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint64_be, Lo, Hi > {}; - template< std::uint64_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint64_be, Cs... > {}; - template< std::uint64_t Lo, std::uint64_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint64_be, Lo, Hi > {}; - template< std::uint64_t... Cs > struct ranges : internal::ranges< internal::peek_uint64_be, Cs... > {}; - template< std::uint64_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint64_be, Cs >... > {}; - - - template< std::uint64_t M, std::uint64_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint64_be< M >, Cs... > {}; - template< std::uint64_t M, std::uint64_t Lo, std::uint64_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint64_be< M >, Lo, Hi > {}; - template< std::uint64_t M, std::uint64_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint64_be< M >, Cs... > {}; - template< std::uint64_t M, std::uint64_t Lo, std::uint64_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint64_be< M >, Lo, Hi > {}; - template< std::uint64_t M, std::uint64_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint64_be< M >, Cs... > {}; - template< std::uint64_t M, std::uint64_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint64_be< M >, Cs >... > {}; - // clang-format on - - } // namespace uint64_be - - namespace uint64_le - { - // clang-format off - struct any : internal::any< internal::peek_uint64_le > {}; - - template< std::uint64_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint64_le, Cs... > {}; - template< std::uint64_t Lo, std::uint64_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint64_le, Lo, Hi > {}; - template< std::uint64_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint64_le, Cs... > {}; - template< std::uint64_t Lo, std::uint64_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint64_le, Lo, Hi > {}; - template< std::uint64_t... Cs > struct ranges : internal::ranges< internal::peek_uint64_le, Cs... > {}; - template< std::uint64_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint64_le, Cs >... > {}; - - template< std::uint64_t M, std::uint64_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint64_le< M >, Cs... > {}; - template< std::uint64_t M, std::uint64_t Lo, std::uint64_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint64_le< M >, Lo, Hi > {}; - template< std::uint64_t M, std::uint64_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint64_le< M >, Cs... > {}; - template< std::uint64_t M, std::uint64_t Lo, std::uint64_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint64_le< M >, Lo, Hi > {}; - template< std::uint64_t M, std::uint64_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint64_le< M >, Cs... > {}; - template< std::uint64_t M, std::uint64_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint64_le< M >, Cs >... > {}; - // clang-format on - - } // namespace uint64_le - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 17 "tao/pegtl.hpp" -#line 1 "tao/pegtl/uint8.hpp" - -#line 1 "tao/pegtl/uint8.hpp" - - - -#ifndef TAO_PEGTL_UINT8_HPP -#define TAO_PEGTL_UINT8_HPP - - - -#line 1 "tao/pegtl/internal/peek_mask_uint8.hpp" - -#line 1 "tao/pegtl/internal/peek_mask_uint8.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PEEK_MASK_UINT8_HPP -#define TAO_PEGTL_INTERNAL_PEEK_MASK_UINT8_HPP - -#include -#include - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< std::uint8_t M > - struct peek_mask_uint8 - { - using data_t = std::uint8_t; - using pair_t = input_pair< std::uint8_t >; - - template< typename Input > - static pair_t peek( Input& in ) noexcept( noexcept( in.empty() ) ) - { - if( in.empty() ) { - return { 0, 0 }; - } - return { std::uint8_t( in.peek_uint8() & M ), 1 }; - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/uint8.hpp" -#line 1 "tao/pegtl/internal/peek_uint8.hpp" - -#line 1 "tao/pegtl/internal/peek_uint8.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PEEK_UINT8_HPP -#define TAO_PEGTL_INTERNAL_PEEK_UINT8_HPP - -#include -#include - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct peek_uint8 - { - using data_t = std::uint8_t; - using pair_t = input_pair< std::uint8_t >; - - template< typename Input > - static pair_t peek( Input& in ) noexcept( noexcept( in.empty() ) ) - { - if( in.empty() ) { - return { 0, 0 }; - } - return { in.peek_uint8(), 1 }; - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 11 "tao/pegtl/uint8.hpp" - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace uint8 - { - // clang-format off - struct any : internal::any< internal::peek_uint8 > {}; - - template< std::uint8_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint8, Cs... > {}; - template< std::uint8_t Lo, std::uint8_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint8, Lo, Hi > {}; - template< std::uint8_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint8, Cs... > {}; - template< std::uint8_t Lo, std::uint8_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_uint8, Lo, Hi > {}; - template< std::uint8_t... Cs > struct ranges : internal::ranges< internal::peek_uint8, Cs... > {}; - template< std::uint8_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint8, Cs >... > {}; - - template< std::uint8_t M, std::uint8_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint8< M >, Cs... > {}; - template< std::uint8_t M, std::uint8_t Lo, std::uint8_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint8< M >, Lo, Hi > {}; - template< std::uint8_t M, std::uint8_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint8< M >, Cs... > {}; - template< std::uint8_t M, std::uint8_t Lo, std::uint8_t Hi > struct mask_range : internal::range< internal::result_on_found::success, internal::peek_mask_uint8< M >, Lo, Hi > {}; - template< std::uint8_t M, std::uint8_t... Cs > struct mask_ranges : internal::ranges< internal::peek_mask_uint8< M >, Cs... > {}; - template< std::uint8_t M, std::uint8_t... Cs > struct mask_string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_mask_uint8< M >, Cs >... > {}; - // clang-format on - - } // namespace uint8 - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 18 "tao/pegtl.hpp" -#line 1 "tao/pegtl/utf16.hpp" - -#line 1 "tao/pegtl/utf16.hpp" - - - -#ifndef TAO_PEGTL_UTF16_HPP -#define TAO_PEGTL_UTF16_HPP - - - -#line 1 "tao/pegtl/internal/peek_utf16.hpp" - -#line 1 "tao/pegtl/internal/peek_utf16.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PEEK_UTF16_HPP -#define TAO_PEGTL_INTERNAL_PEEK_UTF16_HPP - -#include - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename R > - struct peek_utf16_impl - { - using data_t = char32_t; - using pair_t = input_pair< char32_t >; - - using short_t = std::make_unsigned< char16_t >::type; - - static_assert( sizeof( short_t ) == 2, "expected size 2 for 16bit value" ); - static_assert( sizeof( char16_t ) == 2, "expected size 2 for 16bit value" ); - - template< typename Input > - static pair_t peek( Input& in ) noexcept( noexcept( in.size( 4 ) ) ) - { - if( in.size( 2 ) < 2 ) { - return { 0, 0 }; - } - const char32_t t = R::read( in.current() ); - if( ( t < 0xd800 ) || ( t > 0xdfff ) ) { - return { t, 2 }; - } - if( ( t >= 0xdc00 ) || ( in.size( 4 ) < 4 ) ) { - return { 0, 0 }; - } - const char32_t u = R::read( in.current() + 2 ); - if( ( u >= 0xdc00 ) && ( u <= 0xdfff ) ) { - const auto cp = ( ( ( t & 0x03ff ) << 10 ) | ( u & 0x03ff ) ) + 0x10000; - return { cp, 4 }; - } - return { 0, 0 }; - } - }; - - using peek_utf16_be = peek_utf16_impl< read_uint16_be >; - using peek_utf16_le = peek_utf16_impl< read_uint16_le >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/utf16.hpp" - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace utf16_be - { - // clang-format off - struct any : internal::any< internal::peek_utf16_be > {}; - struct bom : internal::one< internal::result_on_found::success, internal::peek_utf16_be, 0xfeff > {}; - template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf16_be, Cs... > {}; - template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf16_be, Lo, Hi > {}; - template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf16_be, Cs... > {}; - template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_utf16_be, Lo, Hi > {}; - template< char32_t... Cs > struct ranges : internal::ranges< internal::peek_utf16_be, Cs... > {}; - template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_utf16_be, Cs >... > {}; - // clang-format on - - } // namespace utf16_be - - namespace utf16_le - { - // clang-format off - struct any : internal::any< internal::peek_utf16_le > {}; - struct bom : internal::one< internal::result_on_found::success, internal::peek_utf16_le, 0xfeff > {}; - template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf16_le, Cs... > {}; - template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf16_le, Lo, Hi > {}; - template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf16_le, Cs... > {}; - template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_utf16_le, Lo, Hi > {}; - template< char32_t... Cs > struct ranges : internal::ranges< internal::peek_utf16_le, Cs... > {}; - template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_utf16_le, Cs >... > {}; - // clang-format on - - } // namespace utf16_le - - namespace utf16 = TAO_PEGTL_NATIVE_UTF16; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 19 "tao/pegtl.hpp" -#line 1 "tao/pegtl/utf32.hpp" - -#line 1 "tao/pegtl/utf32.hpp" - - - -#ifndef TAO_PEGTL_UTF32_HPP -#define TAO_PEGTL_UTF32_HPP - - - -#line 1 "tao/pegtl/internal/peek_utf32.hpp" - -#line 1 "tao/pegtl/internal/peek_utf32.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PEEK_UTF32_HPP -#define TAO_PEGTL_INTERNAL_PEEK_UTF32_HPP - -#include - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename R > - struct peek_utf32_impl - { - using data_t = char32_t; - using pair_t = input_pair< char32_t >; - - static_assert( sizeof( char32_t ) == 4, "expected size 4 for 32bit value" ); - - template< typename Input > - static pair_t peek( Input& in ) noexcept( noexcept( in.size( 4 ) ) ) - { - if( in.size( 4 ) < 4 ) { - return { 0, 0 }; - } - const char32_t t = R::read( in.current() ); - if( ( t <= 0x10ffff ) && !( t >= 0xd800 && t <= 0xdfff ) ) { - return { t, 4 }; - } - return { 0, 0 }; - } - }; - - using peek_utf32_be = peek_utf32_impl< read_uint32_be >; - using peek_utf32_le = peek_utf32_impl< read_uint32_le >; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/utf32.hpp" - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace utf32_be - { - // clang-format off - struct any : internal::any< internal::peek_utf32_be > {}; - struct bom : internal::one< internal::result_on_found::success, internal::peek_utf32_be, 0xfeff > {}; - template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf32_be, Cs... > {}; - template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf32_be, Lo, Hi > {}; - template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf32_be, Cs... > {}; - template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_utf32_be, Lo, Hi > {}; - template< char32_t... Cs > struct ranges : internal::ranges< internal::peek_utf32_be, Cs... > {}; - template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_utf32_be, Cs >... > {}; - // clang-format on - - } // namespace utf32_be - - namespace utf32_le - { - // clang-format off - struct any : internal::any< internal::peek_utf32_le > {}; - struct bom : internal::one< internal::result_on_found::success, internal::peek_utf32_le, 0xfeff > {}; - template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf32_le, Cs... > {}; - template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf32_le, Lo, Hi > {}; - template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf32_le, Cs... > {}; - template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_utf32_le, Lo, Hi > {}; - template< char32_t... Cs > struct ranges : internal::ranges< internal::peek_utf32_le, Cs... > {}; - template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_utf32_le, Cs >... > {}; - // clang-format on - - } // namespace utf32_le - - namespace utf32 = TAO_PEGTL_NATIVE_UTF32; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 20 "tao/pegtl.hpp" -#line 1 "tao/pegtl/utf8.hpp" - -#line 1 "tao/pegtl/utf8.hpp" - - - -#ifndef TAO_PEGTL_UTF8_HPP -#define TAO_PEGTL_UTF8_HPP - - - -#line 1 "tao/pegtl/internal/peek_utf8.hpp" - -#line 1 "tao/pegtl/internal/peek_utf8.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_PEEK_UTF8_HPP -#define TAO_PEGTL_INTERNAL_PEEK_UTF8_HPP - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct peek_utf8 - { - using data_t = char32_t; - using pair_t = input_pair< char32_t >; - - template< typename Input > - static pair_t peek( Input& in ) noexcept( noexcept( in.empty() ) ) - { - if( in.empty() ) { - return { 0, 0 }; - } - char32_t c0 = in.peek_uint8(); - if( ( c0 & 0x80 ) == 0 ) { - return { c0, 1 }; - } - return peek_impl( in, c0 ); - } - - private: - template< typename Input > - static pair_t peek_impl( Input& in, char32_t c0 ) noexcept( noexcept( in.size( 4 ) ) ) - { - if( ( c0 & 0xE0 ) == 0xC0 ) { - if( in.size( 2 ) >= 2 ) { - const char32_t c1 = in.peek_uint8( 1 ); - if( ( c1 & 0xC0 ) == 0x80 ) { - c0 &= 0x1F; - c0 <<= 6; - c0 |= ( c1 & 0x3F ); - if( c0 >= 0x80 ) { - return { c0, 2 }; - } - } - } - } - else if( ( c0 & 0xF0 ) == 0xE0 ) { - if( in.size( 3 ) >= 3 ) { - const char32_t c1 = in.peek_uint8( 1 ); - const char32_t c2 = in.peek_uint8( 2 ); - if( ( ( c1 & 0xC0 ) == 0x80 ) && ( ( c2 & 0xC0 ) == 0x80 ) ) { - c0 &= 0x0F; - c0 <<= 6; - c0 |= ( c1 & 0x3F ); - c0 <<= 6; - c0 |= ( c2 & 0x3F ); - if( c0 >= 0x800 && !( c0 >= 0xD800 && c0 <= 0xDFFF ) ) { - return { c0, 3 }; - } - } - } - } - else if( ( c0 & 0xF8 ) == 0xF0 ) { - if( in.size( 4 ) >= 4 ) { - const char32_t c1 = in.peek_uint8( 1 ); - const char32_t c2 = in.peek_uint8( 2 ); - const char32_t c3 = in.peek_uint8( 3 ); - if( ( ( c1 & 0xC0 ) == 0x80 ) && ( ( c2 & 0xC0 ) == 0x80 ) && ( ( c3 & 0xC0 ) == 0x80 ) ) { - c0 &= 0x07; - c0 <<= 6; - c0 |= ( c1 & 0x3F ); - c0 <<= 6; - c0 |= ( c2 & 0x3F ); - c0 <<= 6; - c0 |= ( c3 & 0x3F ); - if( c0 >= 0x10000 && c0 <= 0x10FFFF ) { - return { c0, 4 }; - } - } - } - } - return { 0, 0 }; - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/utf8.hpp" - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace utf8 - { - // clang-format off - struct any : internal::any< internal::peek_utf8 > {}; - struct bom : internal::one< internal::result_on_found::success, internal::peek_utf8, 0xfeff > {}; - template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf8, Cs... > {}; - template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf8, Lo, Hi > {}; - template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf8, Cs... > {}; - template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_utf8, Lo, Hi > {}; - template< char32_t... Cs > struct ranges : internal::ranges< internal::peek_utf8, Cs... > {}; - template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_utf8, Cs >... > {}; - // clang-format on - - } // namespace utf8 - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 21 "tao/pegtl.hpp" - -#line 1 "tao/pegtl/argv_input.hpp" - -#line 1 "tao/pegtl/argv_input.hpp" - - - -#ifndef TAO_PEGTL_ARGV_INPUT_HPP -#define TAO_PEGTL_ARGV_INPUT_HPP - -#include -#include -#include -#include - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - inline std::string make_argv_source( const std::size_t argn ) - { - std::ostringstream os; - os << "argv[" << argn << ']'; - return os.str(); - } - - } // namespace internal - - template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > - struct argv_input - : public memory_input< P, Eol > - { - template< typename T > - argv_input( char** argv, const std::size_t argn, T&& in_source ) - : memory_input< P, Eol >( static_cast< const char* >( argv[ argn ] ), std::forward< T >( in_source ) ) - { - } - - argv_input( char** argv, const std::size_t argn ) - : argv_input( argv, argn, internal::make_argv_source( argn ) ) - { - } - }; - -#ifdef __cpp_deduction_guides - template< typename... Ts > - argv_input( Ts&&... )->argv_input<>; -#endif - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 23 "tao/pegtl.hpp" -#line 1 "tao/pegtl/buffer_input.hpp" - -#line 1 "tao/pegtl/buffer_input.hpp" - - - -#ifndef TAO_PEGTL_BUFFER_INPUT_HPP -#define TAO_PEGTL_BUFFER_INPUT_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#line 27 "tao/pegtl/buffer_input.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< typename Reader, typename Eol = eol::lf_crlf, typename Source = std::string, std::size_t Chunk = 64 > - class buffer_input - { - public: - using reader_t = Reader; - - using eol_t = Eol; - using source_t = Source; - - using iterator_t = internal::iterator; - - using action_t = internal::action_input< buffer_input >; - - static constexpr std::size_t chunk_size = Chunk; - static constexpr tracking_mode tracking_mode_v = tracking_mode::eager; - - template< typename T, typename... As > - buffer_input( T&& in_source, const std::size_t maximum, As&&... as ) - : m_reader( std::forward< As >( as )... ), - m_maximum( maximum + Chunk ), - m_buffer( new char[ maximum + Chunk ] ), - m_current( m_buffer.get() ), - m_end( m_buffer.get() ), - m_source( std::forward< T >( in_source ) ) - { - static_assert( Chunk != 0, "zero chunk size not implemented" ); - assert( m_maximum > maximum ); // Catches overflow; change to >= when zero chunk size is implemented. - } - - buffer_input( const buffer_input& ) = delete; - buffer_input( buffer_input&& ) = delete; - - ~buffer_input() = default; - - void operator=( const buffer_input& ) = delete; - void operator=( buffer_input&& ) = delete; - - bool empty() - { - require( 1 ); - return m_current.data == m_end; - } - - std::size_t size( const std::size_t amount ) - { - require( amount ); - return buffer_occupied(); - } - - const char* current() const noexcept - { - return m_current.data; - } - - const char* end( const std::size_t amount ) - { - require( amount ); - return m_end; - } - - std::size_t byte() const noexcept - { - return m_current.byte; - } - - std::size_t line() const noexcept - { - return m_current.line; - } - - std::size_t byte_in_line() const noexcept - { - return m_current.byte_in_line; - } - - const Source& source() const noexcept - { - return m_source; - } - - char peek_char( const std::size_t offset = 0 ) const noexcept - { - return m_current.data[ offset ]; - } - - std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept - { - return static_cast< std::uint8_t >( peek_char( offset ) ); - } - - // Compatibility, remove with 3.0.0 - std::uint8_t peek_byte( const std::size_t offset = 0 ) const noexcept - { - return static_cast< std::uint8_t >( peek_char( offset ) ); - } - - void bump( const std::size_t in_count = 1 ) noexcept - { - internal::bump( m_current, in_count, Eol::ch ); - } - - void bump_in_this_line( const std::size_t in_count = 1 ) noexcept - { - internal::bump_in_this_line( m_current, in_count ); - } - - void bump_to_next_line( const std::size_t in_count = 1 ) noexcept - { - internal::bump_to_next_line( m_current, in_count ); - } - - void discard() noexcept - { - if( m_current.data > m_buffer.get() + Chunk ) { - const auto s = m_end - m_current.data; - std::memmove( m_buffer.get(), m_current.data, s ); - m_current.data = m_buffer.get(); - m_end = m_buffer.get() + s; - } - } - - void require( const std::size_t amount ) - { - if( m_current.data + amount <= m_end ) { - return; - } - if( m_current.data + amount > m_buffer.get() + m_maximum ) { - throw std::overflow_error( "require beyond end of buffer" ); - } - if( const auto r = m_reader( m_end, ( std::min )( buffer_free_after_end(), ( std::max )( amount - buffer_occupied(), Chunk ) ) ) ) { - m_end += r; - } - } - - template< rewind_mode M > - internal::marker< iterator_t, M > mark() noexcept - { - return internal::marker< iterator_t, M >( m_current ); - } - - TAO_PEGTL_NAMESPACE::position position( const iterator_t& it ) const - { - return TAO_PEGTL_NAMESPACE::position( it, m_source ); - } - - TAO_PEGTL_NAMESPACE::position position() const - { - return position( m_current ); - } - - const iterator_t& iterator() const noexcept - { - return m_current; - } - - std::size_t buffer_capacity() const noexcept - { - return m_maximum; - } - - std::size_t buffer_occupied() const noexcept - { - assert( m_end >= m_current.data ); - return std::size_t( m_end - m_current.data ); - } - - std::size_t buffer_free_before_current() const noexcept - { - assert( m_current.data >= m_buffer.get() ); - return std::size_t( m_current.data - m_buffer.get() ); - } - - std::size_t buffer_free_after_end() const noexcept - { - assert( m_buffer.get() + m_maximum >= m_end ); - return std::size_t( m_buffer.get() + m_maximum - m_end ); - } - - private: - Reader m_reader; - std::size_t m_maximum; - std::unique_ptr< char[] > m_buffer; // NOLINT - iterator_t m_current; - char* m_end; - const Source m_source; - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 24 "tao/pegtl.hpp" -#line 1 "tao/pegtl/cstream_input.hpp" - -#line 1 "tao/pegtl/cstream_input.hpp" - - - -#ifndef TAO_PEGTL_CSTREAM_INPUT_HPP -#define TAO_PEGTL_CSTREAM_INPUT_HPP - -#include - - - - - -#line 1 "tao/pegtl/internal/cstream_reader.hpp" - -#line 1 "tao/pegtl/internal/cstream_reader.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_CSTREAM_READER_HPP -#define TAO_PEGTL_INTERNAL_CSTREAM_READER_HPP - -#include -#include -#include - - -#line 1 "tao/pegtl/internal/../input_error.hpp" - -#line 1 "tao/pegtl/internal/../input_error.hpp" - - - -#ifndef TAO_PEGTL_INPUT_ERROR_HPP -#define TAO_PEGTL_INPUT_ERROR_HPP - -#include -#include -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - struct input_error - : std::runtime_error - { - input_error( const std::string& message, const int in_errorno ) - : std::runtime_error( message ), - errorno( in_errorno ) - { - } - - int errorno; - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#define TAO_PEGTL_INTERNAL_UNWRAP( ... ) __VA_ARGS__ - -#define TAO_PEGTL_THROW_INPUT_ERROR( MESSAGE ) do { const int errorno = errno; std::ostringstream oss; oss << "pegtl: " << TAO_PEGTL_INTERNAL_UNWRAP( MESSAGE ) << " errno " << errorno; throw tao::TAO_PEGTL_NAMESPACE::input_error( oss.str(), errorno ); } while( false ) - - - - - - - -#define TAO_PEGTL_THROW_INPUT_WIN32_ERROR( MESSAGE ) do { const int errorno = GetLastError(); std::ostringstream oss; oss << "pegtl: " << TAO_PEGTL_INTERNAL_UNWRAP( MESSAGE ) << " GetLastError() " << errorno; throw tao::TAO_PEGTL_NAMESPACE::input_error( oss.str(), errorno ); } while( false ) - - - - - - - -#endif -#line 13 "tao/pegtl/internal/cstream_reader.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct cstream_reader - { - explicit cstream_reader( std::FILE* s ) noexcept - : m_cstream( s ) - { - assert( m_cstream != nullptr ); - } - - std::size_t operator()( char* buffer, const std::size_t length ) const - { - if( const auto r = std::fread( buffer, 1, length, m_cstream ) ) { - return r; - } - if( std::feof( m_cstream ) != 0 ) { - return 0; - } - // Please contact us if you know how to provoke the following exception. - // The example on cppreference.com doesn't work, at least not on macOS. - TAO_PEGTL_THROW_INPUT_ERROR( "error in fread() from cstream" ); // LCOV_EXCL_LINE - } - - std::FILE* m_cstream; - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 14 "tao/pegtl/cstream_input.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< typename Eol = eol::lf_crlf, std::size_t Chunk = 64 > - struct cstream_input - : buffer_input< internal::cstream_reader, Eol, std::string, Chunk > - { - template< typename T > - cstream_input( std::FILE* in_stream, const std::size_t in_maximum, T&& in_source ) - : buffer_input< internal::cstream_reader, Eol, std::string, Chunk >( std::forward< T >( in_source ), in_maximum, in_stream ) - { - } - }; - -#ifdef __cpp_deduction_guides - template< typename... Ts > - cstream_input( Ts&&... )->cstream_input<>; -#endif - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 25 "tao/pegtl.hpp" -#line 1 "tao/pegtl/istream_input.hpp" - -#line 1 "tao/pegtl/istream_input.hpp" - - - -#ifndef TAO_PEGTL_ISTREAM_INPUT_HPP -#define TAO_PEGTL_ISTREAM_INPUT_HPP - -#include - - - - - -#line 1 "tao/pegtl/internal/istream_reader.hpp" - -#line 1 "tao/pegtl/internal/istream_reader.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_ISTREAM_READER_HPP -#define TAO_PEGTL_INTERNAL_ISTREAM_READER_HPP - -#include - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct istream_reader - { - explicit istream_reader( std::istream& s ) noexcept - : m_istream( s ) - { - } - - std::size_t operator()( char* buffer, const std::size_t length ) - { - m_istream.read( buffer, std::streamsize( length ) ); - - if( const auto r = m_istream.gcount() ) { - return std::size_t( r ); - } - if( m_istream.eof() ) { - return 0; - } - TAO_PEGTL_THROW_INPUT_ERROR( "error in istream.read()" ); - } - - std::istream& m_istream; - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 14 "tao/pegtl/istream_input.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< typename Eol = eol::lf_crlf, std::size_t Chunk = 64 > - struct istream_input - : buffer_input< internal::istream_reader, Eol, std::string, Chunk > - { - template< typename T > - istream_input( std::istream& in_stream, const std::size_t in_maximum, T&& in_source ) - : buffer_input< internal::istream_reader, Eol, std::string, Chunk >( std::forward< T >( in_source ), in_maximum, in_stream ) - { - } - }; - -#ifdef __cpp_deduction_guides - template< typename... Ts > - istream_input( Ts&&... )->istream_input<>; -#endif - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 26 "tao/pegtl.hpp" - -#line 1 "tao/pegtl/read_input.hpp" - -#line 1 "tao/pegtl/read_input.hpp" - - - -#ifndef TAO_PEGTL_READ_INPUT_HPP -#define TAO_PEGTL_READ_INPUT_HPP - -#include - - - -#line 1 "tao/pegtl/string_input.hpp" - -#line 1 "tao/pegtl/string_input.hpp" - - - -#ifndef TAO_PEGTL_STRING_INPUT_HPP -#define TAO_PEGTL_STRING_INPUT_HPP - -#include -#include - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct string_holder - { - const std::string data; - - template< typename T > - explicit string_holder( T&& in_data ) - : data( std::forward< T >( in_data ) ) - { - } - - string_holder( const string_holder& ) = delete; - string_holder( string_holder&& ) = delete; - - ~string_holder() = default; - - void operator=( const string_holder& ) = delete; - void operator=( string_holder&& ) = delete; - }; - - } // namespace internal - - template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf, typename Source = std::string > - struct string_input - : private internal::string_holder, - public memory_input< P, Eol, Source > - { - template< typename V, typename T, typename... Ts > - explicit string_input( V&& in_data, T&& in_source, Ts&&... ts ) - : internal::string_holder( std::forward< V >( in_data ) ), - memory_input< P, Eol, Source >( data.data(), data.size(), std::forward< T >( in_source ), std::forward< Ts >( ts )... ) - { - } - - string_input( const string_input& ) = delete; - string_input( string_input&& ) = delete; - - ~string_input() = default; - - void operator=( const string_input& ) = delete; - void operator=( string_input&& ) = delete; - }; - -#ifdef __cpp_deduction_guides - template< typename... Ts > - explicit string_input( Ts&&... )->string_input<>; -#endif - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "tao/pegtl/read_input.hpp" - - -#line 1 "tao/pegtl/internal/file_reader.hpp" - -#line 1 "tao/pegtl/internal/file_reader.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_FILE_READER_HPP -#define TAO_PEGTL_INTERNAL_FILE_READER_HPP - -#include -#include -#include -#include - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - inline std::FILE* file_open( const char* filename ) - { - errno = 0; -#if defined( _MSC_VER ) - std::FILE* file; - if( ::fopen_s( &file, filename, "rb" ) == 0 ) -#elif defined( __MINGW32__ ) - if( auto* file = std::fopen( filename, "rb" ) ) // NOLINT -#else - if( auto* file = std::fopen( filename, "rbe" ) ) // NOLINT -#endif - { - return file; - } - TAO_PEGTL_THROW_INPUT_ERROR( "unable to fopen() file " << filename << " for reading" ); - } - - struct file_close - { - void operator()( FILE* f ) const noexcept - { - std::fclose( f ); // NOLINT - } - }; - - class file_reader - { - public: - explicit file_reader( const char* filename ) - : m_source( filename ), - m_file( file_open( m_source ) ) - { - } - - file_reader( FILE* file, const char* filename ) noexcept - : m_source( filename ), - m_file( file ) - { - } - - file_reader( const file_reader& ) = delete; - file_reader( file_reader&& ) = delete; - - ~file_reader() = default; - - void operator=( const file_reader& ) = delete; - void operator=( file_reader&& ) = delete; - - std::size_t size() const - { - errno = 0; - if( std::fseek( m_file.get(), 0, SEEK_END ) != 0 ) { - TAO_PEGTL_THROW_INPUT_ERROR( "unable to fseek() to end of file " << m_source ); // LCOV_EXCL_LINE - } - errno = 0; - const auto s = std::ftell( m_file.get() ); - if( s < 0 ) { - TAO_PEGTL_THROW_INPUT_ERROR( "unable to ftell() file size of file " << m_source ); // LCOV_EXCL_LINE - } - errno = 0; - if( std::fseek( m_file.get(), 0, SEEK_SET ) != 0 ) { - TAO_PEGTL_THROW_INPUT_ERROR( "unable to fseek() to beginning of file " << m_source ); // LCOV_EXCL_LINE - } - return std::size_t( s ); - } - - std::string read() const - { - std::string nrv; - nrv.resize( size() ); - errno = 0; - if( !nrv.empty() && ( std::fread( &nrv[ 0 ], nrv.size(), 1, m_file.get() ) != 1 ) ) { - TAO_PEGTL_THROW_INPUT_ERROR( "unable to fread() file " << m_source << " size " << nrv.size() ); // LCOV_EXCL_LINE - } - return nrv; - } - - private: - const char* const m_source; - const std::unique_ptr< std::FILE, file_close > m_file; - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 15 "tao/pegtl/read_input.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct filename_holder - { - const std::string filename; - - template< typename T > - explicit filename_holder( T&& in_filename ) - : filename( std::forward< T >( in_filename ) ) - { - } - - filename_holder( const filename_holder& ) = delete; - filename_holder( filename_holder&& ) = delete; - - ~filename_holder() = default; - - void operator=( const filename_holder& ) = delete; - void operator=( filename_holder&& ) = delete; - }; - - } // namespace internal - - template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > - struct read_input - : private internal::filename_holder, - public string_input< P, Eol, const char* > - { - template< typename T > - explicit read_input( T&& in_filename ) - : internal::filename_holder( std::forward< T >( in_filename ) ), - string_input< P, Eol, const char* >( internal::file_reader( filename.c_str() ).read(), filename.c_str() ) - { - } - - template< typename T > - read_input( FILE* in_file, T&& in_filename ) - : internal::filename_holder( std::forward< T >( in_filename ) ), - string_input< P, Eol, const char* >( internal::file_reader( in_file, filename.c_str() ).read(), filename.c_str() ) - { - } - - read_input( const read_input& ) = delete; - read_input( read_input&& ) = delete; - - ~read_input() = default; - - void operator=( const read_input& ) = delete; - void operator=( read_input&& ) = delete; - }; - -#ifdef __cpp_deduction_guides - template< typename... Ts > - explicit read_input( Ts&&... )->read_input<>; -#endif - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 28 "tao/pegtl.hpp" - - -// this has to be included *after* the above inputs, -// otherwise the amalgamated header will not work! -#line 1 "tao/pegtl/file_input.hpp" - -#line 1 "tao/pegtl/file_input.hpp" - - - -#ifndef TAO_PEGTL_FILE_INPUT_HPP -#define TAO_PEGTL_FILE_INPUT_HPP - - - - - -#if defined( __unix__ ) || ( defined( __APPLE__ ) && defined( __MACH__ ) ) -#include // Required for _POSIX_MAPPED_FILES -#endif - -#if defined( _POSIX_MAPPED_FILES ) || defined( _WIN32 ) -#line 1 "tao/pegtl/mmap_input.hpp" - -#line 1 "tao/pegtl/mmap_input.hpp" - - - -#ifndef TAO_PEGTL_MMAP_INPUT_HPP -#define TAO_PEGTL_MMAP_INPUT_HPP - -#include -#include - - - - - - -#if defined( __unix__ ) || ( defined( __APPLE__ ) && defined( __MACH__ ) ) -#include // Required for _POSIX_MAPPED_FILES -#endif - -#if defined( _POSIX_MAPPED_FILES ) -#line 1 "tao/pegtl/internal/file_mapper_posix.hpp" - -#line 1 "tao/pegtl/internal/file_mapper_posix.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_FILE_MAPPER_POSIX_HPP -#define TAO_PEGTL_INTERNAL_FILE_MAPPER_POSIX_HPP - -#include -#include - - - -#line 1 "tao/pegtl/internal/file_opener.hpp" - -#line 1 "tao/pegtl/internal/file_opener.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_FILE_OPENER_HPP -#define TAO_PEGTL_INTERNAL_FILE_OPENER_HPP - -#include -#include -#include -#include - -#include - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct file_opener - { - explicit file_opener( const char* filename ) - : m_source( filename ), - m_fd( open() ) - { - } - - file_opener( const file_opener& ) = delete; - file_opener( file_opener&& ) = delete; - - ~file_opener() noexcept - { - ::close( m_fd ); - } - - void operator=( const file_opener& ) = delete; - void operator=( file_opener&& ) = delete; - - std::size_t size() const - { - struct stat st; // NOLINT - errno = 0; - if( ::fstat( m_fd, &st ) < 0 ) { - TAO_PEGTL_THROW_INPUT_ERROR( "unable to fstat() file " << m_source << " descriptor " << m_fd ); - } - return std::size_t( st.st_size ); - } - - const char* const m_source; - const int m_fd; - - private: - int open() const - { - errno = 0; - const int fd = ::open( m_source, // NOLINT - O_RDONLY -#ifdef O_CLOEXEC - | O_CLOEXEC -#endif - ); - if( fd >= 0 ) { - return fd; - } - TAO_PEGTL_THROW_INPUT_ERROR( "unable to open() file " << m_source << " for reading" ); - } - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 13 "tao/pegtl/internal/file_mapper_posix.hpp" - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - class file_mapper - { - public: - explicit file_mapper( const char* filename ) - : file_mapper( file_opener( filename ) ) - { - } - - explicit file_mapper( const file_opener& reader ) - : m_size( reader.size() ), - m_data( static_cast< const char* >( ::mmap( nullptr, m_size, PROT_READ, MAP_PRIVATE, reader.m_fd, 0 ) ) ) - { - if( ( m_size != 0 ) && ( intptr_t( m_data ) == -1 ) ) { - TAO_PEGTL_THROW_INPUT_ERROR( "unable to mmap() file " << reader.m_source << " descriptor " << reader.m_fd ); - } - } - - file_mapper( const file_mapper& ) = delete; - file_mapper( file_mapper&& ) = delete; - - ~file_mapper() noexcept - { - // Legacy C interface requires pointer-to-mutable but does not write through the pointer. - ::munmap( const_cast< char* >( m_data ), m_size ); // NOLINT - } - - void operator=( const file_mapper& ) = delete; - void operator=( file_mapper&& ) = delete; - - bool empty() const noexcept - { - return m_size == 0; - } - - std::size_t size() const noexcept - { - return m_size; - } - - using iterator = const char*; - using const_iterator = const char*; - - iterator data() const noexcept - { - return m_data; - } - - iterator begin() const noexcept - { - return m_data; - } - - iterator end() const noexcept - { - return m_data + m_size; - } - - std::string string() const - { - return std::string( m_data, m_size ); - } - - private: - const std::size_t m_size; - const char* const m_data; - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 21 "tao/pegtl/mmap_input.hpp" -#elif defined( _WIN32 ) -#line 1 "tao/pegtl/internal/file_mapper_win32.hpp" - -#line 1 "tao/pegtl/internal/file_mapper_win32.hpp" - - - -#ifndef TAO_PEGTL_INTERNAL_FILE_MAPPER_WIN32_HPP -#define TAO_PEGTL_INTERNAL_FILE_MAPPER_WIN32_HPP - -#if !defined( NOMINMAX ) -#define NOMINMAX -#define TAO_PEGTL_NOMINMAX_WAS_DEFINED -#endif - -#if !defined( WIN32_LEAN_AND_MEAN ) -#define WIN32_LEAN_AND_MEAN -#define TAO_PEGTL_WIN32_LEAN_AND_MEAN_WAS_DEFINED -#endif - -#include - -#if defined( TAO_PEGTL_NOMINMAX_WAS_DEFINED ) -#undef NOMINMAX -#undef TAO_PEGTL_NOMINMAX_WAS_DEFINED -#endif - -#if defined( TAO_PEGTL_WIN32_LEAN_AND_MEAN_WAS_DEFINED ) -#undef WIN32_LEAN_AND_MEAN -#undef TAO_PEGTL_WIN32_LEAN_AND_MEAN_WAS_DEFINED -#endif - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct win32_file_opener - { - explicit win32_file_opener( const char* filename ) - : m_source( filename ), - m_handle( open() ) - { - } - - win32_file_opener( const win32_file_opener& ) = delete; - win32_file_opener( win32_file_opener&& ) = delete; - - ~win32_file_opener() noexcept - { - ::CloseHandle( m_handle ); - } - - void operator=( const win32_file_opener& ) = delete; - void operator=( win32_file_opener&& ) = delete; - - std::size_t size() const - { - LARGE_INTEGER size; - if( !::GetFileSizeEx( m_handle, &size ) ) { - TAO_PEGTL_THROW_INPUT_WIN32_ERROR( "unable to GetFileSizeEx() file " << m_source << " handle " << m_handle ); - } - return std::size_t( size.QuadPart ); - } - - const char* const m_source; - const HANDLE m_handle; - - private: - HANDLE open() const - { - SetLastError( 0 ); - std::wstring ws( m_source, m_source + strlen( m_source ) ); - -#if( _WIN32_WINNT >= 0x0602 ) - const HANDLE handle = ::CreateFile2( ws.c_str(), - GENERIC_READ, - FILE_SHARE_READ, - OPEN_EXISTING, - nullptr ); - if( handle != INVALID_HANDLE_VALUE ) { - return handle; - } - TAO_PEGTL_THROW_INPUT_WIN32_ERROR( "CreateFile2() failed opening file " << m_source << " for reading" ); -#else - const HANDLE handle = ::CreateFileW( ws.c_str(), - GENERIC_READ, - FILE_SHARE_READ, - nullptr, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - nullptr ); - if( handle != INVALID_HANDLE_VALUE ) { - return handle; - } - TAO_PEGTL_THROW_INPUT_WIN32_ERROR( "CreateFileW() failed opening file " << m_source << " for reading" ); -#endif - } - }; - - struct win32_file_mapper - { - explicit win32_file_mapper( const char* filename ) - : win32_file_mapper( win32_file_opener( filename ) ) - { - } - - explicit win32_file_mapper( const win32_file_opener& reader ) - : m_size( reader.size() ), - m_handle( open( reader ) ) - { - } - - win32_file_mapper( const win32_file_mapper& ) = delete; - win32_file_mapper( win32_file_mapper&& ) = delete; - - ~win32_file_mapper() noexcept - { - ::CloseHandle( m_handle ); - } - - void operator=( const win32_file_mapper& ) = delete; - void operator=( win32_file_mapper&& ) = delete; - - const size_t m_size; - const HANDLE m_handle; - - private: - HANDLE open( const win32_file_opener& reader ) const - { - const uint64_t file_size = reader.size(); - SetLastError( 0 ); - // Use `CreateFileMappingW` because a) we're not specifying a - // mapping name, so the character type is of no consequence, and - // b) it's defined in `memoryapi.h`, unlike - // `CreateFileMappingA`(?!) - const HANDLE handle = ::CreateFileMappingW( reader.m_handle, - nullptr, - PAGE_READONLY, - DWORD( file_size >> 32 ), - DWORD( file_size & 0xffffffff ), - nullptr ); - if( handle != NULL || file_size == 0 ) { - return handle; - } - TAO_PEGTL_THROW_INPUT_WIN32_ERROR( "unable to CreateFileMappingW() file " << reader.m_source << " for reading" ); - } - }; - - class file_mapper - { - public: - explicit file_mapper( const char* filename ) - : file_mapper( win32_file_mapper( filename ) ) - { - } - - explicit file_mapper( const win32_file_mapper& mapper ) - : m_size( mapper.m_size ), - m_data( static_cast< const char* >( ::MapViewOfFile( mapper.m_handle, - FILE_MAP_READ, - 0, - 0, - 0 ) ) ) - { - if( ( m_size != 0 ) && ( intptr_t( m_data ) == 0 ) ) { - TAO_PEGTL_THROW_INPUT_WIN32_ERROR( "unable to MapViewOfFile() file mapping object with handle " << mapper.m_handle ); - } - } - - file_mapper( const file_mapper& ) = delete; - file_mapper( file_mapper&& ) = delete; - - ~file_mapper() noexcept - { - ::UnmapViewOfFile( LPCVOID( m_data ) ); - } - - void operator=( const file_mapper& ) = delete; - void operator=( file_mapper&& ) = delete; - - bool empty() const noexcept - { - return m_size == 0; - } - - std::size_t size() const noexcept - { - return m_size; - } - - using iterator = const char*; - using const_iterator = const char*; - - iterator data() const noexcept - { - return m_data; - } - - iterator begin() const noexcept - { - return m_data; - } - - iterator end() const noexcept - { - return m_data + m_size; - } - - std::string string() const - { - return std::string( m_data, m_size ); - } - - private: - const std::size_t m_size; - const char* const m_data; - }; - - } // namespace internal - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 23 "tao/pegtl/mmap_input.hpp" -#else -#endif - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - struct mmap_holder - { - const std::string filename; - const file_mapper data; - - template< typename T > - explicit mmap_holder( T&& in_filename ) - : filename( std::forward< T >( in_filename ) ), - data( filename.c_str() ) - { - } - - mmap_holder( const mmap_holder& ) = delete; - mmap_holder( mmap_holder&& ) = delete; - - ~mmap_holder() = default; - - void operator=( const mmap_holder& ) = delete; - void operator=( mmap_holder&& ) = delete; - }; - - } // namespace internal - - template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > - struct mmap_input - : private internal::mmap_holder, - public memory_input< P, Eol, const char* > - { - template< typename T > - explicit mmap_input( T&& in_filename ) - : internal::mmap_holder( std::forward< T >( in_filename ) ), - memory_input< P, Eol, const char* >( data.begin(), data.end(), filename.c_str() ) - { - } - - mmap_input( const mmap_input& ) = delete; - mmap_input( mmap_input&& ) = delete; - - ~mmap_input() = default; - - void operator=( const mmap_input& ) = delete; - void operator=( mmap_input&& ) = delete; - }; - -#ifdef __cpp_deduction_guides - template< typename... Ts > - explicit mmap_input( Ts&&... )->mmap_input<>; -#endif - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 17 "tao/pegtl/file_input.hpp" -#else - -#endif - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { -#if defined( _POSIX_MAPPED_FILES ) || defined( _WIN32 ) - template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > - struct file_input - : mmap_input< P, Eol > - { - using mmap_input< P, Eol >::mmap_input; - }; -#else - template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > - struct file_input - : read_input< P, Eol > - { - using read_input< P, Eol >::read_input; - }; -#endif - -#ifdef __cpp_deduction_guides - template< typename... Ts > - explicit file_input( Ts&&... )->file_input<>; -#endif - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 33 "tao/pegtl.hpp" - -#line 1 "tao/pegtl/change_action.hpp" - -#line 1 "tao/pegtl/change_action.hpp" - - - -#ifndef TAO_PEGTL_CHANGE_ACTION_HPP -#define TAO_PEGTL_CHANGE_ACTION_HPP - -#include - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< template< typename... > class NewAction > - struct change_action - : maybe_nothing - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - static_assert( !std::is_same< Action< void >, NewAction< void > >::value, "old and new action class templates are identical" ); - return Control< Rule >::template match< A, M, NewAction, Control >( in, st... ); - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 35 "tao/pegtl.hpp" -#line 1 "tao/pegtl/change_action_and_state.hpp" - -#line 1 "tao/pegtl/change_action_and_state.hpp" - - - -#ifndef TAO_PEGTL_CHANGE_ACTION_AND_STATE_HPP -#define TAO_PEGTL_CHANGE_ACTION_AND_STATE_HPP - -#include - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< template< typename... > class NewAction, typename NewState > - struct change_action_and_state - : maybe_nothing - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static auto match( Input& in, States&&... st ) - -> typename std::enable_if< ( A == apply_mode::action ), bool >::type - { - static_assert( !std::is_same< Action< void >, NewAction< void > >::value, "old and new action class templates are identical" ); - NewState s( static_cast< const Input& >( in ), st... ); - if( Control< Rule >::template match< A, M, NewAction, Control >( in, s ) ) { - Action< Rule >::success( static_cast< const Input& >( in ), s, st... ); - return true; - } - return false; - } - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States, - int = 1 > - static auto match( Input& in, States&&... st ) - -> typename std::enable_if< ( A == apply_mode::nothing ), bool >::type - { - static_assert( !std::is_same< Action< void >, NewAction< void > >::value, "old and new action class templates are identical" ); - NewState s( static_cast< const Input& >( in ), st... ); - return Control< Rule >::template match< A, M, NewAction, Control >( in, s ); - } - - template< typename Input, - typename... States > - static void success( const Input& in, NewState& s, States&&... st ) noexcept( noexcept( s.success( in, st... ) ) ) - { - s.success( in, st... ); - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 36 "tao/pegtl.hpp" -#line 1 "tao/pegtl/change_action_and_states.hpp" - -#line 1 "tao/pegtl/change_action_and_states.hpp" - - - -#ifndef TAO_PEGTL_CHANGE_ACTION_AND_STATES_HPP -#define TAO_PEGTL_CHANGE_ACTION_AND_STATES_HPP - -#include -#include -#line 17 "tao/pegtl/change_action_and_states.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< template< typename... > class NewAction, typename... NewStates > - struct change_action_and_states - : maybe_nothing - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - std::size_t... Ns, - typename Input, - typename... States > - static bool match( TAO_PEGTL_NAMESPACE::internal::index_sequence< Ns... >, Input& in, States&&... st ) - { - auto t = std::tie( st... ); - if( Control< Rule >::template match< A, M, NewAction, Control >( in, std::get< Ns >( t )... ) ) { - Action< Rule >::success( static_cast< const Input& >( in ), st... ); - return true; - } - return false; - } - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static auto match( Input& in, States&&... st ) - -> typename std::enable_if< ( A == apply_mode::action ), bool >::type - { - static_assert( !std::is_same< Action< void >, NewAction< void > >::value, "old and new action class templates are identical" ); - return match< Rule, A, M, Action, Control >( TAO_PEGTL_NAMESPACE::internal::index_sequence_for< NewStates... >(), in, NewStates()..., st... ); - } - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States, - int = 1 > - static auto match( Input& in, States&&... /*unused*/ ) - -> typename std::enable_if< ( A == apply_mode::nothing ), bool >::type - { - static_assert( !std::is_same< Action< void >, NewAction< void > >::value, "old and new action class templates are identical" ); - return Control< Rule >::template match< A, M, NewAction, Control >( in, NewStates()... ); - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 37 "tao/pegtl.hpp" -#line 1 "tao/pegtl/change_control.hpp" - -#line 1 "tao/pegtl/change_control.hpp" - - - -#ifndef TAO_PEGTL_CHANGE_CONTROL_HPP -#define TAO_PEGTL_CHANGE_CONTROL_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< template< typename... > class NewControl > - struct change_control - : maybe_nothing - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, NewControl >( in, st... ); - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 38 "tao/pegtl.hpp" -#line 1 "tao/pegtl/change_state.hpp" - -#line 1 "tao/pegtl/change_state.hpp" - - - -#ifndef TAO_PEGTL_CHANGE_STATE_HPP -#define TAO_PEGTL_CHANGE_STATE_HPP - -#include - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< typename NewState > - struct change_state - : maybe_nothing - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static auto match( Input& in, States&&... st ) - -> typename std::enable_if< ( A == apply_mode::action ), bool >::type - { - NewState s( static_cast< const Input& >( in ), st... ); - if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s ) ) { - Action< Rule >::success( static_cast< const Input& >( in ), s, st... ); - return true; - } - return false; - } - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States, - int = 1 > - static auto match( Input& in, States&&... st ) - -> typename std::enable_if< ( A == apply_mode::nothing ), bool >::type - { - NewState s( static_cast< const Input& >( in ), st... ); - return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s ); - } - - template< typename Input, - typename... States > - static void success( const Input& in, NewState& s, States&&... st ) noexcept( noexcept( s.success( in, st... ) ) ) - { - s.success( in, st... ); - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 39 "tao/pegtl.hpp" -#line 1 "tao/pegtl/change_states.hpp" - -#line 1 "tao/pegtl/change_states.hpp" - - - -#ifndef TAO_PEGTL_CHANGE_STATES_HPP -#define TAO_PEGTL_CHANGE_STATES_HPP - -#include -#line 17 "tao/pegtl/change_states.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< typename... NewStates > - struct change_states - : maybe_nothing - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - std::size_t... Ns, - typename Input, - typename... States > - static bool match( TAO_PEGTL_NAMESPACE::internal::index_sequence< Ns... >, Input& in, States&&... st ) - { - auto t = std::tie( st... ); - if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, std::get< Ns >( t )... ) ) { - Action< Rule >::success( static_cast< const Input& >( in ), st... ); - return true; - } - return false; - } - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static auto match( Input& in, States&&... st ) - -> typename std::enable_if< ( A == apply_mode::action ), bool >::type - { - return match< Rule, A, M, Action, Control >( TAO_PEGTL_NAMESPACE::internal::index_sequence_for< NewStates... >(), in, NewStates()..., st... ); - } - - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States, - int = 1 > - static auto match( Input& in, States&&... /*unused*/ ) - -> typename std::enable_if< ( A == apply_mode::nothing ), bool >::type - { - return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, NewStates()... ); - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 40 "tao/pegtl.hpp" - -#line 1 "tao/pegtl/disable_action.hpp" - -#line 1 "tao/pegtl/disable_action.hpp" - - - -#ifndef TAO_PEGTL_DISABLE_ACTION_HPP -#define TAO_PEGTL_DISABLE_ACTION_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - struct disable_action - : maybe_nothing - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return TAO_PEGTL_NAMESPACE::match< Rule, apply_mode::nothing, M, Action, Control >( in, st... ); - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 42 "tao/pegtl.hpp" -#line 1 "tao/pegtl/enable_action.hpp" - -#line 1 "tao/pegtl/enable_action.hpp" - - - -#ifndef TAO_PEGTL_ENABLE_ACTION_HPP -#define TAO_PEGTL_ENABLE_ACTION_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - struct enable_action - : maybe_nothing - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - return TAO_PEGTL_NAMESPACE::match< Rule, apply_mode::action, M, Action, Control >( in, st... ); - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 43 "tao/pegtl.hpp" - -#line 1 "tao/pegtl/discard_input.hpp" - -#line 1 "tao/pegtl/discard_input.hpp" - - - -#ifndef TAO_PEGTL_DISCARD_INPUT_HPP -#define TAO_PEGTL_DISCARD_INPUT_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - struct discard_input - : maybe_nothing - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); - in.discard(); - return result; - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 45 "tao/pegtl.hpp" -#line 1 "tao/pegtl/discard_input_on_failure.hpp" - -#line 1 "tao/pegtl/discard_input_on_failure.hpp" - - - -#ifndef TAO_PEGTL_DISCARD_INPUT_ON_FAILURE_HPP -#define TAO_PEGTL_DISCARD_INPUT_ON_FAILURE_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - struct discard_input_on_failure - : maybe_nothing - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); - if( !result ) { - in.discard(); - } - return result; - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 46 "tao/pegtl.hpp" -#line 1 "tao/pegtl/discard_input_on_success.hpp" - -#line 1 "tao/pegtl/discard_input_on_success.hpp" - - - -#ifndef TAO_PEGTL_DISCARD_INPUT_ON_SUCCESS_HPP -#define TAO_PEGTL_DISCARD_INPUT_ON_SUCCESS_HPP - - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - struct discard_input_on_success - : maybe_nothing - { - template< typename Rule, - apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); - if( result ) { - in.discard(); - } - return result; - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 47 "tao/pegtl.hpp" - -// The following are not included by -// default because they include . - -// #include "pegtl/analyze.hpp" - -#endif -#line 2 "amalgamated.hpp" -#line 1 "tao/pegtl/analyze.hpp" - -#line 1 "tao/pegtl/analyze.hpp" - - - -#ifndef TAO_PEGTL_ANALYZE_HPP -#define TAO_PEGTL_ANALYZE_HPP - - - -#line 1 "tao/pegtl/analysis/analyze_cycles.hpp" - -#line 1 "tao/pegtl/analysis/analyze_cycles.hpp" - - - -#ifndef TAO_PEGTL_ANALYSIS_ANALYZE_CYCLES_HPP -#define TAO_PEGTL_ANALYSIS_ANALYZE_CYCLES_HPP - -#include - -#include -#include -#include - -#include -#include - - - - -#line 1 "tao/pegtl/analysis/insert_guard.hpp" - -#line 1 "tao/pegtl/analysis/insert_guard.hpp" - - - -#ifndef TAO_PEGTL_ANALYSIS_INSERT_GUARD_HPP -#define TAO_PEGTL_ANALYSIS_INSERT_GUARD_HPP - -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace analysis - { - template< typename C > - class insert_guard - { - public: - insert_guard( C& container, const typename C::value_type& value ) - : m_i( container.insert( value ) ), - m_c( &container ) - { - } - - insert_guard( const insert_guard& ) = delete; - - insert_guard( insert_guard&& other ) noexcept - : m_i( other.m_i ), - m_c( other.m_c ) - { - other.m_c = nullptr; - } - - ~insert_guard() - { - if( m_c && m_i.second ) { - m_c->erase( m_i.first ); - } - } - - void operator=( const insert_guard& ) = delete; - void operator=( insert_guard&& ) = delete; - - explicit operator bool() const noexcept - { - return m_i.second; - } - - private: - const std::pair< typename C::iterator, bool > m_i; - C* m_c; - }; - - template< typename C > - insert_guard< C > make_insert_guard( C& container, const typename C::value_type& value ) - { - return insert_guard< C >( container, value ); - } - - } // namespace analysis - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 20 "tao/pegtl/analysis/analyze_cycles.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace analysis - { - class analyze_cycles_impl - { - protected: - explicit analyze_cycles_impl( const bool verbose ) noexcept - : m_verbose( verbose ), - m_problems( 0 ) - { - } - - const bool m_verbose; - unsigned m_problems; - grammar_info m_info; - std::set< std::string > m_stack; - std::map< std::string, bool > m_cache; - std::map< std::string, bool > m_results; - - std::map< std::string, rule_info >::const_iterator find( const std::string& name ) const noexcept - { - const auto iter = m_info.map.find( name ); - assert( iter != m_info.map.end() ); - return iter; - } - - bool work( const std::map< std::string, rule_info >::const_iterator& start, const bool accum ) - { - const auto j = m_cache.find( start->first ); - - if( j != m_cache.end() ) { - return j->second; - } - if( const auto g = make_insert_guard( m_stack, start->first ) ) { - switch( start->second.type ) { - case rule_type::any: { - bool a = false; - for( const auto& r : start->second.rules ) { - a = a || work( find( r ), accum || a ); - } - return m_cache[ start->first ] = true; - } - case rule_type::opt: { - bool a = false; - for( const auto& r : start->second.rules ) { - a = a || work( find( r ), accum || a ); - } - return m_cache[ start->first ] = false; - } - case rule_type::seq: { - bool a = false; - for( const auto& r : start->second.rules ) { - a = a || work( find( r ), accum || a ); - } - return m_cache[ start->first ] = a; - } - case rule_type::sor: { - bool a = true; - for( const auto& r : start->second.rules ) { - a = a && work( find( r ), accum ); - } - return m_cache[ start->first ] = a; - } - } - throw std::logic_error( "code should be unreachable: invalid rule_type value" ); // NOLINT, LCOV_EXCL_LINE - } - if( !accum ) { - ++m_problems; - if( m_verbose ) { - std::cout << "problem: cycle without progress detected at rule class " << start->first << std::endl; // LCOV_EXCL_LINE - } - } - return m_cache[ start->first ] = accum; - } - }; - - template< typename Grammar > - class analyze_cycles - : private analyze_cycles_impl - { - public: - explicit analyze_cycles( const bool verbose ) - : analyze_cycles_impl( verbose ) - { - Grammar::analyze_t::template insert< Grammar >( m_info ); - } - - std::size_t problems() - { - for( auto i = m_info.map.begin(); i != m_info.map.end(); ++i ) { - m_results[ i->first ] = work( i, false ); - m_cache.clear(); - } - return m_problems; - } - - template< typename Rule > - bool consumes() const noexcept - { - const auto i = m_results.find( internal::demangle< Rule >() ); - assert( i != m_results.end() ); - return i->second; - } - }; - - } // namespace analysis - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "tao/pegtl/analyze.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - template< typename Rule > - std::size_t analyze( const bool verbose = true ) - { - return analysis::analyze_cycles< Rule >( verbose ).problems(); - } - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 3 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/abnf.hpp" - -#line 1 "tao/pegtl/contrib/abnf.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_ABNF_HPP -#define TAO_PEGTL_CONTRIB_ABNF_HPP - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace abnf - { - // Core ABNF rules according to RFC 5234, Appendix B - - // clang-format off - struct ALPHA : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z' > {}; - struct BIT : internal::one< internal::result_on_found::success, internal::peek_char, '0', '1' > {}; - struct CHAR : internal::range< internal::result_on_found::success, internal::peek_char, char( 1 ), char( 127 ) > {}; - struct CR : internal::one< internal::result_on_found::success, internal::peek_char, '\r' > {}; - struct CRLF : internal::string< '\r', '\n' > {}; - struct CTL : internal::ranges< internal::peek_char, char( 0 ), char( 31 ), char( 127 ) > {}; - struct DIGIT : internal::range< internal::result_on_found::success, internal::peek_char, '0', '9' > {}; - struct DQUOTE : internal::one< internal::result_on_found::success, internal::peek_char, '"' > {}; - struct HEXDIG : internal::ranges< internal::peek_char, '0', '9', 'a', 'f', 'A', 'F' > {}; - struct HTAB : internal::one< internal::result_on_found::success, internal::peek_char, '\t' > {}; - struct LF : internal::one< internal::result_on_found::success, internal::peek_char, '\n' > {}; - struct LWSP : internal::star< internal::sor< internal::string< '\r', '\n' >, internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > >, internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > > {}; - struct OCTET : internal::any< internal::peek_char > {}; - struct SP : internal::one< internal::result_on_found::success, internal::peek_char, ' ' > {}; - struct VCHAR : internal::range< internal::result_on_found::success, internal::peek_char, char( 33 ), char( 126 ) > {}; - struct WSP : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > {}; - // clang-format on - - } // namespace abnf - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 4 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/alphabet.hpp" - -#line 1 "tao/pegtl/contrib/alphabet.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_ALPHABET_HPP -#define TAO_PEGTL_CONTRIB_ALPHABET_HPP - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace alphabet - { - static const int a = 'a'; // NOLINT - static const int b = 'b'; // NOLINT - static const int c = 'c'; // NOLINT - static const int d = 'd'; // NOLINT - static const int e = 'e'; // NOLINT - static const int f = 'f'; // NOLINT - static const int g = 'g'; // NOLINT - static const int h = 'h'; // NOLINT - static const int i = 'i'; // NOLINT - static const int j = 'j'; // NOLINT - static const int k = 'k'; // NOLINT - static const int l = 'l'; // NOLINT - static const int m = 'm'; // NOLINT - static const int n = 'n'; // NOLINT - static const int o = 'o'; // NOLINT - static const int p = 'p'; // NOLINT - static const int q = 'q'; // NOLINT - static const int r = 'r'; // NOLINT - static const int s = 's'; // NOLINT - static const int t = 't'; // NOLINT - static const int u = 'u'; // NOLINT - static const int v = 'v'; // NOLINT - static const int w = 'w'; // NOLINT - static const int x = 'x'; // NOLINT - static const int y = 'y'; // NOLINT - static const int z = 'z'; // NOLINT - - static const int A = 'A'; // NOLINT - static const int B = 'B'; // NOLINT - static const int C = 'C'; // NOLINT - static const int D = 'D'; // NOLINT - static const int E = 'E'; // NOLINT - static const int F = 'F'; // NOLINT - static const int G = 'G'; // NOLINT - static const int H = 'H'; // NOLINT - static const int I = 'I'; // NOLINT - static const int J = 'J'; // NOLINT - static const int K = 'K'; // NOLINT - static const int L = 'L'; // NOLINT - static const int M = 'M'; // NOLINT - static const int N = 'N'; // NOLINT - static const int O = 'O'; // NOLINT - static const int P = 'P'; // NOLINT - static const int Q = 'Q'; // NOLINT - static const int R = 'R'; // NOLINT - static const int S = 'S'; // NOLINT - static const int T = 'T'; // NOLINT - static const int U = 'U'; // NOLINT - static const int V = 'V'; // NOLINT - static const int W = 'W'; // NOLINT - static const int X = 'X'; // NOLINT - static const int Y = 'Y'; // NOLINT - static const int Z = 'Z'; // NOLINT - - } // namespace alphabet - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 5 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/counter.hpp" - -#line 1 "tao/pegtl/contrib/counter.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_COUNTER_HPP -#define TAO_PEGTL_CONTRIB_COUNTER_HPP - -#include -#include - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - struct counter_data - { - unsigned start = 0; - unsigned success = 0; - unsigned failure = 0; - }; - - struct counter_state - { - std::map< std::string, counter_data > counts; - }; - - template< typename Rule > - struct counter - : normal< Rule > - { - template< typename Input > - static void start( const Input& /*unused*/, counter_state& ts ) - { - ++ts.counts[ internal::demangle< Rule >() ].start; - } - - template< typename Input > - static void success( const Input& /*unused*/, counter_state& ts ) - { - ++ts.counts[ internal::demangle< Rule >() ].success; - } - - template< typename Input > - static void failure( const Input& /*unused*/, counter_state& ts ) - { - ++ts.counts[ internal::demangle< Rule >() ].failure; - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 6 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/http.hpp" - -#line 1 "tao/pegtl/contrib/http.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_HTTP_HPP -#define TAO_PEGTL_CONTRIB_HTTP_HPP -#line 14 "tao/pegtl/contrib/http.hpp" -#line 1 "tao/pegtl/contrib/remove_first_state.hpp" - -#line 1 "tao/pegtl/contrib/remove_first_state.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_REMOVE_FIRST_STATE_HPP -#define TAO_PEGTL_CONTRIB_REMOVE_FIRST_STATE_HPP - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - // Applies to start(), success(), failure(), raise(), apply(), and apply0(): - // The first state is removed when the call is forwarded to Base. - template< typename Base > - struct remove_first_state - : Base - { - template< typename Input, typename State, typename... States > - static void start( const Input& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Base::start( in, st... ) ) ) - { - Base::start( in, st... ); - } - - template< typename Input, typename State, typename... States > - static void success( const Input& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Base::success( in, st... ) ) ) - { - Base::success( in, st... ); - } - - template< typename Input, typename State, typename... States > - static void failure( const Input& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Base::failure( in, st... ) ) ) - { - Base::failure( in, st... ); - } - - template< typename Input, typename State, typename... States > - static void raise( const Input& in, State&& /*unused*/, States&&... st ) - { - Base::raise( in, st... ); - } - - template< template< typename... > class Action, typename Iterator, typename Input, typename State, typename... States > - static auto apply( const Iterator& begin, const Input& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Base::template apply< Action >( begin, in, st... ) ) ) - -> decltype( Base::template apply< Action >( begin, in, st... ) ) - { - return Base::template apply< Action >( begin, in, st... ); - } - - template< template< typename... > class Action, typename Input, typename State, typename... States > - static auto apply0( const Input& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Base::template apply0< Action >( in, st... ) ) ) - -> decltype( Base::template apply0< Action >( in, st... ) ) - { - return Base::template apply0< Action >( in, st... ); - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 15 "tao/pegtl/contrib/http.hpp" -#line 1 "tao/pegtl/contrib/uri.hpp" - -#line 1 "tao/pegtl/contrib/uri.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_URI_HPP -#define TAO_PEGTL_CONTRIB_URI_HPP -#line 14 "tao/pegtl/contrib/uri.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace uri - { - // URI grammar according to RFC 3986. - - // This grammar is a direct PEG translation of the original URI grammar. - // It should be considered experimental -- in case of any issues, in particular - // missing rules for attached actions, please contact the developers. - - // Note that this grammar has multiple top-level rules. - - using dot = one< '.' >; - using colon = one< ':' >; - - // clang-format off - struct dec_octet : sor< one< '0' >, - rep_min_max< 1, 2, abnf::DIGIT >, - seq< one< '1' >, abnf::DIGIT, abnf::DIGIT >, - seq< one< '2' >, range< '0', '4' >, abnf::DIGIT >, - seq< string< '2', '5' >, range< '0', '5' > > > {}; - - struct IPv4address : seq< dec_octet, dot, dec_octet, dot, dec_octet, dot, dec_octet > {}; - - struct h16 : rep_min_max< 1, 4, abnf::HEXDIG > {}; - struct ls32 : sor< seq< h16, colon, h16 >, IPv4address > {}; - - struct dcolon : two< ':' > {}; - - struct IPv6address : sor< seq< rep< 6, h16, colon >, ls32 >, - seq< dcolon, rep< 5, h16, colon >, ls32 >, - seq< opt< h16 >, dcolon, rep< 4, h16, colon >, ls32 >, - seq< opt< h16, opt< colon, h16 > >, dcolon, rep< 3, h16, colon >, ls32 >, - seq< opt< h16, rep_opt< 2, colon, h16 > >, dcolon, rep< 2, h16, colon >, ls32 >, - seq< opt< h16, rep_opt< 3, colon, h16 > >, dcolon, h16, colon, ls32 >, - seq< opt< h16, rep_opt< 4, colon, h16 > >, dcolon, ls32 >, - seq< opt< h16, rep_opt< 5, colon, h16 > >, dcolon, h16 >, - seq< opt< h16, rep_opt< 6, colon, h16 > >, dcolon > > {}; - - struct gen_delims : one< ':', '/', '?', '#', '[', ']', '@' > {}; - struct sub_delims : one< '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=' > {}; - - struct unreserved : sor< abnf::ALPHA, abnf::DIGIT, one< '-', '.', '_', '~' > > {}; - struct reserved : sor< gen_delims, sub_delims > {}; - - struct IPvFuture : if_must< one< 'v' >, plus< abnf::HEXDIG >, dot, plus< sor< unreserved, sub_delims, colon > > > {}; - - struct IP_literal : if_must< one< '[' >, sor< IPvFuture, IPv6address >, one< ']' > > {}; - - struct pct_encoded : if_must< one< '%' >, abnf::HEXDIG, abnf::HEXDIG > {}; - struct pchar : sor< unreserved, pct_encoded, sub_delims, one< ':', '@' > > {}; - - struct query : star< sor< pchar, one< '/', '?' > > > {}; - struct fragment : star< sor< pchar, one< '/', '?' > > > {}; - - struct segment : star< pchar > {}; - struct segment_nz : plus< pchar > {}; - struct segment_nz_nc : plus< sor< unreserved, pct_encoded, sub_delims, one< '@' > > > {}; // non-zero-length segment without any colon ":" - - struct path_abempty : star< one< '/' >, segment > {}; - struct path_absolute : seq< one< '/' >, opt< segment_nz, star< one< '/' >, segment > > > {}; - struct path_noscheme : seq< segment_nz_nc, star< one< '/' >, segment > > {}; - struct path_rootless : seq< segment_nz, star< one< '/' >, segment > > {}; - struct path_empty : success {}; - - struct path : sor< path_noscheme, // begins with a non-colon segment - path_rootless, // begins with a segment - path_absolute, // begins with "/" but not "//" - path_abempty > {}; // begins with "/" or is empty - - struct reg_name : star< sor< unreserved, pct_encoded, sub_delims > > {}; - - struct port : star< abnf::DIGIT > {}; - struct host : sor< IP_literal, IPv4address, reg_name > {}; - struct userinfo : star< sor< unreserved, pct_encoded, sub_delims, colon > > {}; - struct opt_userinfo : opt< userinfo, one< '@' > > {}; - struct authority : seq< opt_userinfo, host, opt< colon, port > > {}; - - struct scheme : seq< abnf::ALPHA, star< sor< abnf::ALPHA, abnf::DIGIT, one< '+', '-', '.' > > > > {}; - - using dslash = two< '/' >; - using opt_query = opt_must< one< '?' >, query >; - using opt_fragment = opt_must< one< '#' >, fragment >; - - struct hier_part : sor< if_must< dslash, authority, path_abempty >, path_rootless, path_absolute, path_empty > {}; - struct relative_part : sor< if_must< dslash, authority, path_abempty >, path_noscheme, path_absolute, path_empty > {}; - struct relative_ref : seq< relative_part, opt_query, opt_fragment > {}; - - struct URI : seq< scheme, one< ':' >, hier_part, opt_query, opt_fragment > {}; - struct URI_reference : sor< URI, relative_ref > {}; - struct absolute_URI : seq< scheme, one< ':' >, hier_part, opt_query > {}; - // clang-format on - - } // namespace uri - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 16 "tao/pegtl/contrib/http.hpp" - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace http - { - // HTTP 1.1 grammar according to RFC 7230. - - // This grammar is a direct PEG translation of the original HTTP grammar. - // It should be considered experimental -- in case of any issues, in particular - // missing rules for attached actions, please contact the developers. - - using OWS = star< abnf::WSP >; // optional whitespace - using RWS = plus< abnf::WSP >; // required whitespace - using BWS = OWS; // "bad" whitespace - - using obs_text = not_range< 0x00, 0x7F >; - using obs_fold = seq< abnf::CRLF, plus< abnf::WSP > >; - - // clang-format off - struct tchar : sor< abnf::ALPHA, abnf::DIGIT, one< '!', '#', '$', '%', '&', '\'', '*', '+', '-', '.', '^', '_', '`', '|', '~' > > {}; - struct token : plus< tchar > {}; - - struct field_name : token {}; - - struct field_vchar : sor< abnf::VCHAR, obs_text > {}; - struct field_content : list< field_vchar, plus< abnf::WSP > > {}; - struct field_value : star< sor< field_content, obs_fold > > {}; - - struct header_field : seq< field_name, one< ':' >, OWS, field_value, OWS > {}; - - struct method : token {}; - - struct absolute_path : plus< one< '/' >, uri::segment > {}; - - struct origin_form : seq< absolute_path, uri::opt_query > {}; - struct absolute_form : uri::absolute_URI {}; - struct authority_form : uri::authority {}; - struct asterisk_form : one< '*' > {}; - - struct request_target : sor< origin_form, absolute_form, authority_form, asterisk_form > {}; - - struct status_code : rep< 3, abnf::DIGIT > {}; - struct reason_phrase : star< sor< abnf::VCHAR, obs_text, abnf::WSP > > {}; - - struct HTTP_version : if_must< string< 'H', 'T', 'T', 'P', '/' >, abnf::DIGIT, one< '.' >, abnf::DIGIT > {}; - - struct request_line : if_must< method, abnf::SP, request_target, abnf::SP, HTTP_version, abnf::CRLF > {}; - struct status_line : if_must< HTTP_version, abnf::SP, status_code, abnf::SP, reason_phrase, abnf::CRLF > {}; - struct start_line : sor< status_line, request_line > {}; - - struct message_body : star< abnf::OCTET > {}; - struct HTTP_message : seq< start_line, star< header_field, abnf::CRLF >, abnf::CRLF, opt< message_body > > {}; - - struct Content_Length : plus< abnf::DIGIT > {}; - - struct uri_host : uri::host {}; - struct port : uri::port {}; - - struct Host : seq< uri_host, opt< one< ':' >, port > > {}; - - // PEG are different from CFGs! (this replaces ctext and qdtext) - using text = sor< abnf::HTAB, range< 0x20, 0x7E >, obs_text >; - - struct quoted_pair : if_must< one< '\\' >, sor< abnf::VCHAR, obs_text, abnf::WSP > > {}; - struct quoted_string : if_must< abnf::DQUOTE, until< abnf::DQUOTE, sor< quoted_pair, text > > > {}; - - struct transfer_parameter : seq< token, BWS, one< '=' >, BWS, sor< token, quoted_string > > {}; - struct transfer_extension : seq< token, star< OWS, one< ';' >, OWS, transfer_parameter > > {}; - struct transfer_coding : sor< istring< 'c', 'h', 'u', 'n', 'k', 'e', 'd' >, - istring< 'c', 'o', 'm', 'p', 'r', 'e', 's', 's' >, - istring< 'd', 'e', 'f', 'l', 'a', 't', 'e' >, - istring< 'g', 'z', 'i', 'p' >, - transfer_extension > {}; - - struct rank : sor< seq< one< '0' >, opt< one< '.' >, rep_opt< 3, abnf::DIGIT > > >, - seq< one< '1' >, opt< one< '.' >, rep_opt< 3, one< '0' > > > > > {}; - - struct t_ranking : seq< OWS, one< ';' >, OWS, one< 'q', 'Q' >, one< '=' >, rank > {}; - struct t_codings : sor< istring< 't', 'r', 'a', 'i', 'l', 'e', 'r', 's' >, seq< transfer_coding, opt< t_ranking > > > {}; - - struct TE : opt< sor< one< ',' >, t_codings >, star< OWS, one< ',' >, opt< OWS, t_codings > > > {}; - - template< typename T > - using make_comma_list = seq< star< one< ',' >, OWS >, T, star< OWS, one< ',' >, opt< OWS, T > > >; - - struct connection_option : token {}; - struct Connection : make_comma_list< connection_option > {}; - - struct Trailer : make_comma_list< field_name > {}; - - struct Transfer_Encoding : make_comma_list< transfer_coding > {}; - - struct protocol_name : token {}; - struct protocol_version : token {}; - struct protocol : seq< protocol_name, opt< one< '/' >, protocol_version > > {}; - struct Upgrade : make_comma_list< protocol > {}; - - struct pseudonym : token {}; - - struct received_protocol : seq< opt< protocol_name, one< '/' > >, protocol_version > {}; - struct received_by : sor< seq< uri_host, opt< one< ':' >, port > >, pseudonym > {}; - - struct comment : if_must< one< '(' >, until< one< ')' >, sor< comment, quoted_pair, text > > > {}; - - struct Via : make_comma_list< seq< received_protocol, RWS, received_by, opt< RWS, comment > > > {}; - - struct http_URI : if_must< istring< 'h', 't', 't', 'p', ':', '/', '/' >, uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {}; - struct https_URI : if_must< istring< 'h', 't', 't', 'p', 's', ':', '/', '/' >, uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {}; - - struct partial_URI : seq< uri::relative_part, uri::opt_query > {}; - - // clang-format on - struct chunk_size - { - using analyze_t = plus< abnf::HEXDIG >::analyze_t; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, std::size_t& size, States&&... /*unused*/ ) - { - size = 0; - std::size_t i = 0; - while( in.size( i + 1 ) >= i + 1 ) { - const auto c = in.peek_char( i ); - if( ( '0' <= c ) && ( c <= '9' ) ) { - size <<= 4; - size |= std::size_t( c - '0' ); - ++i; - continue; - } - if( ( 'a' <= c ) && ( c <= 'f' ) ) { - size <<= 4; - size |= std::size_t( c - 'a' + 10 ); - ++i; - continue; - } - if( ( 'A' <= c ) && ( c <= 'F' ) ) { - size <<= 4; - size |= std::size_t( c - 'A' + 10 ); - ++i; - continue; - } - break; - } - in.bump_in_this_line( i ); - return i > 0; - } - }; - // clang-format off - - struct chunk_ext_name : token {}; - struct chunk_ext_val : sor< quoted_string, token > {}; - struct chunk_ext : star_must< one< ';' >, chunk_ext_name, if_must< one< '=' >, chunk_ext_val > > {}; - - // clang-format on - struct chunk_data - { - using analyze_t = star< abnf::OCTET >::analyze_t; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, const std::size_t size, States&&... /*unused*/ ) - { - if( in.size( size ) >= size ) { - in.bump( size ); - return true; - } - return false; - } - }; - - namespace internal - { - namespace chunk_helper - { - template< typename Base > - struct control; - - template< template< typename... > class Control, typename Rule > - struct control< Control< Rule > > - : Control< Rule > - { - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class, - typename Input, - typename State, - typename... States > - static bool match( Input& in, State&& /*unused*/, States&&... st ) - { - return Control< Rule >::template match< A, M, Action, Control >( in, st... ); - } - }; - - template< template< typename... > class Control > - struct control< Control< chunk_size > > - : remove_first_state< Control< chunk_size > > - {}; - - template< template< typename... > class Control > - struct control< Control< chunk_data > > - : remove_first_state< Control< chunk_data > > - {}; - - template< template< typename... > class Control > - struct bind - { - template< typename Rule > - using type = control< Control< Rule > >; - }; - - } // namespace chunk_helper - - } // namespace internal - - struct chunk - { - using impl = seq< chunk_size, chunk_ext, abnf::CRLF, chunk_data, abnf::CRLF >; - using analyze_t = impl::analyze_t; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - std::size_t size{}; - return impl::template match< A, M, Action, internal::chunk_helper::bind< Control >::template type >( in, size, st... ); - } - }; - - // clang-format off - struct last_chunk : seq< plus< one< '0' > >, not_at< digit >, chunk_ext, abnf::CRLF > {}; - - struct trailer_part : star< header_field, abnf::CRLF > {}; - - struct chunked_body : seq< until< last_chunk, chunk >, trailer_part, abnf::CRLF > {}; - // clang-format on - - } // namespace http - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 7 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/if_then.hpp" - -#line 1 "tao/pegtl/contrib/if_then.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_IF_THEN_HPP -#define TAO_PEGTL_CONTRIB_IF_THEN_HPP - -#include -#line 16 "tao/pegtl/contrib/if_then.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Cond, typename Then > - struct if_pair - { - }; - - template< typename... Pairs > - struct if_then; - - template< typename Cond, typename Then, typename... Pairs > - struct if_then< if_pair< Cond, Then >, Pairs... > - : if_then_else< Cond, Then, if_then< Pairs... > > - { - template< typename ElseCond, typename... Thens > - using else_if_then = if_then< if_pair< Cond, Then >, Pairs..., if_pair< ElseCond, seq< Thens... > > >; - - template< typename... Thens > - using else_then = if_then_else< Cond, Then, if_then< Pairs..., if_pair< trivial< true >, seq< Thens... > > > >; - }; - - template<> - struct if_then<> - : trivial< false > - { - }; - - template< typename... Pairs > - struct skip_control< if_then< Pairs... > > : std::true_type - { - }; - - } // namespace internal - - template< typename Cond, typename... Thens > - using if_then = internal::if_then< internal::if_pair< Cond, internal::seq< Thens... > > >; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 8 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/integer.hpp" - -#line 1 "tao/pegtl/contrib/integer.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_INTEGER_HPP -#define TAO_PEGTL_CONTRIB_INTEGER_HPP - -#include -#include - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace integer - { - namespace internal - { - template< typename I, I Limit, typename Input > - I actual_convert( const Input& in, std::size_t index ) - { - static constexpr I cutoff = Limit / 10; - static constexpr I cutlim = Limit % 10; - - I out = in.peek_char( index ) - '0'; - while( ++index < in.size() ) { - const I c = in.peek_char( index ) - '0'; - if( ( out > cutoff ) || ( ( out == cutoff ) && ( c > cutlim ) ) ) { - throw parse_error( "integer out of range", in ); - } - out *= 10; - out += c; - } - return out; - } - - template< typename I, typename Input > - I convert_positive( const Input& in, std::size_t index ) - { - static constexpr I limit = ( std::numeric_limits< I >::max )(); - return actual_convert< I, limit >( in, index ); - } - - template< typename I, typename Input > - I convert_negative( const Input& in, std::size_t index ) - { - using U = typename std::make_unsigned< I >::type; - static constexpr U limit = static_cast< U >( ( std::numeric_limits< I >::max )() ) + 1; - return static_cast< I >( ~actual_convert< U, limit >( in, index ) ) + 1; - } - - } // namespace internal - - struct unsigned_rule - : plus< digit > - { - }; - - struct unsigned_action - { - // Assumes that 'in' contains a non-empty sequence of ASCII digits. - - template< typename Input, typename State, typename... States > - static void apply( const Input& in, State& st, States&&... /*unused*/ ) - { - using T = typename std::decay< decltype( st.converted ) >::type; - static_assert( std::is_integral< T >::value, "need integral type" ); - static_assert( std::is_unsigned< T >::value, "need unsigned type" ); - st.converted = internal::convert_positive< T >( in, 0 ); - } - }; - - struct signed_rule - : seq< opt< one< '+', '-' > >, plus< digit > > - { - }; - - struct signed_action - { - // Assumes that 'in' contains a non-empty sequence of ASCII digits, - // with optional leading sign; with sign, in.size() must be >= 2. - - template< typename Input, typename State, typename... States > - static void apply( const Input& in, State& st, States&&... /*unused*/ ) - { - using T = typename std::decay< decltype( st.converted ) >::type; - static_assert( std::is_integral< T >::value, "need integral type" ); - static_assert( std::is_signed< T >::value, "need signed type" ); - const auto c = in.peek_char(); - if( c == '-' ) { - st.converted = internal::convert_negative< T >( in, 1 ); - } - else { - st.converted = internal::convert_positive< T >( in, std::size_t( c == '+' ) ); - } - } - }; - - } // namespace integer - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 9 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/json.hpp" - -#line 1 "tao/pegtl/contrib/json.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_JSON_HPP -#define TAO_PEGTL_CONTRIB_JSON_HPP -#line 14 "tao/pegtl/contrib/json.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace json - { - // JSON grammar according to RFC 8259 - - // clang-format off - struct ws : one< ' ', '\t', '\n', '\r' > {}; - - template< typename R, typename P = ws > - struct padr : internal::seq< R, internal::star< P > > {}; - - struct begin_array : padr< one< '[' > > {}; - struct begin_object : padr< one< '{' > > {}; - struct end_array : one< ']' > {}; - struct end_object : one< '}' > {}; - struct name_separator : pad< one< ':' >, ws > {}; - struct value_separator : padr< one< ',' > > {}; - - struct false_ : string< 'f', 'a', 'l', 's', 'e' > {}; // NOLINT - struct null : string< 'n', 'u', 'l', 'l' > {}; - struct true_ : string< 't', 'r', 'u', 'e' > {}; // NOLINT - - struct digits : plus< abnf::DIGIT > {}; - struct exp : seq< one< 'e', 'E' >, opt< one< '-', '+'> >, must< digits > > {}; - struct frac : if_must< one< '.' >, digits > {}; - struct int_ : sor< one< '0' >, digits > {}; // NOLINT - struct number : seq< opt< one< '-' > >, int_, opt< frac >, opt< exp > > {}; - - struct xdigit : abnf::HEXDIG {}; - struct unicode : list< seq< one< 'u' >, rep< 4, must< xdigit > > >, one< '\\' > > {}; - struct escaped_char : one< '"', '\\', '/', 'b', 'f', 'n', 'r', 't' > {}; - struct escaped : sor< escaped_char, unicode > {}; - struct unescaped : utf8::range< 0x20, 0x10FFFF > {}; - struct char_ : if_then_else< one< '\\' >, must< escaped >, unescaped > {}; // NOLINT - - struct string_content : until< at< one< '"' > >, must< char_ > > {}; - struct string : seq< one< '"' >, must< string_content >, any > - { - using content = string_content; - }; - - struct key_content : until< at< one< '"' > >, must< char_ > > {}; - struct key : seq< one< '"' >, must< key_content >, any > - { - using content = key_content; - }; - - struct value; - - struct array_element; - struct array_content : opt< list_must< array_element, value_separator > > {}; - struct array : seq< begin_array, array_content, must< end_array > > - { - using begin = begin_array; - using end = end_array; - using element = array_element; - using content = array_content; - }; - - struct member : if_must< key, name_separator, value > {}; - struct object_content : opt< list_must< member, value_separator > > {}; - struct object : seq< begin_object, object_content, must< end_object > > - { - using begin = begin_object; - using end = end_object; - using element = member; - using content = object_content; - }; - - struct value : padr< sor< string, number, object, array, false_, true_, null > > {}; - struct array_element : seq< value > {}; - - struct text : seq< star< ws >, value > {}; - // clang-format on - - } // namespace json - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 10 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/json_pointer.hpp" - -#line 1 "tao/pegtl/contrib/json_pointer.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_JSON_POINTER_HPP -#define TAO_PEGTL_CONTRIB_JSON_POINTER_HPP - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace json_pointer - { - // JSON pointer grammar according to RFC 6901 - - // clang-format off - struct unescaped : utf8::ranges< 0x0, 0x2E, 0x30, 0x7D, 0x7F, 0x10FFFF > {}; - struct escaped : seq< one< '~' >, one< '0', '1' > > {}; - - struct reference_token : star< sor< unescaped, escaped > > {}; - struct json_pointer : star< one< '/' >, reference_token > {}; - // clang-format on - - // relative JSON pointer, see ... - - // clang-format off - struct non_negative_integer : sor< one< '0' >, plus< digit > > {}; - struct relative_json_pointer : seq< non_negative_integer, sor< one< '#' >, json_pointer > > {}; - // clang-format on - - } // namespace json_pointer - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 11 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/parse_tree.hpp" - -#line 1 "tao/pegtl/contrib/parse_tree.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_PARSE_TREE_HPP -#define TAO_PEGTL_CONTRIB_PARSE_TREE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - - -#line 1 "tao/pegtl/contrib/shuffle_states.hpp" - -#line 1 "tao/pegtl/contrib/shuffle_states.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_SHUFFLE_STATES_HPP -#define TAO_PEGTL_CONTRIB_SHUFFLE_STATES_HPP - -#include -#include - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< std::size_t N > - struct rotate_left - { - template< std::size_t I, std::size_t S > - using type = std::integral_constant< std::size_t, ( I + N ) % S >; - }; - - template< std::size_t N > - struct rotate_right - { - template< std::size_t I, std::size_t S > - using type = std::integral_constant< std::size_t, ( I + S - N ) % S >; - }; - - struct reverse - { - template< std::size_t I, std::size_t S > - using type = std::integral_constant< std::size_t, ( S - 1 ) - I >; - }; - - } // namespace internal - - // Applies 'Shuffle' to the states of start(), success(), failure(), raise(), apply(), and apply0() - template< typename Base, typename Shuffle > - struct shuffle_states - : Base - { - template< typename Input, typename Tuple, std::size_t... Is > - static void start_impl( const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::start( in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ) ) ) - { - Base::start( in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ); - } - - template< typename Input, typename... States > - static void start( const Input& in, States&&... st ) noexcept( noexcept( start_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ) ) ) - { - start_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ); - } - - template< typename Input, typename State > - static void start( const Input& in, State&& st ) noexcept( noexcept( Base::start( in, st ) ) ) - { - Base::start( in, st ); - } - - template< typename Input, typename Tuple, std::size_t... Is > - static void success_impl( const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::success( in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ) ) ) - { - Base::success( in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ); - } - - template< typename Input, typename... States > - static void success( const Input& in, States&&... st ) noexcept( noexcept( success_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ) ) ) - { - success_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ); - } - - template< typename Input, typename State > - static void success( const Input& in, State&& st ) noexcept( noexcept( Base::success( in, st ) ) ) - { - Base::success( in, st ); - } - - template< typename Input, typename Tuple, std::size_t... Is > - static void failure_impl( const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::failure( in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ) ) ) - { - Base::failure( in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ); - } - - template< typename Input, typename... States > - static void failure( const Input& in, States&&... st ) noexcept( noexcept( failure_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ) ) ) - { - failure_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ); - } - - template< typename Input, typename State > - static void failure( const Input& in, State&& st ) noexcept( noexcept( Base::failure( in, st ) ) ) - { - Base::failure( in, st ); - } - - template< typename Input, typename Tuple, std::size_t... Is > - static void raise_impl( const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) - { - Base::raise( in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ); - } - - template< typename Input, typename... States > - static void raise( const Input& in, States&&... st ) - { - raise_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ); - } - - template< typename Input, typename State > - static void raise( const Input& in, State&& st ) - { - Base::raise( in, st ); - } - - template< template< typename... > class Action, typename Iterator, typename Input, typename Tuple, std::size_t... Is > - static auto apply_impl( const Iterator& begin, const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::template apply< Action >( begin, in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ) ) ) - -> decltype( Base::template apply< Action >( begin, in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ) ) - { - return Base::template apply< Action >( begin, in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ); - } - - template< template< typename... > class Action, typename Iterator, typename Input, typename... States > - static auto apply( const Iterator& begin, const Input& in, States&&... st ) noexcept( noexcept( apply_impl< Action >( begin, in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ) ) ) - -> decltype( apply_impl< Action >( begin, in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ) ) - { - return apply_impl< Action >( begin, in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ); - } - - template< template< typename... > class Action, typename Iterator, typename Input, typename State > - static auto apply( const Iterator& begin, const Input& in, State&& st ) noexcept( noexcept( Base::template apply< Action >( begin, in, st ) ) ) - -> decltype( Base::template apply< Action >( begin, in, st ) ) - { - return Base::template apply< Action >( begin, in, st ); - } - - template< template< typename... > class Action, typename Input, typename Tuple, std::size_t... Is > - static auto apply0_impl( const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::template apply0< Action >( in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ) ) ) - -> decltype( Base::template apply0< Action >( in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ) ) - { - return Base::template apply0< Action >( in, std::get< Shuffle::template type< Is, sizeof...( Is ) >::value >( t )... ); - } - - template< template< typename... > class Action, typename Input, typename... States > - static auto apply0( const Input& in, States&&... st ) noexcept( noexcept( apply0_impl< Action >( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ) ) ) - -> decltype( apply0_impl< Action >( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ) ) - { - return apply0_impl< Action >( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) >() ); - } - - template< template< typename... > class Action, typename Input, typename State > - static auto apply0( const Input& in, State&& st ) noexcept( noexcept( Base::template apply0< Action >( in, st ) ) ) - -> decltype( Base::template apply0< Action >( in, st ) ) - { - return Base::template apply0< Action >( in, st ); - } - }; - - template< typename Base, std::size_t N = 1 > - using rotate_states_left = shuffle_states< Base, internal::rotate_left< N > >; - - template< typename Base, std::size_t N = 1 > - using rotate_states_right = shuffle_states< Base, internal::rotate_right< N > >; - - template< typename Base > - using reverse_states = shuffle_states< Base, internal::reverse >; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 18 "tao/pegtl/contrib/parse_tree.hpp" -#line 35 "tao/pegtl/contrib/parse_tree.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace parse_tree - { - template< typename T > - struct basic_node - { - using node_t = T; - using children_t = std::vector< std::unique_ptr< node_t > >; - children_t children; - - std::type_index id = std::type_index( typeid( void ) ); - std::string source; - - TAO_PEGTL_NAMESPACE::internal::iterator m_begin; - TAO_PEGTL_NAMESPACE::internal::iterator m_end; - - // each node will be default constructed - basic_node() = default; - - // no copy/move is necessary - // (nodes are always owned/handled by a std::unique_ptr) - basic_node( const basic_node& ) = delete; - basic_node( basic_node&& ) = delete; - - ~basic_node() = default; - - // no assignment either - basic_node& operator=( const basic_node& ) = delete; - basic_node& operator=( basic_node&& ) = delete; - - bool is_root() const noexcept - { - return id == typeid( void ); - } - - template< typename U > - bool is() const noexcept - { - return id == typeid( U ); - } - - std::string name() const - { - assert( !is_root() ); - return TAO_PEGTL_NAMESPACE::internal::demangle( id.name() ); - } - - position begin() const - { - return position( m_begin, source ); - } - - position end() const - { - return position( m_end, source ); - } - - bool has_content() const noexcept - { - return m_end.data != nullptr; - } - - std::string string() const - { - assert( has_content() ); - return std::string( m_begin.data, m_end.data ); - } - - // Compatibility, remove with 3.0.0 - std::string content() const - { - return string(); - } - - template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > - memory_input< P, Eol > as_memory_input() const - { - assert( has_content() ); - return { m_begin.data, m_end.data, source, m_begin.byte, m_begin.line, m_begin.byte_in_line }; - } - - template< typename... States > - void remove_content( States&&... /*unused*/ ) noexcept - { - m_end.reset(); - } - - // all non-root nodes are initialized by calling this method - template< typename Rule, typename Input, typename... States > - void start( const Input& in, States&&... /*unused*/ ) - { - id = typeid( Rule ); - source = in.source(); - m_begin = TAO_PEGTL_NAMESPACE::internal::iterator( in.iterator() ); - } - - // if parsing of the rule succeeded, this method is called - template< typename Rule, typename Input, typename... States > - void success( const Input& in, States&&... /*unused*/ ) noexcept - { - m_end = TAO_PEGTL_NAMESPACE::internal::iterator( in.iterator() ); - } - - // if parsing of the rule failed, this method is called - template< typename Rule, typename Input, typename... States > - void failure( const Input& /*unused*/, States&&... /*unused*/ ) noexcept - { - } - - // if parsing succeeded and the (optional) transform call - // did not discard the node, it is appended to its parent. - // note that "child" is the node whose Rule just succeeded - // and "*this" is the parent where the node should be appended. - template< typename... States > - void emplace_back( std::unique_ptr< node_t >&& child, States&&... /*unused*/ ) - { - assert( child ); - children.emplace_back( std::move( child ) ); - } - }; - - struct node - : basic_node< node > - { - }; - - namespace internal - { - template< typename > - struct is_try_catch_type - : std::false_type - { - }; - - template< typename Exception, typename... Rules > - struct is_try_catch_type< TAO_PEGTL_NAMESPACE::internal::try_catch_type< Exception, Rules... > > - : std::true_type - { - }; - - template< typename Node > - struct state - { - std::vector< std::unique_ptr< Node > > stack; - - state() - { - emplace_back(); - } - - void emplace_back() - { - stack.emplace_back( std::unique_ptr< Node >( new Node ) ); - } - - std::unique_ptr< Node >& back() noexcept - { - assert( !stack.empty() ); - return stack.back(); - } - - void pop_back() noexcept - { - assert( !stack.empty() ); - return stack.pop_back(); - } - }; - - template< typename Selector, typename... Parameters > - void transform( Parameters&&... /*unused*/ ) noexcept - { - } - - template< typename Selector, typename Input, typename Node, typename... States > - auto transform( const Input& in, std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( Selector::transform( in, n, st... ) ) ) - -> decltype( Selector::transform( in, n, st... ), void() ) - { - Selector::transform( in, n, st... ); - } - - template< typename Selector, typename Input, typename Node, typename... States > - auto transform( const Input& /*unused*/, std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( Selector::transform( n, st... ) ) ) - -> decltype( Selector::transform( n, st... ), void() ) - { - Selector::transform( n, st... ); - } - - template< typename Rule, template< typename... > class Selector > - struct is_selected_node - : std::integral_constant< bool, !TAO_PEGTL_NAMESPACE::internal::skip_control< Rule >::value && Selector< Rule >::value > - { - }; - - template< unsigned Level, typename Analyse, template< typename... > class Selector > - struct is_leaf - : std::false_type - { - }; - - template< analysis::rule_type Type, template< typename... > class Selector > - struct is_leaf< 0, analysis::generic< Type >, Selector > - : std::true_type - { - }; - - template< analysis::rule_type Type, std::size_t Count, template< typename... > class Selector > - struct is_leaf< 0, analysis::counted< Type, Count >, Selector > - : std::true_type - { - }; - - template< analysis::rule_type Type, typename... Rules, template< typename... > class Selector > - struct is_leaf< 0, analysis::generic< Type, Rules... >, Selector > - : std::false_type - { - }; - - template< analysis::rule_type Type, std::size_t Count, typename... Rules, template< typename... > class Selector > - struct is_leaf< 0, analysis::counted< Type, Count, Rules... >, Selector > - : std::false_type - { - }; - - template< bool... > - struct bool_sequence; - - template< bool... Bs > - struct is_all - : std::is_same< bool_sequence< Bs..., true >, bool_sequence< true, Bs... > > - { - }; - - template< bool... Bs > - struct is_none - : std::integral_constant< bool, !is_all< !Bs... >::value > - { - }; - - template< unsigned Level, typename Rule, template< typename... > class Selector > - using is_unselected_leaf = std::integral_constant< bool, !is_selected_node< Rule, Selector >::value && is_leaf< Level, typename Rule::analyze_t, Selector >::value >; - - template< unsigned Level, analysis::rule_type Type, typename... Rules, template< typename... > class Selector > - struct is_leaf< Level, analysis::generic< Type, Rules... >, Selector > - : is_all< is_unselected_leaf< Level - 1, Rules, Selector >::value... > - { - }; - - template< unsigned Level, analysis::rule_type Type, std::size_t Count, typename... Rules, template< typename... > class Selector > - struct is_leaf< Level, analysis::counted< Type, Count, Rules... >, Selector > - : is_all< is_unselected_leaf< Level - 1, Rules, Selector >::value... > - { - }; - - template< typename Node, template< typename... > class Selector, template< typename... > class Control > - struct make_control - { - template< typename Rule, bool, bool > - struct state_handler; - - template< typename Rule > - using type = rotate_states_right< state_handler< Rule, is_selected_node< Rule, Selector >::value, is_leaf< 8, typename Rule::analyze_t, Selector >::value > >; - }; - - template< typename Node, template< typename... > class Selector, template< typename... > class Control > - template< typename Rule > - struct make_control< Node, Selector, Control >::state_handler< Rule, false, true > - : remove_first_state< Control< Rule > > - { - }; - - template< typename Node, template< typename... > class Selector, template< typename... > class Control > - template< typename Rule > - struct make_control< Node, Selector, Control >::state_handler< Rule, false, false > - : remove_first_state< Control< Rule > > - { - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control2, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - auto& state = std::get< sizeof...( st ) - 1 >( std::tie( st... ) ); - if( is_try_catch_type< Rule >::value ) { - internal::state< Node > tmp; - tmp.emplace_back(); - tmp.stack.swap( state.stack ); - const bool result = Control< Rule >::template match< A, M, Action, Control2 >( in, st... ); - tmp.stack.swap( state.stack ); - if( result ) { - for( auto& c : tmp.back()->children ) { - state.back()->children.emplace_back( std::move( c ) ); - } - } - return result; - } - state.emplace_back(); - const bool result = Control< Rule >::template match< A, M, Action, Control2 >( in, st... ); - if( result ) { - auto n = std::move( state.back() ); - state.pop_back(); - for( auto& c : n->children ) { - state.back()->children.emplace_back( std::move( c ) ); - } - } - else { - state.pop_back(); - } - return result; - } - }; - - template< typename Node, template< typename... > class Selector, template< typename... > class Control > - template< typename Rule, bool B > - struct make_control< Node, Selector, Control >::state_handler< Rule, true, B > - : remove_first_state< Control< Rule > > - { - template< typename Input, typename... States > - static void start( const Input& in, state< Node >& state, States&&... st ) - { - Control< Rule >::start( in, st... ); - state.emplace_back(); - state.back()->template start< Rule >( in, st... ); - } - - template< typename Input, typename... States > - static void success( const Input& in, state< Node >& state, States&&... st ) - { - Control< Rule >::success( in, st... ); - auto n = std::move( state.back() ); - state.pop_back(); - n->template success< Rule >( in, st... ); - transform< Selector< Rule > >( in, n, st... ); - if( n ) { - state.back()->emplace_back( std::move( n ), st... ); - } - } - - template< typename Input, typename... States > - static void failure( const Input& in, state< Node >& state, States&&... st ) noexcept( noexcept( Control< Rule >::failure( in, st... ) ) && noexcept( std::declval< Node& >().template failure< Rule >( in, st... ) ) ) - { - Control< Rule >::failure( in, st... ); - state.back()->template failure< Rule >( in, st... ); - state.pop_back(); - } - }; - - template< typename > - using store_all = std::true_type; - - template< typename > - struct selector; - - template<> - struct selector< std::tuple<> > - { - using type = std::false_type; - }; - - template< typename T > - struct selector< std::tuple< T > > - { - using type = typename T::type; - }; - - template< typename... Ts > - struct selector< std::tuple< Ts... > > - { - static_assert( sizeof...( Ts ) == 0, "multiple matches found" ); - }; - - template< typename Rule, typename Collection > - using select_tuple = typename std::conditional< Collection::template contains< Rule >::value, std::tuple< Collection >, std::tuple<> >::type; - - } // namespace internal - - template< typename Rule, typename... Collections > - struct selector - : internal::selector< decltype( std::tuple_cat( std::declval< internal::select_tuple< Rule, Collections > >()... ) ) >::type - {}; - - template< typename Base > - struct apply - : std::true_type - { - template< typename... Rules > - struct on - { - using type = Base; - - template< typename Rule > - using contains = internal::is_none< std::is_same< Rule, Rules >::value... >; - }; - }; - - struct store_content - : apply< store_content > - {}; - - // some nodes don't need to store their content - struct remove_content - : apply< remove_content > - { - template< typename Node, typename... States > - static void transform( std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( n->Node::remove_content( st... ) ) ) - { - n->remove_content( st... ); - } - }; - - // if a node has only one child, replace the node with its child, otherwise remove content - struct fold_one - : apply< fold_one > - { - template< typename Node, typename... States > - static void transform( std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( n->children.size(), n->Node::remove_content( st... ) ) ) - { - if( n->children.size() == 1 ) { - n = std::move( n->children.front() ); - } - else { - n->remove_content( st... ); - } - } - }; - - // if a node has no children, discard the node, otherwise remove content - struct discard_empty - : apply< discard_empty > - { - template< typename Node, typename... States > - static void transform( std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( n->children.empty(), n->Node::remove_content( st... ) ) ) - { - if( n->children.empty() ) { - n.reset(); - } - else { - n->remove_content( st... ); - } - } - }; - - template< typename Rule, - typename Node, - template< typename... > class Selector = internal::store_all, - template< typename... > class Action = nothing, - template< typename... > class Control = normal, - typename Input, - typename... States > - std::unique_ptr< Node > parse( Input&& in, States&&... st ) - { - internal::state< Node > state; - if( !TAO_PEGTL_NAMESPACE::parse< Rule, Action, internal::make_control< Node, Selector, Control >::template type >( in, st..., state ) ) { - return nullptr; - } - assert( state.stack.size() == 1 ); - return std::move( state.back() ); - } - - template< typename Rule, - template< typename... > class Selector = internal::store_all, - template< typename... > class Action = nothing, - template< typename... > class Control = normal, - typename Input, - typename... States > - std::unique_ptr< node > parse( Input&& in, States&&... st ) - { - return parse< Rule, node, Selector, Action, Control >( in, st... ); - } - - } // namespace parse_tree - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 12 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/parse_tree_to_dot.hpp" - -#line 1 "tao/pegtl/contrib/parse_tree_to_dot.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_PARSE_TREE_TO_DOT_HPP -#define TAO_PEGTL_CONTRIB_PARSE_TREE_TO_DOT_HPP - -#include -#include -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace parse_tree - { - namespace internal - { - inline void escape( std::ostream& os, const char* p, const std::size_t s ) - { - static const char* h = "0123456789abcdef"; - - const char* l = p; - const char* const e = p + s; - while( p != e ) { - const unsigned char c = *p; - if( c == '\\' ) { - os.write( l, p - l ); - l = ++p; - os << "\\\\"; - } - else if( c == '"' ) { - os.write( l, p - l ); - l = ++p; - os << "\\\""; - } - else if( c < 32 ) { - os.write( l, p - l ); - l = ++p; - switch( c ) { - case '\b': - os << "\\b"; - break; - case '\f': - os << "\\f"; - break; - case '\n': - os << "\\n"; - break; - case '\r': - os << "\\r"; - break; - case '\t': - os << "\\t"; - break; - default: - os << "\\u00" << h[ ( c & 0xf0 ) >> 4 ] << h[ c & 0x0f ]; - } - } - else if( c == 127 ) { - os.write( l, p - l ); - l = ++p; - os << "\\u007f"; - } - else { - ++p; - } - } - os.write( l, p - l ); - } - - inline void escape( std::ostream& os, const std::string& s ) - { - escape( os, s.data(), s.size() ); - } - - template< typename Node > - void print_dot_node( std::ostream& os, const Node& n, const std::string& s ) - { - os << " x" << &n << " [ label=\""; - escape( os, s ); - if( n.has_content() ) { - os << "\\n"; - escape( os, n.m_begin.data, n.m_end.data - n.m_begin.data ); - } - os << "\" ]\n"; - if( !n.children.empty() ) { - os << " x" << &n << " -> { "; - for( auto& up : n.children ) { - os << "x" << up.get() << ( ( up == n.children.back() ) ? " }\n" : ", " ); - } - for( auto& up : n.children ) { - print_dot_node( os, *up, up->name() ); - } - } - } - - } // namespace internal - - template< typename Node > - void print_dot( std::ostream& os, const Node& n ) - { - os << "digraph parse_tree\n{\n"; - internal::print_dot_node( os, n, n.is_root() ? "ROOT" : n.name() ); - os << "}\n"; - } - - } // namespace parse_tree - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 13 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/raw_string.hpp" - -#line 1 "tao/pegtl/contrib/raw_string.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_RAW_STRING_HPP -#define TAO_PEGTL_CONTRIB_RAW_STRING_HPP - -#include -#include -#line 25 "tao/pegtl/contrib/raw_string.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< char Open, char Marker > - struct raw_string_open - { - using analyze_t = analysis::generic< analysis::rule_type::any >; - - template< apply_mode A, - rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, std::size_t& marker_size, States&&... /*unused*/ ) noexcept( noexcept( in.size( 0 ) ) ) - { - if( in.empty() || ( in.peek_char( 0 ) != Open ) ) { - return false; - } - for( std::size_t i = 1; i < in.size( i + 1 ); ++i ) { - switch( const auto c = in.peek_char( i ) ) { - case Open: - marker_size = i + 1; - in.bump_in_this_line( marker_size ); - eol::match( in ); - return true; - case Marker: - break; - default: - return false; - } - } - return false; - } - }; - - template< char Open, char Marker > - struct skip_control< raw_string_open< Open, Marker > > : std::true_type - { - }; - - template< char Marker, char Close > - struct at_raw_string_close - { - using analyze_t = analysis::generic< analysis::rule_type::opt >; - - template< apply_mode A, - rewind_mode, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, const std::size_t& marker_size, States&&... /*unused*/ ) noexcept( noexcept( in.size( 0 ) ) ) - { - if( in.size( marker_size ) < marker_size ) { - return false; - } - if( in.peek_char( 0 ) != Close ) { - return false; - } - if( in.peek_char( marker_size - 1 ) != Close ) { - return false; - } - for( std::size_t i = 0; i < ( marker_size - 2 ); ++i ) { - if( in.peek_char( i + 1 ) != Marker ) { - return false; - } - } - return true; - } - }; - - template< char Marker, char Close > - struct skip_control< at_raw_string_close< Marker, Close > > : std::true_type - { - }; - - template< typename Cond, typename... Rules > - struct raw_string_until; - - template< typename Cond > - struct raw_string_until< Cond > - { - using analyze_t = analysis::generic< analysis::rule_type::seq, star< not_at< Cond >, not_at< eof >, bytes< 1 > >, Cond >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, const std::size_t& marker_size, States&&... st ) - { - auto m = in.template mark< M >(); - - while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, marker_size, st... ) ) { - if( in.empty() ) { - return false; - } - in.bump(); - } - return m( true ); - } - }; - - template< typename Cond, typename... Rules > - struct raw_string_until - { - using analyze_t = analysis::generic< analysis::rule_type::seq, star< not_at< Cond >, not_at< eof >, Rules... >, Cond >; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, const std::size_t& marker_size, States&&... st ) - { - auto m = in.template mark< M >(); - using m_t = decltype( m ); - - while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, marker_size, st... ) ) { - if( in.empty() || ( !Control< seq< Rules... > >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) ) { - return false; - } - } - return m( true ); - } - }; - - template< typename Cond, typename... Rules > - struct skip_control< raw_string_until< Cond, Rules... > > : std::true_type - { - }; - - } // namespace internal - - // raw_string matches Lua-style long literals. - // - // The following description was taken from the Lua documentation - // (see http://www.lua.org/docs.html): - // - // - An "opening long bracket of level n" is defined as an opening square - // bracket followed by n equal signs followed by another opening square - // bracket. So, an opening long bracket of level 0 is written as `[[`, - // an opening long bracket of level 1 is written as `[=[`, and so on. - // - A "closing long bracket" is defined similarly; for instance, a closing - // long bracket of level 4 is written as `]====]`. - // - A "long literal" starts with an opening long bracket of any level and - // ends at the first closing long bracket of the same level. It can - // contain any text except a closing bracket of the same level. - // - Literals in this bracketed form can run for several lines, do not - // interpret any escape sequences, and ignore long brackets of any other - // level. - // - For convenience, when the opening long bracket is immediately followed - // by a newline, the newline is not included in the string. - // - // Note that unlike Lua's long literal, a raw_string is customizable to use - // other characters than `[`, `=` and `]` for matching. Also note that Lua - // introduced newline-specific replacements in Lua 5.2, which we do not - // support on the grammar level. - - template< char Open, char Marker, char Close, typename... Contents > - struct raw_string - { - // This is used for binding the apply()-method and for error-reporting - // when a raw string is not closed properly or has invalid content. - struct content - : internal::raw_string_until< internal::at_raw_string_close< Marker, Close >, Contents... > - { - }; - - using analyze_t = typename internal::seq< internal::bytes< 1 >, content, internal::bytes< 1 > >::analyze_t; - - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - static bool match( Input& in, States&&... st ) - { - std::size_t marker_size; - if( internal::raw_string_open< Open, Marker >::template match< A, M, Action, Control >( in, marker_size, st... ) ) { - internal::must< content >::template match< A, M, Action, Control >( in, marker_size, st... ); - in.bump_in_this_line( marker_size ); - return true; - } - return false; - } - }; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 14 "amalgamated.hpp" - -#line 1 "tao/pegtl/contrib/remove_last_states.hpp" - -#line 1 "tao/pegtl/contrib/remove_last_states.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_REMOVE_LAST_STATES_HPP -#define TAO_PEGTL_CONTRIB_REMOVE_LAST_STATES_HPP - -#include -#include - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - // Remove the last N states of start(), success(), failure(), raise(), apply(), and apply0() - template< typename Base, std::size_t N > - struct remove_last_states - : Base - { - template< typename Input, typename Tuple, std::size_t... Is > - static void start_impl( const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::start( in, std::get< Is >( t )... ) ) ) - { - Base::start( in, std::get< Is >( t )... ); - } - - template< typename Input, typename... States > - static void start( const Input& in, States&&... st ) noexcept( noexcept( start_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ) ) ) - { - start_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ); - } - - template< typename Input, typename Tuple, std::size_t... Is > - static void success_impl( const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::success( in, std::get< Is >( t )... ) ) ) - { - Base::success( in, std::get< Is >( t )... ); - } - - template< typename Input, typename... States > - static void success( const Input& in, States&&... st ) noexcept( noexcept( success_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ) ) ) - { - success_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ); - } - - template< typename Input, typename Tuple, std::size_t... Is > - static void failure_impl( const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::failure( in, std::get< Is >( t )... ) ) ) - { - Base::failure( in, std::get< Is >( t )... ); - } - - template< typename Input, typename... States > - static void failure( const Input& in, States&&... st ) noexcept( noexcept( failure_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ) ) ) - { - failure_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ); - } - - template< typename Input, typename Tuple, std::size_t... Is > - static void raise_impl( const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) - { - Base::raise( in, std::get< Is >( t )... ); - } - - template< typename Input, typename... States > - static void raise( const Input& in, States&&... st ) - { - raise_impl( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ); - } - - template< template< typename... > class Action, typename Iterator, typename Input, typename Tuple, std::size_t... Is > - static auto apply_impl( const Iterator& begin, const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::template apply< Action >( begin, in, std::get< Is >( t )... ) ) ) - -> decltype( Base::template apply< Action >( begin, in, std::get< Is >( t )... ) ) - { - return Base::template apply< Action >( begin, in, std::get< Is >( t )... ); - } - - template< template< typename... > class Action, typename Iterator, typename Input, typename... States > - static auto apply( const Iterator& begin, const Input& in, States&&... st ) noexcept( noexcept( apply_impl< Action >( begin, in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ) ) ) - -> decltype( apply_impl< Action >( begin, in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ) ) - { - return apply_impl< Action >( begin, in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ); - } - - template< template< typename... > class Action, typename Input, typename Tuple, std::size_t... Is > - static auto apply0_impl( const Input& in, const Tuple& t, internal::index_sequence< Is... > /*unused*/ ) noexcept( noexcept( Base::template apply0< Action >( in, std::get< Is >( t )... ) ) ) - -> decltype( Base::template apply0< Action >( in, std::get< Is >( t )... ) ) - { - return Base::template apply0< Action >( in, std::get< Is >( t )... ); - } - - template< template< typename... > class Action, typename Input, typename... States > - static auto apply0( const Input& in, States&&... st ) noexcept( noexcept( apply0_impl< Action >( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ) ) ) - -> decltype( apply0_impl< Action >( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ) ) - { - return apply0_impl< Action >( in, std::tie( st... ), internal::make_index_sequence< sizeof...( st ) - N >() ); - } - }; - - template< typename Base > - using remove_last_state = remove_last_states< Base, 1 >; - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 16 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/rep_one_min_max.hpp" - -#line 1 "tao/pegtl/contrib/rep_one_min_max.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_REP_ONE_MIN_MAX_HPP -#define TAO_PEGTL_CONTRIB_REP_ONE_MIN_MAX_HPP - -#include -#line 16 "tao/pegtl/contrib/rep_one_min_max.hpp" -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< unsigned Min, unsigned Max, char C > - struct rep_one_min_max - { - using analyze_t = analysis::counted< analysis::rule_type::any, Min >; - - static_assert( Min <= Max, "invalid rep_one_min_max rule (maximum number of repetitions smaller than minimum)" ); - - template< typename Input > - static bool match( Input& in ) - { - const auto size = in.size( Max + 1 ); - if( size < Min ) { - return false; - } - std::size_t i = 0; - while( ( i < size ) && ( in.peek_char( i ) == C ) ) { - ++i; - } - if( ( Min <= i ) && ( i <= Max ) ) { - bump_help< result_on_found::success, Input, char, C >( in, i ); - return true; - } - return false; - } - }; - - template< unsigned Min, unsigned Max, char C > - struct skip_control< rep_one_min_max< Min, Max, C > > : std::true_type - { - }; - - } // namespace internal - - inline namespace ascii - { - template< unsigned Min, unsigned Max, char C > - struct rep_one_min_max : internal::rep_one_min_max< Min, Max, C > - { - }; - - } // namespace ascii - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 17 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/rep_string.hpp" - -#line 1 "tao/pegtl/contrib/rep_string.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_REP_STRING_HPP -#define TAO_PEGTL_CONTRIB_REP_STRING_HPP - -#include - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< std::size_t, typename, char... > - struct make_rep_string; - - template< char... Ss, char... Cs > - struct make_rep_string< 0, string< Ss... >, Cs... > - { - using type = string< Ss... >; - }; - - template< std::size_t N, char... Ss, char... Cs > - struct make_rep_string< N, string< Ss... >, Cs... > - : make_rep_string< N - 1, string< Ss..., Cs... >, Cs... > - {}; - - } // namespace internal - - inline namespace ascii - { - template< std::size_t N, char... Cs > - struct rep_string - : internal::make_rep_string< N, internal::string<>, Cs... >::type - {}; - - } // namespace ascii - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 18 "amalgamated.hpp" - -#line 1 "tao/pegtl/contrib/to_string.hpp" - -#line 1 "tao/pegtl/contrib/to_string.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_TO_STRING_HPP -#define TAO_PEGTL_CONTRIB_TO_STRING_HPP - -#include - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename > - struct to_string; - - template< template< char... > class X, char... Cs > - struct to_string< X< Cs... > > - { - static std::string get() - { - const char s[] = { Cs..., 0 }; - return std::string( s, sizeof...( Cs ) ); - } - }; - - } // namespace internal - - template< typename T > - std::string to_string() - { - return internal::to_string< T >::get(); - } - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 20 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/tracer.hpp" - -#line 1 "tao/pegtl/contrib/tracer.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_TRACER_HPP -#define TAO_PEGTL_CONTRIB_TRACER_HPP - -#include -#include -#include -#include -#include - - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace internal - { - template< typename Input > - void print_current( const Input& in ) - { - if( in.empty() ) { - std::cerr << ""; - } - else { - const auto c = in.peek_uint8(); - switch( c ) { - case 0: - std::cerr << " = "; - break; - case 9: - std::cerr << " = "; - break; - case 10: - std::cerr << " = "; - break; - case 13: - std::cerr << " = "; - break; - default: - if( isprint( c ) ) { - std::cerr << '\'' << c << "' = "; - } - } - std::cerr << "(char)" << unsigned( c ); - } - } - - } // namespace internal - - struct trace_state - { - unsigned rule = 0; - unsigned line = 0; - std::vector< unsigned > stack; - }; - -#if defined( _MSC_VER ) && ( _MSC_VER < 1910 ) - - template< typename Rule > - struct tracer - : normal< Rule > - { - template< typename Input, typename... States > - static void start( const Input& in, States&&... /*unused*/ ) - { - std::cerr << in.position() << " start " << internal::demangle< Rule >() << "; current "; - print_current( in ); - std::cerr << std::endl; - } - - template< typename Input, typename... States > - static void start( const Input& in, trace_state& ts, States&&... st ) - { - std::cerr << std::setw( 6 ) << ++ts.line << " " << std::setw( 6 ) << ++ts.rule << " "; - start( in, st... ); - ts.stack.push_back( ts.rule ); - } - - template< typename Input, typename... States > - static void success( const Input& in, States&&... /*unused*/ ) - { - std::cerr << in.position() << " success " << internal::demangle< Rule >() << "; next "; - print_current( in ); - std::cerr << std::endl; - } - - template< typename Input, typename... States > - static void success( const Input& in, trace_state& ts, States&&... st ) - { - assert( !ts.stack.empty() ); - std::cerr << std::setw( 6 ) << ++ts.line << " " << std::setw( 6 ) << ts.stack.back() << " "; - success( in, st... ); - ts.stack.pop_back(); - } - - template< typename Input, typename... States > - static void failure( const Input& in, States&&... /*unused*/ ) - { - std::cerr << in.position() << " failure " << internal::demangle< Rule >() << std::endl; - } - - template< typename Input, typename... States > - static void failure( const Input& in, trace_state& ts, States&&... st ) - { - assert( !ts.stack.empty() ); - std::cerr << std::setw( 6 ) << ++ts.line << " " << std::setw( 6 ) << ts.stack.back() << " "; - failure( in, st... ); - ts.stack.pop_back(); - } - - template< template< typename... > class Action, typename Iterator, typename Input, typename... States > - static auto apply( const Iterator& begin, const Input& in, States&&... st ) - -> decltype( normal< Rule >::template apply< Action >( begin, in, st... ) ) - { - std::cerr << in.position() << " apply " << internal::demangle< Rule >() << std::endl; - return normal< Rule >::template apply< Action >( begin, in, st... ); - } - - template< template< typename... > class Action, typename Iterator, typename Input, typename... States > - static auto apply( const Iterator& begin, const Input& in, trace_state& ts, States&&... st ) - -> decltype( apply< Action >( begin, in, st... ) ) - { - std::cerr << std::setw( 6 ) << ++ts.line << " "; - return apply< Action >( begin, in, st... ); - } - - template< template< typename... > class Action, typename Input, typename... States > - static auto apply0( const Input& in, States&&... st ) - -> decltype( normal< Rule >::template apply0< Action >( in, st... ) ) - { - std::cerr << in.position() << " apply0 " << internal::demangle< Rule >() << std::endl; - return normal< Rule >::template apply0< Action >( in, st... ); - } - - template< template< typename... > class Action, typename Input, typename... States > - static auto apply0( const Input& in, trace_state& ts, States&&... st ) - -> decltype( apply0< Action >( in, st... ) ) - { - std::cerr << std::setw( 6 ) << ++ts.line << " "; - return apply0< Action >( in, st... ); - } - }; - -#else - - template< template< typename... > class Base > - struct trace - { - template< typename Rule > - struct control - : Base< Rule > - { - template< typename Input, typename... States > - static void start( const Input& in, States&&... st ) - { - std::cerr << in.position() << " start " << internal::demangle< Rule >() << "; current "; - print_current( in ); - std::cerr << std::endl; - Base< Rule >::start( in, st... ); - } - - template< typename Input, typename... States > - static void start( const Input& in, trace_state& ts, States&&... st ) - { - std::cerr << std::setw( 6 ) << ++ts.line << " " << std::setw( 6 ) << ++ts.rule << " "; - start( in, st... ); - ts.stack.push_back( ts.rule ); - } - - template< typename Input, typename... States > - static void success( const Input& in, States&&... st ) - { - std::cerr << in.position() << " success " << internal::demangle< Rule >() << "; next "; - print_current( in ); - std::cerr << std::endl; - Base< Rule >::success( in, st... ); - } - - template< typename Input, typename... States > - static void success( const Input& in, trace_state& ts, States&&... st ) - { - assert( !ts.stack.empty() ); - std::cerr << std::setw( 6 ) << ++ts.line << " " << std::setw( 6 ) << ts.stack.back() << " "; - success( in, st... ); - ts.stack.pop_back(); - } - - template< typename Input, typename... States > - static void failure( const Input& in, States&&... st ) - { - std::cerr << in.position() << " failure " << internal::demangle< Rule >() << std::endl; - Base< Rule >::failure( in, st... ); - } - - template< typename Input, typename... States > - static void failure( const Input& in, trace_state& ts, States&&... st ) - { - assert( !ts.stack.empty() ); - std::cerr << std::setw( 6 ) << ++ts.line << " " << std::setw( 6 ) << ts.stack.back() << " "; - failure( in, st... ); - ts.stack.pop_back(); - } - - template< template< typename... > class Action, typename Iterator, typename Input, typename... States > - static auto apply( const Iterator& begin, const Input& in, States&&... st ) - -> decltype( Base< Rule >::template apply< Action >( begin, in, st... ) ) - { - std::cerr << in.position() << " apply " << internal::demangle< Rule >() << std::endl; - return Base< Rule >::template apply< Action >( begin, in, st... ); - } - - template< template< typename... > class Action, typename Iterator, typename Input, typename... States > - static auto apply( const Iterator& begin, const Input& in, trace_state& ts, States&&... st ) - -> decltype( apply< Action >( begin, in, st... ) ) - { - std::cerr << std::setw( 6 ) << ++ts.line << " "; - return apply< Action >( begin, in, st... ); - } - - template< template< typename... > class Action, typename Input, typename... States > - static auto apply0( const Input& in, States&&... st ) - -> decltype( Base< Rule >::template apply0< Action >( in, st... ) ) - { - std::cerr << in.position() << " apply0 " << internal::demangle< Rule >() << std::endl; - return Base< Rule >::template apply0< Action >( in, st... ); - } - - template< template< typename... > class Action, typename Input, typename... States > - static auto apply0( const Input& in, trace_state& ts, States&&... st ) - -> decltype( apply0< Action >( in, st... ) ) - { - std::cerr << std::setw( 6 ) << ++ts.line << " "; - return apply0< Action >( in, st... ); - } - }; - }; - - template< typename Rule > - using tracer = trace< normal >::control< Rule >; - -#endif - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 21 "amalgamated.hpp" -#line 1 "tao/pegtl/contrib/unescape.hpp" - -#line 1 "tao/pegtl/contrib/unescape.hpp" - - - -#ifndef TAO_PEGTL_CONTRIB_UNESCAPE_HPP -#define TAO_PEGTL_CONTRIB_UNESCAPE_HPP - -#include -#include - - - - - -namespace tao -{ - namespace TAO_PEGTL_NAMESPACE - { - namespace unescape - { - // Utility functions for the unescape actions. - - inline bool utf8_append_utf32( std::string& string, const unsigned utf32 ) - { - if( utf32 <= 0x7f ) { - string += char( utf32 & 0xff ); - return true; - } - if( utf32 <= 0x7ff ) { - char tmp[] = { char( ( ( utf32 & 0x7c0 ) >> 6 ) | 0xc0 ), // NOLINT - char( ( ( utf32 & 0x03f ) ) | 0x80 ) }; - string.append( tmp, sizeof( tmp ) ); - return true; - } - if( utf32 <= 0xffff ) { - if( utf32 >= 0xd800 && utf32 <= 0xdfff ) { - // nope, this is a UTF-16 surrogate - return false; - } - char tmp[] = { char( ( ( utf32 & 0xf000 ) >> 12 ) | 0xe0 ), // NOLINT - char( ( ( utf32 & 0x0fc0 ) >> 6 ) | 0x80 ), - char( ( ( utf32 & 0x003f ) ) | 0x80 ) }; - string.append( tmp, sizeof( tmp ) ); - return true; - } - if( utf32 <= 0x10ffff ) { - char tmp[] = { char( ( ( utf32 & 0x1c0000 ) >> 18 ) | 0xf0 ), // NOLINT - char( ( ( utf32 & 0x03f000 ) >> 12 ) | 0x80 ), - char( ( ( utf32 & 0x000fc0 ) >> 6 ) | 0x80 ), - char( ( ( utf32 & 0x00003f ) ) | 0x80 ) }; - string.append( tmp, sizeof( tmp ) ); - return true; - } - return false; - } - - // This function MUST only be called for characters matching TAO_PEGTL_NAMESPACE::ascii::xdigit! - template< typename I > - I unhex_char( const char c ) - { - switch( c ) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - return I( c - '0' ); - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - return I( c - 'a' + 10 ); - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - return I( c - 'A' + 10 ); - default: // LCOV_EXCL_LINE - throw std::runtime_error( "invalid character in unhex" ); // NOLINT, LCOV_EXCL_LINE - } - } - - template< typename I > - I unhex_string( const char* begin, const char* end ) - { - I r = 0; - while( begin != end ) { - r <<= 4; - r += unhex_char< I >( *begin++ ); - } - return r; - } - - // Actions for common unescape situations. - - struct append_all - { - template< typename Input > - static void apply( const Input& in, std::string& s ) - { - s.append( in.begin(), in.size() ); - } - }; - - // This action MUST be called for a character matching T which MUST be TAO_PEGTL_NAMESPACE::one< ... >. - template< typename T, char... Rs > - struct unescape_c - { - template< typename Input > - static void apply( const Input& in, std::string& s ) - { - assert( in.size() == 1 ); - s += apply_one( in, static_cast< const T* >( nullptr ) ); - } - - template< typename Input, char... Qs > - static char apply_one( const Input& in, const one< Qs... >* /*unused*/ ) - { - static_assert( sizeof...( Qs ) == sizeof...( Rs ), "size mismatch between escaped characters and their mappings" ); - return apply_two( in, { Qs... }, { Rs... } ); - } - - template< typename Input > - static char apply_two( const Input& in, const std::initializer_list< char >& q, const std::initializer_list< char >& r ) - { - const char c = *in.begin(); - for( std::size_t i = 0; i < q.size(); ++i ) { - if( *( q.begin() + i ) == c ) { - return *( r.begin() + i ); - } - } - throw parse_error( "invalid character in unescape", in ); // NOLINT, LCOV_EXCL_LINE - } - }; - - // See src/example/pegtl/unescape.cpp for why the following two actions - // skip the first input character. They also MUST be called - // with non-empty matched inputs! - - struct unescape_u - { - template< typename Input > - static void apply( const Input& in, std::string& s ) - { - assert( !in.empty() ); // First character MUST be present, usually 'u' or 'U'. - if( !utf8_append_utf32( s, unhex_string< unsigned >( in.begin() + 1, in.end() ) ) ) { - throw parse_error( "invalid escaped unicode code point", in ); - } - } - }; - - struct unescape_x - { - template< typename Input > - static void apply( const Input& in, std::string& s ) - { - assert( !in.empty() ); // First character MUST be present, usually 'x'. - s += unhex_string< char >( in.begin() + 1, in.end() ); - } - }; - - // The unescape_j action is similar to unescape_u, however unlike - // unescape_u it - // (a) assumes exactly 4 hexdigits per escape sequence, - // (b) accepts multiple consecutive escaped 16-bit values. - // When applied to more than one escape sequence, unescape_j - // translates UTF-16 surrogate pairs in the input into a single - // UTF-8 sequence in s, as required for JSON by RFC 8259. - - struct unescape_j - { - template< typename Input > - static void apply( const Input& in, std::string& s ) - { - assert( ( ( in.size() + 1 ) % 6 ) == 0 ); // Expects multiple "\\u1234", starting with the first "u". - for( const char* b = in.begin() + 1; b < in.end(); b += 6 ) { - const auto c = unhex_string< unsigned >( b, b + 4 ); - if( ( 0xd800 <= c ) && ( c <= 0xdbff ) && ( b + 6 < in.end() ) ) { - const auto d = unhex_string< unsigned >( b + 6, b + 10 ); - if( ( 0xdc00 <= d ) && ( d <= 0xdfff ) ) { - b += 6; - (void)utf8_append_utf32( s, ( ( ( c & 0x03ff ) << 10 ) | ( d & 0x03ff ) ) + 0x10000 ); - continue; - } - } - if( !utf8_append_utf32( s, c ) ) { - throw parse_error( "invalid escaped unicode code point", in ); - } - } - } - }; - - } // namespace unescape - - } // namespace TAO_PEGTL_NAMESPACE - -} // namespace tao - -#endif -#line 22 "amalgamated.hpp" diff --git a/pxr/base/tf/pxrPEGTL/pxr-pegtl.patch b/pxr/base/tf/pxrPEGTL/pxr-pegtl.patch deleted file mode 100644 index 058d8e2dff..0000000000 --- a/pxr/base/tf/pxrPEGTL/pxr-pegtl.patch +++ /dev/null @@ -1,36 +0,0 @@ -diff --git a/pxr/base/tf/pxrPEGTL/pegtl.h b/pxr/base/tf/pxrPEGTL/pegtl.h -index b14aebed2..e6b8962d7 100644 ---- a/pxr/base/tf/pxrPEGTL/pegtl.h -+++ b/pxr/base/tf/pxrPEGTL/pegtl.h -@@ -29,6 +29,31 @@ SOFTWARE. - - */ - -+// PIXAR: -+// This header is not meant to be included in a .h file, to guard against -+// conflicts if a program includes their own pegtl header and then transitively -+// includes this header. -+#ifdef PXR_PEGTL_H -+#error This file should only be included once in any given source (.cpp) file. -+#endif -+#define PXR_PEGTL_H -+ -+// PIXAR: -+// Define TAO_PEGTL_NAMESPACE based on internal namespace to isolate -+// it from other versions of USD/PEGTL in client code. -+// -+// This would typically be done by wrapping the contents of this header in -+// PXR_NAMESPACE_OPEN_SCOPE and PXR_NAMESPACE_CLOSE_SCOPE, but that would -+// require more invasive changes to this header since there are STL header -+// includes scattered throughout. -+#include "pxr/pxr.h" -+ -+#if PXR_USE_NAMESPACES -+#define TAO_PEGTL_NAMESPACE PXR_INTERNAL_NS ## _pegtl -+#else -+#define TAO_PEGTL_NAMESPACE pxr_pegtl -+#endif -+ - #line 1 "amalgamated.hpp" - #line 1 "" - #line 1 "" diff --git a/pxr/usd/sdf/CMakeLists.txt b/pxr/usd/sdf/CMakeLists.txt index c4c76c96d1..c38fbd29e5 100644 --- a/pxr/usd/sdf/CMakeLists.txt +++ b/pxr/usd/sdf/CMakeLists.txt @@ -6,6 +6,7 @@ pxr_library(sdf arch tf gf + pegtl trace vt work diff --git a/pxr/usd/sdf/moduleDeps.cpp b/pxr/usd/sdf/moduleDeps.cpp index f741db332f..e7abeac9c4 100644 --- a/pxr/usd/sdf/moduleDeps.cpp +++ b/pxr/usd/sdf/moduleDeps.cpp @@ -38,6 +38,7 @@ TF_REGISTRY_FUNCTION(TfScriptModuleLoader) { TfToken("ar"), TfToken("arch"), TfToken("gf"), + TfToken("pegtl"), TfToken("plug"), TfToken("tf"), TfToken("trace"), diff --git a/pxr/usd/sdf/pathExpression.cpp b/pxr/usd/sdf/pathExpression.cpp index be6567f37f..2371f07572 100644 --- a/pxr/usd/sdf/pathExpression.cpp +++ b/pxr/usd/sdf/pathExpression.cpp @@ -753,7 +753,7 @@ struct Sdf_PathExprBuilder namespace { -using namespace tao::TAO_PEGTL_NAMESPACE; +using namespace PXR_PEGTL_NAMESPACE; //////////////////////////////////////////////////////////////////////// // Path patterns with predicates. @@ -1059,7 +1059,7 @@ ParsePathExpression(std::string const &inputStr, std::string errMsg = err.what(); errMsg += " -- "; bool first = true; - for (position const &p: err.positions) { + for (position const &p: err.positions()) { if (!first) { errMsg += ", "; } diff --git a/pxr/usd/sdf/pathParser.cpp b/pxr/usd/sdf/pathParser.cpp index 1fac7fc949..409ed55451 100644 --- a/pxr/usd/sdf/pathParser.cpp +++ b/pxr/usd/sdf/pathParser.cpp @@ -26,7 +26,7 @@ PXR_NAMESPACE_OPEN_SCOPE -using namespace tao::TAO_PEGTL_NAMESPACE; +using namespace PXR_PEGTL_NAMESPACE; namespace Sdf_PathParser { diff --git a/pxr/usd/sdf/pathParser.h b/pxr/usd/sdf/pathParser.h index d4ae61eae9..95b743fee3 100644 --- a/pxr/usd/sdf/pathParser.h +++ b/pxr/usd/sdf/pathParser.h @@ -29,7 +29,7 @@ #include "pxr/base/tf/unicodeUtils.h" #include "pxr/usd/sdf/path.h" -#include "pxr/base/tf/pxrPEGTL/pegtl.h" +#include "pxr/base/pegtl/pegtl.hpp" PXR_NAMESPACE_OPEN_SCOPE @@ -38,7 +38,7 @@ Sdf_ParsePath(std::string const &pathStr, SdfPath *path, std::string *errMsg); namespace Sdf_PathParser { -namespace PEGTL_NS = tao::TAO_PEGTL_NAMESPACE; +namespace PEGTL_NS = PXR_PEGTL_NAMESPACE; //////////////////////////////////////////////////////////////////////// // Helper rules for parsing UTF8 content @@ -51,7 +51,7 @@ struct XidStart { // peek at the next character in the input // if the size is not 0, it was a valid code point - auto utf8_char = tao::TAO_PEGTL_NAMESPACE::internal::peek_utf8::peek(in); + auto utf8_char = PEGTL_NS::internal::peek_utf8::peek(in); if (utf8_char.size != 0) { // valid utf8_char, data has the code point @@ -77,7 +77,7 @@ struct XidContinue { // peek at the next character in the input // if the size is not 0, it was a valid code point - auto utf8_char = tao::TAO_PEGTL_NAMESPACE::internal::peek_utf8::peek(in); + auto utf8_char = PEGTL_NS::internal::peek_utf8::peek(in); if (utf8_char.size != 0) { // valid utf8_char, data has the code point @@ -166,7 +166,7 @@ struct BracketPath : PEGTL_NS::if_must, BracketPath, PEGTL_NS::opt> {}; -struct Expression : TAO_PEGTL_KEYWORD("expression") {}; +struct Expression : PXR_PEGTL_KEYWORD("expression") {}; struct RelAttrSeq : PEGTL_NS::if_must< PEGTL_NS::one<'.'>, RelationalAttributeName, @@ -242,4 +242,4 @@ struct Action : PEGTL_NS::nothing {}; PXR_NAMESPACE_CLOSE_SCOPE -#endif // PXR_USD_SDF_PATH_PARSER_H \ No newline at end of file +#endif // PXR_USD_SDF_PATH_PARSER_H diff --git a/pxr/usd/sdf/predicateExpression.cpp b/pxr/usd/sdf/predicateExpression.cpp index ab56183c95..a0eff16e03 100644 --- a/pxr/usd/sdf/predicateExpression.cpp +++ b/pxr/usd/sdf/predicateExpression.cpp @@ -255,9 +255,8 @@ operator<<(std::ostream &out, SdfPredicateExpression const &expr) SdfPredicateExpression::SdfPredicateExpression( std::string const &input, std::string const &context) { - using namespace tao::TAO_PEGTL_NAMESPACE; + using namespace PXR_PEGTL_NAMESPACE; - Analyze(); try { SdfPredicateExprBuilder builder; // Uncomment the 'tracer' bit below for debugging. @@ -272,7 +271,7 @@ SdfPredicateExpression::SdfPredicateExpression( std::string errMsg = err.what(); errMsg += " -- "; bool first = true; - for (position const &p: err.positions) { + for (position const &p: err.positions()) { if (!first) { errMsg += ", "; } diff --git a/pxr/usd/sdf/predicateExpressionParser.h b/pxr/usd/sdf/predicateExpressionParser.h index 4c532436bf..bb4cbeec70 100644 --- a/pxr/usd/sdf/predicateExpressionParser.h +++ b/pxr/usd/sdf/predicateExpressionParser.h @@ -31,7 +31,7 @@ #include "pxr/base/tf/diagnostic.h" #include "pxr/base/vt/value.h" -#include "pxr/base/tf/pxrPEGTL/pegtl.h" +#include "pxr/base/pegtl/pegtl.hpp" #include @@ -162,7 +162,7 @@ struct SdfPredicateExprBuilder namespace { -using namespace tao::TAO_PEGTL_NAMESPACE; +using namespace PXR_PEGTL_NAMESPACE; template using LookaheadList = seq, Sep, Rule>>; @@ -401,15 +401,6 @@ template <> struct PredAction template <> struct PredAction : PredCallAction {}; -template -static void Analyze() { - static const size_t numIssues = analyze(); - if (numIssues) { - TF_FATAL_ERROR("%zu issues found in '%s'", numIssues, - TF_FUNC_NAME().c_str()); - } -} - } PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/sdf/variableExpressionParser.cpp b/pxr/usd/sdf/variableExpressionParser.cpp index 1be031b382..9f644a4c73 100644 --- a/pxr/usd/sdf/variableExpressionParser.cpp +++ b/pxr/usd/sdf/variableExpressionParser.cpp @@ -27,12 +27,13 @@ #include "pxr/usd/sdf/debugCodes.h" #include "pxr/usd/sdf/variableExpressionImpl.h" -#include "pxr/base/tf/pxrPEGTL/pegtl.h" +#include "pxr/base/pegtl/pegtl.hpp" +#include "pxr/base/pegtl/pegtl/contrib/trace.hpp" #include "pxr/base/tf/stringUtils.h" #include -using namespace tao::TAO_PEGTL_NAMESPACE; +using namespace PXR_PEGTL_NAMESPACE; PXR_NAMESPACE_OPEN_SCOPE @@ -305,6 +306,7 @@ class ParserContext // Parser utilities ----------------------------------------------- template +[[noreturn]] void _ThrowParseError(const Input& in, const std::string& msg) { // XXX: @@ -316,8 +318,7 @@ void _ThrowParseError(const Input& in, const std::string& msg) // pegtl 3.x adds API to parse_error to decompose the error message, // so we could use that later. - // throw parse_error(errorMsg, in); - throw parse_error(msg, std::vector{ in.position() }); + throw parse_error(msg, in); } // Parser grammar ----------------------------------------------- @@ -444,15 +445,15 @@ struct Integer // for users working in those languages while writing expressions. struct BooleanTrue : sor< - TAO_PEGTL_KEYWORD("True"), - TAO_PEGTL_KEYWORD("true") + PXR_PEGTL_KEYWORD("True"), + PXR_PEGTL_KEYWORD("true") > {}; struct BooleanFalse : sor< - TAO_PEGTL_KEYWORD("False"), - TAO_PEGTL_KEYWORD("false") + PXR_PEGTL_KEYWORD("False"), + PXR_PEGTL_KEYWORD("false") > {}; @@ -467,8 +468,8 @@ struct Boolean struct None : sor< - TAO_PEGTL_KEYWORD("None"), - TAO_PEGTL_KEYWORD("none") + PXR_PEGTL_KEYWORD("None"), + PXR_PEGTL_KEYWORD("none") > {}; @@ -761,7 +762,7 @@ struct Errors static const std::string errorMsg; template - static void raise(const Input& in, States&&...) + [[noreturn]] static void raise(const Input& in, States&&...) { _ThrowParseError(in, errorMsg); } @@ -797,7 +798,7 @@ MATCH_ERROR(SingleQuotedString::End, R"(Missing ending "'")"); Sdf_VariableExpressionParserResult Sdf_ParseVariableExpression(const std::string& expr) { - namespace pegtl = tao::TAO_PEGTL_NAMESPACE; + namespace pegtl = PXR_PEGTL_NAMESPACE; ParserContext context; @@ -806,8 +807,7 @@ Sdf_ParseVariableExpression(const std::string& expr) try { const bool parseSuccess = TfDebug::IsEnabled(SDF_VARIABLE_EXPRESSION_PARSING) ? - pegtl::parse::control>(in, context) : + pegtl::standard_trace(in, context) : pegtl::parse(in, context); if (!parseSuccess) { @@ -820,10 +820,10 @@ Sdf_ParseVariableExpression(const std::string& expr) // XXX: "at character" is probably incorrect if the expression // contains Unicode strings? - { TfStringPrintf("%s at character %zu", - e.what(), - e.positions.empty() ? - expr.size() : e.positions.front().byte_in_line) } + { TfStringPrintf("%s at character %zu", + std::string(e.message()).c_str(), + e.positions().empty() + ? expr.size() : e.positions().front().column-1) } }; }