// SPDX-FileCopyrightText: 2025 ModelCloud.ai
// SPDX-FileCopyrightText: 2025 qubitium@modelcloud.ai
// SPDX-License-Identifier: Apache-2.0
// Contact: qubitium@modelcloud.ai, x.com/qubitium

#include "pcre2_module.h"
#include <ctype.h>
#include <string.h>
#include <stdio.h>

/* Autogenerated from PCRE2 commit c5ad23c8833b99c56a2913f86dbe16a79a1791fe. */
#ifdef PCRE2_ERROR_END_BACKSLASH
#  define HANDLE_PCRE2_ERROR_END_BACKSLASH(X) X(PCRE2_ERROR_END_BACKSLASH)
#else
#  define HANDLE_PCRE2_ERROR_END_BACKSLASH(X)
#endif
#ifdef PCRE2_ERROR_END_BACKSLASH_C
#  define HANDLE_PCRE2_ERROR_END_BACKSLASH_C(X) X(PCRE2_ERROR_END_BACKSLASH_C)
#else
#  define HANDLE_PCRE2_ERROR_END_BACKSLASH_C(X)
#endif
#ifdef PCRE2_ERROR_UNKNOWN_ESCAPE
#  define HANDLE_PCRE2_ERROR_UNKNOWN_ESCAPE(X) X(PCRE2_ERROR_UNKNOWN_ESCAPE)
#else
#  define HANDLE_PCRE2_ERROR_UNKNOWN_ESCAPE(X)
#endif
#ifdef PCRE2_ERROR_QUANTIFIER_OUT_OF_ORDER
#  define HANDLE_PCRE2_ERROR_QUANTIFIER_OUT_OF_ORDER(X) X(PCRE2_ERROR_QUANTIFIER_OUT_OF_ORDER)
#else
#  define HANDLE_PCRE2_ERROR_QUANTIFIER_OUT_OF_ORDER(X)
#endif
#ifdef PCRE2_ERROR_QUANTIFIER_TOO_BIG
#  define HANDLE_PCRE2_ERROR_QUANTIFIER_TOO_BIG(X) X(PCRE2_ERROR_QUANTIFIER_TOO_BIG)
#else
#  define HANDLE_PCRE2_ERROR_QUANTIFIER_TOO_BIG(X)
#endif
#ifdef PCRE2_ERROR_MISSING_SQUARE_BRACKET
#  define HANDLE_PCRE2_ERROR_MISSING_SQUARE_BRACKET(X) X(PCRE2_ERROR_MISSING_SQUARE_BRACKET)
#else
#  define HANDLE_PCRE2_ERROR_MISSING_SQUARE_BRACKET(X)
#endif
#ifdef PCRE2_ERROR_ESCAPE_INVALID_IN_CLASS
#  define HANDLE_PCRE2_ERROR_ESCAPE_INVALID_IN_CLASS(X) X(PCRE2_ERROR_ESCAPE_INVALID_IN_CLASS)
#else
#  define HANDLE_PCRE2_ERROR_ESCAPE_INVALID_IN_CLASS(X)
#endif
#ifdef PCRE2_ERROR_CLASS_RANGE_ORDER
#  define HANDLE_PCRE2_ERROR_CLASS_RANGE_ORDER(X) X(PCRE2_ERROR_CLASS_RANGE_ORDER)
#else
#  define HANDLE_PCRE2_ERROR_CLASS_RANGE_ORDER(X)
#endif
#ifdef PCRE2_ERROR_QUANTIFIER_INVALID
#  define HANDLE_PCRE2_ERROR_QUANTIFIER_INVALID(X) X(PCRE2_ERROR_QUANTIFIER_INVALID)
#else
#  define HANDLE_PCRE2_ERROR_QUANTIFIER_INVALID(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_UNEXPECTED_REPEAT
#  define HANDLE_PCRE2_ERROR_INTERNAL_UNEXPECTED_REPEAT(X) X(PCRE2_ERROR_INTERNAL_UNEXPECTED_REPEAT)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_UNEXPECTED_REPEAT(X)
#endif
#ifdef PCRE2_ERROR_INVALID_AFTER_PARENS_QUERY
#  define HANDLE_PCRE2_ERROR_INVALID_AFTER_PARENS_QUERY(X) X(PCRE2_ERROR_INVALID_AFTER_PARENS_QUERY)
#else
#  define HANDLE_PCRE2_ERROR_INVALID_AFTER_PARENS_QUERY(X)
#endif
#ifdef PCRE2_ERROR_POSIX_CLASS_NOT_IN_CLASS
#  define HANDLE_PCRE2_ERROR_POSIX_CLASS_NOT_IN_CLASS(X) X(PCRE2_ERROR_POSIX_CLASS_NOT_IN_CLASS)
#else
#  define HANDLE_PCRE2_ERROR_POSIX_CLASS_NOT_IN_CLASS(X)
#endif
#ifdef PCRE2_ERROR_POSIX_NO_SUPPORT_COLLATING
#  define HANDLE_PCRE2_ERROR_POSIX_NO_SUPPORT_COLLATING(X) X(PCRE2_ERROR_POSIX_NO_SUPPORT_COLLATING)
#else
#  define HANDLE_PCRE2_ERROR_POSIX_NO_SUPPORT_COLLATING(X)
#endif
#ifdef PCRE2_ERROR_MISSING_CLOSING_PARENTHESIS
#  define HANDLE_PCRE2_ERROR_MISSING_CLOSING_PARENTHESIS(X) X(PCRE2_ERROR_MISSING_CLOSING_PARENTHESIS)
#else
#  define HANDLE_PCRE2_ERROR_MISSING_CLOSING_PARENTHESIS(X)
#endif
#ifdef PCRE2_ERROR_BAD_SUBPATTERN_REFERENCE
#  define HANDLE_PCRE2_ERROR_BAD_SUBPATTERN_REFERENCE(X) X(PCRE2_ERROR_BAD_SUBPATTERN_REFERENCE)
#else
#  define HANDLE_PCRE2_ERROR_BAD_SUBPATTERN_REFERENCE(X)
#endif
#ifdef PCRE2_ERROR_NULL_PATTERN
#  define HANDLE_PCRE2_ERROR_NULL_PATTERN(X) X(PCRE2_ERROR_NULL_PATTERN)
#else
#  define HANDLE_PCRE2_ERROR_NULL_PATTERN(X)
#endif
#ifdef PCRE2_ERROR_BAD_OPTIONS
#  define HANDLE_PCRE2_ERROR_BAD_OPTIONS(X) X(PCRE2_ERROR_BAD_OPTIONS)
#else
#  define HANDLE_PCRE2_ERROR_BAD_OPTIONS(X)
#endif
#ifdef PCRE2_ERROR_MISSING_COMMENT_CLOSING
#  define HANDLE_PCRE2_ERROR_MISSING_COMMENT_CLOSING(X) X(PCRE2_ERROR_MISSING_COMMENT_CLOSING)
#else
#  define HANDLE_PCRE2_ERROR_MISSING_COMMENT_CLOSING(X)
#endif
#ifdef PCRE2_ERROR_PARENTHESES_NEST_TOO_DEEP
#  define HANDLE_PCRE2_ERROR_PARENTHESES_NEST_TOO_DEEP(X) X(PCRE2_ERROR_PARENTHESES_NEST_TOO_DEEP)
#else
#  define HANDLE_PCRE2_ERROR_PARENTHESES_NEST_TOO_DEEP(X)
#endif
#ifdef PCRE2_ERROR_PATTERN_TOO_LARGE
#  define HANDLE_PCRE2_ERROR_PATTERN_TOO_LARGE(X) X(PCRE2_ERROR_PATTERN_TOO_LARGE)
#else
#  define HANDLE_PCRE2_ERROR_PATTERN_TOO_LARGE(X)
#endif
#ifdef PCRE2_ERROR_HEAP_FAILED
#  define HANDLE_PCRE2_ERROR_HEAP_FAILED(X) X(PCRE2_ERROR_HEAP_FAILED)
#else
#  define HANDLE_PCRE2_ERROR_HEAP_FAILED(X)
#endif
#ifdef PCRE2_ERROR_UNMATCHED_CLOSING_PARENTHESIS
#  define HANDLE_PCRE2_ERROR_UNMATCHED_CLOSING_PARENTHESIS(X) X(PCRE2_ERROR_UNMATCHED_CLOSING_PARENTHESIS)
#else
#  define HANDLE_PCRE2_ERROR_UNMATCHED_CLOSING_PARENTHESIS(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_CODE_OVERFLOW
#  define HANDLE_PCRE2_ERROR_INTERNAL_CODE_OVERFLOW(X) X(PCRE2_ERROR_INTERNAL_CODE_OVERFLOW)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_CODE_OVERFLOW(X)
#endif
#ifdef PCRE2_ERROR_MISSING_CONDITION_CLOSING
#  define HANDLE_PCRE2_ERROR_MISSING_CONDITION_CLOSING(X) X(PCRE2_ERROR_MISSING_CONDITION_CLOSING)
#else
#  define HANDLE_PCRE2_ERROR_MISSING_CONDITION_CLOSING(X)
#endif
#ifdef PCRE2_ERROR_LOOKBEHIND_NOT_FIXED_LENGTH
#  define HANDLE_PCRE2_ERROR_LOOKBEHIND_NOT_FIXED_LENGTH(X) X(PCRE2_ERROR_LOOKBEHIND_NOT_FIXED_LENGTH)
#else
#  define HANDLE_PCRE2_ERROR_LOOKBEHIND_NOT_FIXED_LENGTH(X)
#endif
#ifdef PCRE2_ERROR_ZERO_RELATIVE_REFERENCE
#  define HANDLE_PCRE2_ERROR_ZERO_RELATIVE_REFERENCE(X) X(PCRE2_ERROR_ZERO_RELATIVE_REFERENCE)
#else
#  define HANDLE_PCRE2_ERROR_ZERO_RELATIVE_REFERENCE(X)
#endif
#ifdef PCRE2_ERROR_TOO_MANY_CONDITION_BRANCHES
#  define HANDLE_PCRE2_ERROR_TOO_MANY_CONDITION_BRANCHES(X) X(PCRE2_ERROR_TOO_MANY_CONDITION_BRANCHES)
#else
#  define HANDLE_PCRE2_ERROR_TOO_MANY_CONDITION_BRANCHES(X)
#endif
#ifdef PCRE2_ERROR_CONDITION_ASSERTION_EXPECTED
#  define HANDLE_PCRE2_ERROR_CONDITION_ASSERTION_EXPECTED(X) X(PCRE2_ERROR_CONDITION_ASSERTION_EXPECTED)
#else
#  define HANDLE_PCRE2_ERROR_CONDITION_ASSERTION_EXPECTED(X)
#endif
#ifdef PCRE2_ERROR_BAD_RELATIVE_REFERENCE
#  define HANDLE_PCRE2_ERROR_BAD_RELATIVE_REFERENCE(X) X(PCRE2_ERROR_BAD_RELATIVE_REFERENCE)
#else
#  define HANDLE_PCRE2_ERROR_BAD_RELATIVE_REFERENCE(X)
#endif
#ifdef PCRE2_ERROR_UNKNOWN_POSIX_CLASS
#  define HANDLE_PCRE2_ERROR_UNKNOWN_POSIX_CLASS(X) X(PCRE2_ERROR_UNKNOWN_POSIX_CLASS)
#else
#  define HANDLE_PCRE2_ERROR_UNKNOWN_POSIX_CLASS(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_STUDY_ERROR
#  define HANDLE_PCRE2_ERROR_INTERNAL_STUDY_ERROR(X) X(PCRE2_ERROR_INTERNAL_STUDY_ERROR)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_STUDY_ERROR(X)
#endif
#ifdef PCRE2_ERROR_UNICODE_NOT_SUPPORTED
#  define HANDLE_PCRE2_ERROR_UNICODE_NOT_SUPPORTED(X) X(PCRE2_ERROR_UNICODE_NOT_SUPPORTED)
#else
#  define HANDLE_PCRE2_ERROR_UNICODE_NOT_SUPPORTED(X)
#endif
#ifdef PCRE2_ERROR_PARENTHESES_STACK_CHECK
#  define HANDLE_PCRE2_ERROR_PARENTHESES_STACK_CHECK(X) X(PCRE2_ERROR_PARENTHESES_STACK_CHECK)
#else
#  define HANDLE_PCRE2_ERROR_PARENTHESES_STACK_CHECK(X)
#endif
#ifdef PCRE2_ERROR_CODE_POINT_TOO_BIG
#  define HANDLE_PCRE2_ERROR_CODE_POINT_TOO_BIG(X) X(PCRE2_ERROR_CODE_POINT_TOO_BIG)
#else
#  define HANDLE_PCRE2_ERROR_CODE_POINT_TOO_BIG(X)
#endif
#ifdef PCRE2_ERROR_LOOKBEHIND_TOO_COMPLICATED
#  define HANDLE_PCRE2_ERROR_LOOKBEHIND_TOO_COMPLICATED(X) X(PCRE2_ERROR_LOOKBEHIND_TOO_COMPLICATED)
#else
#  define HANDLE_PCRE2_ERROR_LOOKBEHIND_TOO_COMPLICATED(X)
#endif
#ifdef PCRE2_ERROR_LOOKBEHIND_INVALID_BACKSLASH_C
#  define HANDLE_PCRE2_ERROR_LOOKBEHIND_INVALID_BACKSLASH_C(X) X(PCRE2_ERROR_LOOKBEHIND_INVALID_BACKSLASH_C)
#else
#  define HANDLE_PCRE2_ERROR_LOOKBEHIND_INVALID_BACKSLASH_C(X)
#endif
#ifdef PCRE2_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE
#  define HANDLE_PCRE2_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE(X) X(PCRE2_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE)
#else
#  define HANDLE_PCRE2_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE(X)
#endif
#ifdef PCRE2_ERROR_CALLOUT_NUMBER_TOO_BIG
#  define HANDLE_PCRE2_ERROR_CALLOUT_NUMBER_TOO_BIG(X) X(PCRE2_ERROR_CALLOUT_NUMBER_TOO_BIG)
#else
#  define HANDLE_PCRE2_ERROR_CALLOUT_NUMBER_TOO_BIG(X)
#endif
#ifdef PCRE2_ERROR_MISSING_CALLOUT_CLOSING
#  define HANDLE_PCRE2_ERROR_MISSING_CALLOUT_CLOSING(X) X(PCRE2_ERROR_MISSING_CALLOUT_CLOSING)
#else
#  define HANDLE_PCRE2_ERROR_MISSING_CALLOUT_CLOSING(X)
#endif
#ifdef PCRE2_ERROR_ESCAPE_INVALID_IN_VERB
#  define HANDLE_PCRE2_ERROR_ESCAPE_INVALID_IN_VERB(X) X(PCRE2_ERROR_ESCAPE_INVALID_IN_VERB)
#else
#  define HANDLE_PCRE2_ERROR_ESCAPE_INVALID_IN_VERB(X)
#endif
#ifdef PCRE2_ERROR_UNRECOGNIZED_AFTER_QUERY_P
#  define HANDLE_PCRE2_ERROR_UNRECOGNIZED_AFTER_QUERY_P(X) X(PCRE2_ERROR_UNRECOGNIZED_AFTER_QUERY_P)
#else
#  define HANDLE_PCRE2_ERROR_UNRECOGNIZED_AFTER_QUERY_P(X)
#endif
#ifdef PCRE2_ERROR_MISSING_NAME_TERMINATOR
#  define HANDLE_PCRE2_ERROR_MISSING_NAME_TERMINATOR(X) X(PCRE2_ERROR_MISSING_NAME_TERMINATOR)
#else
#  define HANDLE_PCRE2_ERROR_MISSING_NAME_TERMINATOR(X)
#endif
#ifdef PCRE2_ERROR_DUPLICATE_SUBPATTERN_NAME
#  define HANDLE_PCRE2_ERROR_DUPLICATE_SUBPATTERN_NAME(X) X(PCRE2_ERROR_DUPLICATE_SUBPATTERN_NAME)
#else
#  define HANDLE_PCRE2_ERROR_DUPLICATE_SUBPATTERN_NAME(X)
#endif
#ifdef PCRE2_ERROR_INVALID_SUBPATTERN_NAME
#  define HANDLE_PCRE2_ERROR_INVALID_SUBPATTERN_NAME(X) X(PCRE2_ERROR_INVALID_SUBPATTERN_NAME)
#else
#  define HANDLE_PCRE2_ERROR_INVALID_SUBPATTERN_NAME(X)
#endif
#ifdef PCRE2_ERROR_UNICODE_PROPERTIES_UNAVAILABLE
#  define HANDLE_PCRE2_ERROR_UNICODE_PROPERTIES_UNAVAILABLE(X) X(PCRE2_ERROR_UNICODE_PROPERTIES_UNAVAILABLE)
#else
#  define HANDLE_PCRE2_ERROR_UNICODE_PROPERTIES_UNAVAILABLE(X)
#endif
#ifdef PCRE2_ERROR_MALFORMED_UNICODE_PROPERTY
#  define HANDLE_PCRE2_ERROR_MALFORMED_UNICODE_PROPERTY(X) X(PCRE2_ERROR_MALFORMED_UNICODE_PROPERTY)
#else
#  define HANDLE_PCRE2_ERROR_MALFORMED_UNICODE_PROPERTY(X)
#endif
#ifdef PCRE2_ERROR_UNKNOWN_UNICODE_PROPERTY
#  define HANDLE_PCRE2_ERROR_UNKNOWN_UNICODE_PROPERTY(X) X(PCRE2_ERROR_UNKNOWN_UNICODE_PROPERTY)
#else
#  define HANDLE_PCRE2_ERROR_UNKNOWN_UNICODE_PROPERTY(X)
#endif
#ifdef PCRE2_ERROR_SUBPATTERN_NAME_TOO_LONG
#  define HANDLE_PCRE2_ERROR_SUBPATTERN_NAME_TOO_LONG(X) X(PCRE2_ERROR_SUBPATTERN_NAME_TOO_LONG)
#else
#  define HANDLE_PCRE2_ERROR_SUBPATTERN_NAME_TOO_LONG(X)
#endif
#ifdef PCRE2_ERROR_TOO_MANY_NAMED_SUBPATTERNS
#  define HANDLE_PCRE2_ERROR_TOO_MANY_NAMED_SUBPATTERNS(X) X(PCRE2_ERROR_TOO_MANY_NAMED_SUBPATTERNS)
#else
#  define HANDLE_PCRE2_ERROR_TOO_MANY_NAMED_SUBPATTERNS(X)
#endif
#ifdef PCRE2_ERROR_CLASS_INVALID_RANGE
#  define HANDLE_PCRE2_ERROR_CLASS_INVALID_RANGE(X) X(PCRE2_ERROR_CLASS_INVALID_RANGE)
#else
#  define HANDLE_PCRE2_ERROR_CLASS_INVALID_RANGE(X)
#endif
#ifdef PCRE2_ERROR_OCTAL_BYTE_TOO_BIG
#  define HANDLE_PCRE2_ERROR_OCTAL_BYTE_TOO_BIG(X) X(PCRE2_ERROR_OCTAL_BYTE_TOO_BIG)
#else
#  define HANDLE_PCRE2_ERROR_OCTAL_BYTE_TOO_BIG(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_OVERRAN_WORKSPACE
#  define HANDLE_PCRE2_ERROR_INTERNAL_OVERRAN_WORKSPACE(X) X(PCRE2_ERROR_INTERNAL_OVERRAN_WORKSPACE)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_OVERRAN_WORKSPACE(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_MISSING_SUBPATTERN
#  define HANDLE_PCRE2_ERROR_INTERNAL_MISSING_SUBPATTERN(X) X(PCRE2_ERROR_INTERNAL_MISSING_SUBPATTERN)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_MISSING_SUBPATTERN(X)
#endif
#ifdef PCRE2_ERROR_DEFINE_TOO_MANY_BRANCHES
#  define HANDLE_PCRE2_ERROR_DEFINE_TOO_MANY_BRANCHES(X) X(PCRE2_ERROR_DEFINE_TOO_MANY_BRANCHES)
#else
#  define HANDLE_PCRE2_ERROR_DEFINE_TOO_MANY_BRANCHES(X)
#endif
#ifdef PCRE2_ERROR_BACKSLASH_O_MISSING_BRACE
#  define HANDLE_PCRE2_ERROR_BACKSLASH_O_MISSING_BRACE(X) X(PCRE2_ERROR_BACKSLASH_O_MISSING_BRACE)
#else
#  define HANDLE_PCRE2_ERROR_BACKSLASH_O_MISSING_BRACE(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_UNKNOWN_NEWLINE
#  define HANDLE_PCRE2_ERROR_INTERNAL_UNKNOWN_NEWLINE(X) X(PCRE2_ERROR_INTERNAL_UNKNOWN_NEWLINE)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_UNKNOWN_NEWLINE(X)
#endif
#ifdef PCRE2_ERROR_BACKSLASH_G_SYNTAX
#  define HANDLE_PCRE2_ERROR_BACKSLASH_G_SYNTAX(X) X(PCRE2_ERROR_BACKSLASH_G_SYNTAX)
#else
#  define HANDLE_PCRE2_ERROR_BACKSLASH_G_SYNTAX(X)
#endif
#ifdef PCRE2_ERROR_PARENS_QUERY_R_MISSING_CLOSING
#  define HANDLE_PCRE2_ERROR_PARENS_QUERY_R_MISSING_CLOSING(X) X(PCRE2_ERROR_PARENS_QUERY_R_MISSING_CLOSING)
#else
#  define HANDLE_PCRE2_ERROR_PARENS_QUERY_R_MISSING_CLOSING(X)
#endif
#ifdef PCRE2_ERROR_VERB_ARGUMENT_NOT_ALLOWED
#  define HANDLE_PCRE2_ERROR_VERB_ARGUMENT_NOT_ALLOWED(X) X(PCRE2_ERROR_VERB_ARGUMENT_NOT_ALLOWED)
#else
#  define HANDLE_PCRE2_ERROR_VERB_ARGUMENT_NOT_ALLOWED(X)
#endif
#ifdef PCRE2_ERROR_VERB_UNKNOWN
#  define HANDLE_PCRE2_ERROR_VERB_UNKNOWN(X) X(PCRE2_ERROR_VERB_UNKNOWN)
#else
#  define HANDLE_PCRE2_ERROR_VERB_UNKNOWN(X)
#endif
#ifdef PCRE2_ERROR_SUBPATTERN_NUMBER_TOO_BIG
#  define HANDLE_PCRE2_ERROR_SUBPATTERN_NUMBER_TOO_BIG(X) X(PCRE2_ERROR_SUBPATTERN_NUMBER_TOO_BIG)
#else
#  define HANDLE_PCRE2_ERROR_SUBPATTERN_NUMBER_TOO_BIG(X)
#endif
#ifdef PCRE2_ERROR_SUBPATTERN_NAME_EXPECTED
#  define HANDLE_PCRE2_ERROR_SUBPATTERN_NAME_EXPECTED(X) X(PCRE2_ERROR_SUBPATTERN_NAME_EXPECTED)
#else
#  define HANDLE_PCRE2_ERROR_SUBPATTERN_NAME_EXPECTED(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_PARSED_OVERFLOW
#  define HANDLE_PCRE2_ERROR_INTERNAL_PARSED_OVERFLOW(X) X(PCRE2_ERROR_INTERNAL_PARSED_OVERFLOW)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_PARSED_OVERFLOW(X)
#endif
#ifdef PCRE2_ERROR_INVALID_OCTAL
#  define HANDLE_PCRE2_ERROR_INVALID_OCTAL(X) X(PCRE2_ERROR_INVALID_OCTAL)
#else
#  define HANDLE_PCRE2_ERROR_INVALID_OCTAL(X)
#endif
#ifdef PCRE2_ERROR_SUBPATTERN_NAMES_MISMATCH
#  define HANDLE_PCRE2_ERROR_SUBPATTERN_NAMES_MISMATCH(X) X(PCRE2_ERROR_SUBPATTERN_NAMES_MISMATCH)
#else
#  define HANDLE_PCRE2_ERROR_SUBPATTERN_NAMES_MISMATCH(X)
#endif
#ifdef PCRE2_ERROR_MARK_MISSING_ARGUMENT
#  define HANDLE_PCRE2_ERROR_MARK_MISSING_ARGUMENT(X) X(PCRE2_ERROR_MARK_MISSING_ARGUMENT)
#else
#  define HANDLE_PCRE2_ERROR_MARK_MISSING_ARGUMENT(X)
#endif
#ifdef PCRE2_ERROR_INVALID_HEXADECIMAL
#  define HANDLE_PCRE2_ERROR_INVALID_HEXADECIMAL(X) X(PCRE2_ERROR_INVALID_HEXADECIMAL)
#else
#  define HANDLE_PCRE2_ERROR_INVALID_HEXADECIMAL(X)
#endif
#ifdef PCRE2_ERROR_BACKSLASH_C_SYNTAX
#  define HANDLE_PCRE2_ERROR_BACKSLASH_C_SYNTAX(X) X(PCRE2_ERROR_BACKSLASH_C_SYNTAX)
#else
#  define HANDLE_PCRE2_ERROR_BACKSLASH_C_SYNTAX(X)
#endif
#ifdef PCRE2_ERROR_BACKSLASH_K_SYNTAX
#  define HANDLE_PCRE2_ERROR_BACKSLASH_K_SYNTAX(X) X(PCRE2_ERROR_BACKSLASH_K_SYNTAX)
#else
#  define HANDLE_PCRE2_ERROR_BACKSLASH_K_SYNTAX(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_BAD_CODE_LOOKBEHINDS
#  define HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE_LOOKBEHINDS(X) X(PCRE2_ERROR_INTERNAL_BAD_CODE_LOOKBEHINDS)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE_LOOKBEHINDS(X)
#endif
#ifdef PCRE2_ERROR_BACKSLASH_N_IN_CLASS
#  define HANDLE_PCRE2_ERROR_BACKSLASH_N_IN_CLASS(X) X(PCRE2_ERROR_BACKSLASH_N_IN_CLASS)
#else
#  define HANDLE_PCRE2_ERROR_BACKSLASH_N_IN_CLASS(X)
#endif
#ifdef PCRE2_ERROR_CALLOUT_STRING_TOO_LONG
#  define HANDLE_PCRE2_ERROR_CALLOUT_STRING_TOO_LONG(X) X(PCRE2_ERROR_CALLOUT_STRING_TOO_LONG)
#else
#  define HANDLE_PCRE2_ERROR_CALLOUT_STRING_TOO_LONG(X)
#endif
#ifdef PCRE2_ERROR_UNICODE_DISALLOWED_CODE_POINT
#  define HANDLE_PCRE2_ERROR_UNICODE_DISALLOWED_CODE_POINT(X) X(PCRE2_ERROR_UNICODE_DISALLOWED_CODE_POINT)
#else
#  define HANDLE_PCRE2_ERROR_UNICODE_DISALLOWED_CODE_POINT(X)
#endif
#ifdef PCRE2_ERROR_UTF_IS_DISABLED
#  define HANDLE_PCRE2_ERROR_UTF_IS_DISABLED(X) X(PCRE2_ERROR_UTF_IS_DISABLED)
#else
#  define HANDLE_PCRE2_ERROR_UTF_IS_DISABLED(X)
#endif
#ifdef PCRE2_ERROR_UCP_IS_DISABLED
#  define HANDLE_PCRE2_ERROR_UCP_IS_DISABLED(X) X(PCRE2_ERROR_UCP_IS_DISABLED)
#else
#  define HANDLE_PCRE2_ERROR_UCP_IS_DISABLED(X)
#endif
#ifdef PCRE2_ERROR_VERB_NAME_TOO_LONG
#  define HANDLE_PCRE2_ERROR_VERB_NAME_TOO_LONG(X) X(PCRE2_ERROR_VERB_NAME_TOO_LONG)
#else
#  define HANDLE_PCRE2_ERROR_VERB_NAME_TOO_LONG(X)
#endif
#ifdef PCRE2_ERROR_BACKSLASH_U_CODE_POINT_TOO_BIG
#  define HANDLE_PCRE2_ERROR_BACKSLASH_U_CODE_POINT_TOO_BIG(X) X(PCRE2_ERROR_BACKSLASH_U_CODE_POINT_TOO_BIG)
#else
#  define HANDLE_PCRE2_ERROR_BACKSLASH_U_CODE_POINT_TOO_BIG(X)
#endif
#ifdef PCRE2_ERROR_MISSING_OCTAL_OR_HEX_DIGITS
#  define HANDLE_PCRE2_ERROR_MISSING_OCTAL_OR_HEX_DIGITS(X) X(PCRE2_ERROR_MISSING_OCTAL_OR_HEX_DIGITS)
#else
#  define HANDLE_PCRE2_ERROR_MISSING_OCTAL_OR_HEX_DIGITS(X)
#endif
#ifdef PCRE2_ERROR_VERSION_CONDITION_SYNTAX
#  define HANDLE_PCRE2_ERROR_VERSION_CONDITION_SYNTAX(X) X(PCRE2_ERROR_VERSION_CONDITION_SYNTAX)
#else
#  define HANDLE_PCRE2_ERROR_VERSION_CONDITION_SYNTAX(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_BAD_CODE_AUTO_POSSESS
#  define HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE_AUTO_POSSESS(X) X(PCRE2_ERROR_INTERNAL_BAD_CODE_AUTO_POSSESS)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE_AUTO_POSSESS(X)
#endif
#ifdef PCRE2_ERROR_CALLOUT_NO_STRING_DELIMITER
#  define HANDLE_PCRE2_ERROR_CALLOUT_NO_STRING_DELIMITER(X) X(PCRE2_ERROR_CALLOUT_NO_STRING_DELIMITER)
#else
#  define HANDLE_PCRE2_ERROR_CALLOUT_NO_STRING_DELIMITER(X)
#endif
#ifdef PCRE2_ERROR_CALLOUT_BAD_STRING_DELIMITER
#  define HANDLE_PCRE2_ERROR_CALLOUT_BAD_STRING_DELIMITER(X) X(PCRE2_ERROR_CALLOUT_BAD_STRING_DELIMITER)
#else
#  define HANDLE_PCRE2_ERROR_CALLOUT_BAD_STRING_DELIMITER(X)
#endif
#ifdef PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED
#  define HANDLE_PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED(X) X(PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED)
#else
#  define HANDLE_PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED(X)
#endif
#ifdef PCRE2_ERROR_QUERY_BARJX_NEST_TOO_DEEP
#  define HANDLE_PCRE2_ERROR_QUERY_BARJX_NEST_TOO_DEEP(X) X(PCRE2_ERROR_QUERY_BARJX_NEST_TOO_DEEP)
#else
#  define HANDLE_PCRE2_ERROR_QUERY_BARJX_NEST_TOO_DEEP(X)
#endif
#ifdef PCRE2_ERROR_BACKSLASH_C_LIBRARY_DISABLED
#  define HANDLE_PCRE2_ERROR_BACKSLASH_C_LIBRARY_DISABLED(X) X(PCRE2_ERROR_BACKSLASH_C_LIBRARY_DISABLED)
#else
#  define HANDLE_PCRE2_ERROR_BACKSLASH_C_LIBRARY_DISABLED(X)
#endif
#ifdef PCRE2_ERROR_PATTERN_TOO_COMPLICATED
#  define HANDLE_PCRE2_ERROR_PATTERN_TOO_COMPLICATED(X) X(PCRE2_ERROR_PATTERN_TOO_COMPLICATED)
#else
#  define HANDLE_PCRE2_ERROR_PATTERN_TOO_COMPLICATED(X)
#endif
#ifdef PCRE2_ERROR_LOOKBEHIND_TOO_LONG
#  define HANDLE_PCRE2_ERROR_LOOKBEHIND_TOO_LONG(X) X(PCRE2_ERROR_LOOKBEHIND_TOO_LONG)
#else
#  define HANDLE_PCRE2_ERROR_LOOKBEHIND_TOO_LONG(X)
#endif
#ifdef PCRE2_ERROR_PATTERN_STRING_TOO_LONG
#  define HANDLE_PCRE2_ERROR_PATTERN_STRING_TOO_LONG(X) X(PCRE2_ERROR_PATTERN_STRING_TOO_LONG)
#else
#  define HANDLE_PCRE2_ERROR_PATTERN_STRING_TOO_LONG(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_BAD_CODE
#  define HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE(X) X(PCRE2_ERROR_INTERNAL_BAD_CODE)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_BAD_CODE_IN_SKIP
#  define HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE_IN_SKIP(X) X(PCRE2_ERROR_INTERNAL_BAD_CODE_IN_SKIP)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE_IN_SKIP(X)
#endif
#ifdef PCRE2_ERROR_NO_SURROGATES_IN_UTF16
#  define HANDLE_PCRE2_ERROR_NO_SURROGATES_IN_UTF16(X) X(PCRE2_ERROR_NO_SURROGATES_IN_UTF16)
#else
#  define HANDLE_PCRE2_ERROR_NO_SURROGATES_IN_UTF16(X)
#endif
#ifdef PCRE2_ERROR_BAD_LITERAL_OPTIONS
#  define HANDLE_PCRE2_ERROR_BAD_LITERAL_OPTIONS(X) X(PCRE2_ERROR_BAD_LITERAL_OPTIONS)
#else
#  define HANDLE_PCRE2_ERROR_BAD_LITERAL_OPTIONS(X)
#endif
#ifdef PCRE2_ERROR_SUPPORTED_ONLY_IN_UNICODE
#  define HANDLE_PCRE2_ERROR_SUPPORTED_ONLY_IN_UNICODE(X) X(PCRE2_ERROR_SUPPORTED_ONLY_IN_UNICODE)
#else
#  define HANDLE_PCRE2_ERROR_SUPPORTED_ONLY_IN_UNICODE(X)
#endif
#ifdef PCRE2_ERROR_INVALID_HYPHEN_IN_OPTIONS
#  define HANDLE_PCRE2_ERROR_INVALID_HYPHEN_IN_OPTIONS(X) X(PCRE2_ERROR_INVALID_HYPHEN_IN_OPTIONS)
#else
#  define HANDLE_PCRE2_ERROR_INVALID_HYPHEN_IN_OPTIONS(X)
#endif
#ifdef PCRE2_ERROR_ALPHA_ASSERTION_UNKNOWN
#  define HANDLE_PCRE2_ERROR_ALPHA_ASSERTION_UNKNOWN(X) X(PCRE2_ERROR_ALPHA_ASSERTION_UNKNOWN)
#else
#  define HANDLE_PCRE2_ERROR_ALPHA_ASSERTION_UNKNOWN(X)
#endif
#ifdef PCRE2_ERROR_SCRIPT_RUN_NOT_AVAILABLE
#  define HANDLE_PCRE2_ERROR_SCRIPT_RUN_NOT_AVAILABLE(X) X(PCRE2_ERROR_SCRIPT_RUN_NOT_AVAILABLE)
#else
#  define HANDLE_PCRE2_ERROR_SCRIPT_RUN_NOT_AVAILABLE(X)
#endif
#ifdef PCRE2_ERROR_TOO_MANY_CAPTURES
#  define HANDLE_PCRE2_ERROR_TOO_MANY_CAPTURES(X) X(PCRE2_ERROR_TOO_MANY_CAPTURES)
#else
#  define HANDLE_PCRE2_ERROR_TOO_MANY_CAPTURES(X)
#endif
#ifdef PCRE2_ERROR_MISSING_OCTAL_DIGIT
#  define HANDLE_PCRE2_ERROR_MISSING_OCTAL_DIGIT(X) X(PCRE2_ERROR_MISSING_OCTAL_DIGIT)
#else
#  define HANDLE_PCRE2_ERROR_MISSING_OCTAL_DIGIT(X)
#endif
#ifdef PCRE2_ERROR_BACKSLASH_K_IN_LOOKAROUND
#  define HANDLE_PCRE2_ERROR_BACKSLASH_K_IN_LOOKAROUND(X) X(PCRE2_ERROR_BACKSLASH_K_IN_LOOKAROUND)
#else
#  define HANDLE_PCRE2_ERROR_BACKSLASH_K_IN_LOOKAROUND(X)
#endif
#ifdef PCRE2_ERROR_MAX_VAR_LOOKBEHIND_EXCEEDED
#  define HANDLE_PCRE2_ERROR_MAX_VAR_LOOKBEHIND_EXCEEDED(X) X(PCRE2_ERROR_MAX_VAR_LOOKBEHIND_EXCEEDED)
#else
#  define HANDLE_PCRE2_ERROR_MAX_VAR_LOOKBEHIND_EXCEEDED(X)
#endif
#ifdef PCRE2_ERROR_PATTERN_COMPILED_SIZE_TOO_BIG
#  define HANDLE_PCRE2_ERROR_PATTERN_COMPILED_SIZE_TOO_BIG(X) X(PCRE2_ERROR_PATTERN_COMPILED_SIZE_TOO_BIG)
#else
#  define HANDLE_PCRE2_ERROR_PATTERN_COMPILED_SIZE_TOO_BIG(X)
#endif
#ifdef PCRE2_ERROR_OVERSIZE_PYTHON_OCTAL
#  define HANDLE_PCRE2_ERROR_OVERSIZE_PYTHON_OCTAL(X) X(PCRE2_ERROR_OVERSIZE_PYTHON_OCTAL)
#else
#  define HANDLE_PCRE2_ERROR_OVERSIZE_PYTHON_OCTAL(X)
#endif
#ifdef PCRE2_ERROR_CALLOUT_CALLER_DISABLED
#  define HANDLE_PCRE2_ERROR_CALLOUT_CALLER_DISABLED(X) X(PCRE2_ERROR_CALLOUT_CALLER_DISABLED)
#else
#  define HANDLE_PCRE2_ERROR_CALLOUT_CALLER_DISABLED(X)
#endif
#ifdef PCRE2_ERROR_EXTRA_CASING_REQUIRES_UNICODE
#  define HANDLE_PCRE2_ERROR_EXTRA_CASING_REQUIRES_UNICODE(X) X(PCRE2_ERROR_EXTRA_CASING_REQUIRES_UNICODE)
#else
#  define HANDLE_PCRE2_ERROR_EXTRA_CASING_REQUIRES_UNICODE(X)
#endif
#ifdef PCRE2_ERROR_TURKISH_CASING_REQUIRES_UTF
#  define HANDLE_PCRE2_ERROR_TURKISH_CASING_REQUIRES_UTF(X) X(PCRE2_ERROR_TURKISH_CASING_REQUIRES_UTF)
#else
#  define HANDLE_PCRE2_ERROR_TURKISH_CASING_REQUIRES_UTF(X)
#endif
#ifdef PCRE2_ERROR_EXTRA_CASING_INCOMPATIBLE
#  define HANDLE_PCRE2_ERROR_EXTRA_CASING_INCOMPATIBLE(X) X(PCRE2_ERROR_EXTRA_CASING_INCOMPATIBLE)
#else
#  define HANDLE_PCRE2_ERROR_EXTRA_CASING_INCOMPATIBLE(X)
#endif
#ifdef PCRE2_ERROR_ECLASS_NEST_TOO_DEEP
#  define HANDLE_PCRE2_ERROR_ECLASS_NEST_TOO_DEEP(X) X(PCRE2_ERROR_ECLASS_NEST_TOO_DEEP)
#else
#  define HANDLE_PCRE2_ERROR_ECLASS_NEST_TOO_DEEP(X)
#endif
#ifdef PCRE2_ERROR_ECLASS_INVALID_OPERATOR
#  define HANDLE_PCRE2_ERROR_ECLASS_INVALID_OPERATOR(X) X(PCRE2_ERROR_ECLASS_INVALID_OPERATOR)
#else
#  define HANDLE_PCRE2_ERROR_ECLASS_INVALID_OPERATOR(X)
#endif
#ifdef PCRE2_ERROR_ECLASS_UNEXPECTED_OPERATOR
#  define HANDLE_PCRE2_ERROR_ECLASS_UNEXPECTED_OPERATOR(X) X(PCRE2_ERROR_ECLASS_UNEXPECTED_OPERATOR)
#else
#  define HANDLE_PCRE2_ERROR_ECLASS_UNEXPECTED_OPERATOR(X)
#endif
#ifdef PCRE2_ERROR_ECLASS_EXPECTED_OPERAND
#  define HANDLE_PCRE2_ERROR_ECLASS_EXPECTED_OPERAND(X) X(PCRE2_ERROR_ECLASS_EXPECTED_OPERAND)
#else
#  define HANDLE_PCRE2_ERROR_ECLASS_EXPECTED_OPERAND(X)
#endif
#ifdef PCRE2_ERROR_ECLASS_MIXED_OPERATORS
#  define HANDLE_PCRE2_ERROR_ECLASS_MIXED_OPERATORS(X) X(PCRE2_ERROR_ECLASS_MIXED_OPERATORS)
#else
#  define HANDLE_PCRE2_ERROR_ECLASS_MIXED_OPERATORS(X)
#endif
#ifdef PCRE2_ERROR_ECLASS_HINT_SQUARE_BRACKET
#  define HANDLE_PCRE2_ERROR_ECLASS_HINT_SQUARE_BRACKET(X) X(PCRE2_ERROR_ECLASS_HINT_SQUARE_BRACKET)
#else
#  define HANDLE_PCRE2_ERROR_ECLASS_HINT_SQUARE_BRACKET(X)
#endif
#ifdef PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_EXPR
#  define HANDLE_PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_EXPR(X) X(PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_EXPR)
#else
#  define HANDLE_PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_EXPR(X)
#endif
#ifdef PCRE2_ERROR_PERL_ECLASS_EMPTY_EXPR
#  define HANDLE_PCRE2_ERROR_PERL_ECLASS_EMPTY_EXPR(X) X(PCRE2_ERROR_PERL_ECLASS_EMPTY_EXPR)
#else
#  define HANDLE_PCRE2_ERROR_PERL_ECLASS_EMPTY_EXPR(X)
#endif
#ifdef PCRE2_ERROR_PERL_ECLASS_MISSING_CLOSE
#  define HANDLE_PCRE2_ERROR_PERL_ECLASS_MISSING_CLOSE(X) X(PCRE2_ERROR_PERL_ECLASS_MISSING_CLOSE)
#else
#  define HANDLE_PCRE2_ERROR_PERL_ECLASS_MISSING_CLOSE(X)
#endif
#ifdef PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_CHAR
#  define HANDLE_PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_CHAR(X) X(PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_CHAR)
#else
#  define HANDLE_PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_CHAR(X)
#endif
#ifdef PCRE2_ERROR_EXPECTED_CAPTURE_GROUP
#  define HANDLE_PCRE2_ERROR_EXPECTED_CAPTURE_GROUP(X) X(PCRE2_ERROR_EXPECTED_CAPTURE_GROUP)
#else
#  define HANDLE_PCRE2_ERROR_EXPECTED_CAPTURE_GROUP(X)
#endif
#ifdef PCRE2_ERROR_MISSING_OPENING_PARENTHESIS
#  define HANDLE_PCRE2_ERROR_MISSING_OPENING_PARENTHESIS(X) X(PCRE2_ERROR_MISSING_OPENING_PARENTHESIS)
#else
#  define HANDLE_PCRE2_ERROR_MISSING_OPENING_PARENTHESIS(X)
#endif
#ifdef PCRE2_ERROR_MISSING_NUMBER_TERMINATOR
#  define HANDLE_PCRE2_ERROR_MISSING_NUMBER_TERMINATOR(X) X(PCRE2_ERROR_MISSING_NUMBER_TERMINATOR)
#else
#  define HANDLE_PCRE2_ERROR_MISSING_NUMBER_TERMINATOR(X)
#endif
#ifdef PCRE2_ERROR_NULL_ERROROFFSET
#  define HANDLE_PCRE2_ERROR_NULL_ERROROFFSET(X) X(PCRE2_ERROR_NULL_ERROROFFSET)
#else
#  define HANDLE_PCRE2_ERROR_NULL_ERROROFFSET(X)
#endif
#ifdef PCRE2_ERROR_NOMATCH
#  define HANDLE_PCRE2_ERROR_NOMATCH(X) X(PCRE2_ERROR_NOMATCH)
#else
#  define HANDLE_PCRE2_ERROR_NOMATCH(X)
#endif
#ifdef PCRE2_ERROR_PARTIAL
#  define HANDLE_PCRE2_ERROR_PARTIAL(X) X(PCRE2_ERROR_PARTIAL)
#else
#  define HANDLE_PCRE2_ERROR_PARTIAL(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR1
#  define HANDLE_PCRE2_ERROR_UTF8_ERR1(X) X(PCRE2_ERROR_UTF8_ERR1)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR1(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR2
#  define HANDLE_PCRE2_ERROR_UTF8_ERR2(X) X(PCRE2_ERROR_UTF8_ERR2)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR2(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR3
#  define HANDLE_PCRE2_ERROR_UTF8_ERR3(X) X(PCRE2_ERROR_UTF8_ERR3)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR3(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR4
#  define HANDLE_PCRE2_ERROR_UTF8_ERR4(X) X(PCRE2_ERROR_UTF8_ERR4)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR4(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR5
#  define HANDLE_PCRE2_ERROR_UTF8_ERR5(X) X(PCRE2_ERROR_UTF8_ERR5)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR5(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR6
#  define HANDLE_PCRE2_ERROR_UTF8_ERR6(X) X(PCRE2_ERROR_UTF8_ERR6)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR6(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR7
#  define HANDLE_PCRE2_ERROR_UTF8_ERR7(X) X(PCRE2_ERROR_UTF8_ERR7)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR7(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR8
#  define HANDLE_PCRE2_ERROR_UTF8_ERR8(X) X(PCRE2_ERROR_UTF8_ERR8)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR8(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR9
#  define HANDLE_PCRE2_ERROR_UTF8_ERR9(X) X(PCRE2_ERROR_UTF8_ERR9)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR9(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR10
#  define HANDLE_PCRE2_ERROR_UTF8_ERR10(X) X(PCRE2_ERROR_UTF8_ERR10)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR10(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR11
#  define HANDLE_PCRE2_ERROR_UTF8_ERR11(X) X(PCRE2_ERROR_UTF8_ERR11)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR11(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR12
#  define HANDLE_PCRE2_ERROR_UTF8_ERR12(X) X(PCRE2_ERROR_UTF8_ERR12)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR12(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR13
#  define HANDLE_PCRE2_ERROR_UTF8_ERR13(X) X(PCRE2_ERROR_UTF8_ERR13)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR13(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR14
#  define HANDLE_PCRE2_ERROR_UTF8_ERR14(X) X(PCRE2_ERROR_UTF8_ERR14)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR14(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR15
#  define HANDLE_PCRE2_ERROR_UTF8_ERR15(X) X(PCRE2_ERROR_UTF8_ERR15)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR15(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR16
#  define HANDLE_PCRE2_ERROR_UTF8_ERR16(X) X(PCRE2_ERROR_UTF8_ERR16)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR16(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR17
#  define HANDLE_PCRE2_ERROR_UTF8_ERR17(X) X(PCRE2_ERROR_UTF8_ERR17)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR17(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR18
#  define HANDLE_PCRE2_ERROR_UTF8_ERR18(X) X(PCRE2_ERROR_UTF8_ERR18)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR18(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR19
#  define HANDLE_PCRE2_ERROR_UTF8_ERR19(X) X(PCRE2_ERROR_UTF8_ERR19)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR19(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR20
#  define HANDLE_PCRE2_ERROR_UTF8_ERR20(X) X(PCRE2_ERROR_UTF8_ERR20)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR20(X)
#endif
#ifdef PCRE2_ERROR_UTF8_ERR21
#  define HANDLE_PCRE2_ERROR_UTF8_ERR21(X) X(PCRE2_ERROR_UTF8_ERR21)
#else
#  define HANDLE_PCRE2_ERROR_UTF8_ERR21(X)
#endif
#ifdef PCRE2_ERROR_UTF16_ERR1
#  define HANDLE_PCRE2_ERROR_UTF16_ERR1(X) X(PCRE2_ERROR_UTF16_ERR1)
#else
#  define HANDLE_PCRE2_ERROR_UTF16_ERR1(X)
#endif
#ifdef PCRE2_ERROR_UTF16_ERR2
#  define HANDLE_PCRE2_ERROR_UTF16_ERR2(X) X(PCRE2_ERROR_UTF16_ERR2)
#else
#  define HANDLE_PCRE2_ERROR_UTF16_ERR2(X)
#endif
#ifdef PCRE2_ERROR_UTF16_ERR3
#  define HANDLE_PCRE2_ERROR_UTF16_ERR3(X) X(PCRE2_ERROR_UTF16_ERR3)
#else
#  define HANDLE_PCRE2_ERROR_UTF16_ERR3(X)
#endif
#ifdef PCRE2_ERROR_UTF32_ERR1
#  define HANDLE_PCRE2_ERROR_UTF32_ERR1(X) X(PCRE2_ERROR_UTF32_ERR1)
#else
#  define HANDLE_PCRE2_ERROR_UTF32_ERR1(X)
#endif
#ifdef PCRE2_ERROR_UTF32_ERR2
#  define HANDLE_PCRE2_ERROR_UTF32_ERR2(X) X(PCRE2_ERROR_UTF32_ERR2)
#else
#  define HANDLE_PCRE2_ERROR_UTF32_ERR2(X)
#endif
#ifdef PCRE2_ERROR_BADDATA
#  define HANDLE_PCRE2_ERROR_BADDATA(X) X(PCRE2_ERROR_BADDATA)
#else
#  define HANDLE_PCRE2_ERROR_BADDATA(X)
#endif
#ifdef PCRE2_ERROR_MIXEDTABLES
#  define HANDLE_PCRE2_ERROR_MIXEDTABLES(X) X(PCRE2_ERROR_MIXEDTABLES)
#else
#  define HANDLE_PCRE2_ERROR_MIXEDTABLES(X)
#endif
#ifdef PCRE2_ERROR_BADMAGIC
#  define HANDLE_PCRE2_ERROR_BADMAGIC(X) X(PCRE2_ERROR_BADMAGIC)
#else
#  define HANDLE_PCRE2_ERROR_BADMAGIC(X)
#endif
#ifdef PCRE2_ERROR_BADMODE
#  define HANDLE_PCRE2_ERROR_BADMODE(X) X(PCRE2_ERROR_BADMODE)
#else
#  define HANDLE_PCRE2_ERROR_BADMODE(X)
#endif
#ifdef PCRE2_ERROR_BADOFFSET
#  define HANDLE_PCRE2_ERROR_BADOFFSET(X) X(PCRE2_ERROR_BADOFFSET)
#else
#  define HANDLE_PCRE2_ERROR_BADOFFSET(X)
#endif
#ifdef PCRE2_ERROR_BADOPTION
#  define HANDLE_PCRE2_ERROR_BADOPTION(X) X(PCRE2_ERROR_BADOPTION)
#else
#  define HANDLE_PCRE2_ERROR_BADOPTION(X)
#endif
#ifdef PCRE2_ERROR_BADREPLACEMENT
#  define HANDLE_PCRE2_ERROR_BADREPLACEMENT(X) X(PCRE2_ERROR_BADREPLACEMENT)
#else
#  define HANDLE_PCRE2_ERROR_BADREPLACEMENT(X)
#endif
#ifdef PCRE2_ERROR_BADUTFOFFSET
#  define HANDLE_PCRE2_ERROR_BADUTFOFFSET(X) X(PCRE2_ERROR_BADUTFOFFSET)
#else
#  define HANDLE_PCRE2_ERROR_BADUTFOFFSET(X)
#endif
#ifdef PCRE2_ERROR_CALLOUT
#  define HANDLE_PCRE2_ERROR_CALLOUT(X) X(PCRE2_ERROR_CALLOUT)
#else
#  define HANDLE_PCRE2_ERROR_CALLOUT(X)
#endif
#ifdef PCRE2_ERROR_DFA_BADRESTART
#  define HANDLE_PCRE2_ERROR_DFA_BADRESTART(X) X(PCRE2_ERROR_DFA_BADRESTART)
#else
#  define HANDLE_PCRE2_ERROR_DFA_BADRESTART(X)
#endif
#ifdef PCRE2_ERROR_DFA_RECURSE
#  define HANDLE_PCRE2_ERROR_DFA_RECURSE(X) X(PCRE2_ERROR_DFA_RECURSE)
#else
#  define HANDLE_PCRE2_ERROR_DFA_RECURSE(X)
#endif
#ifdef PCRE2_ERROR_DFA_UCOND
#  define HANDLE_PCRE2_ERROR_DFA_UCOND(X) X(PCRE2_ERROR_DFA_UCOND)
#else
#  define HANDLE_PCRE2_ERROR_DFA_UCOND(X)
#endif
#ifdef PCRE2_ERROR_DFA_UFUNC
#  define HANDLE_PCRE2_ERROR_DFA_UFUNC(X) X(PCRE2_ERROR_DFA_UFUNC)
#else
#  define HANDLE_PCRE2_ERROR_DFA_UFUNC(X)
#endif
#ifdef PCRE2_ERROR_DFA_UITEM
#  define HANDLE_PCRE2_ERROR_DFA_UITEM(X) X(PCRE2_ERROR_DFA_UITEM)
#else
#  define HANDLE_PCRE2_ERROR_DFA_UITEM(X)
#endif
#ifdef PCRE2_ERROR_DFA_WSSIZE
#  define HANDLE_PCRE2_ERROR_DFA_WSSIZE(X) X(PCRE2_ERROR_DFA_WSSIZE)
#else
#  define HANDLE_PCRE2_ERROR_DFA_WSSIZE(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL
#  define HANDLE_PCRE2_ERROR_INTERNAL(X) X(PCRE2_ERROR_INTERNAL)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL(X)
#endif
#ifdef PCRE2_ERROR_JIT_BADOPTION
#  define HANDLE_PCRE2_ERROR_JIT_BADOPTION(X) X(PCRE2_ERROR_JIT_BADOPTION)
#else
#  define HANDLE_PCRE2_ERROR_JIT_BADOPTION(X)
#endif
#ifdef PCRE2_ERROR_JIT_STACKLIMIT
#  define HANDLE_PCRE2_ERROR_JIT_STACKLIMIT(X) X(PCRE2_ERROR_JIT_STACKLIMIT)
#else
#  define HANDLE_PCRE2_ERROR_JIT_STACKLIMIT(X)
#endif
#ifdef PCRE2_ERROR_MATCHLIMIT
#  define HANDLE_PCRE2_ERROR_MATCHLIMIT(X) X(PCRE2_ERROR_MATCHLIMIT)
#else
#  define HANDLE_PCRE2_ERROR_MATCHLIMIT(X)
#endif
#ifdef PCRE2_ERROR_NOMEMORY
#  define HANDLE_PCRE2_ERROR_NOMEMORY(X) X(PCRE2_ERROR_NOMEMORY)
#else
#  define HANDLE_PCRE2_ERROR_NOMEMORY(X)
#endif
#ifdef PCRE2_ERROR_NOSUBSTRING
#  define HANDLE_PCRE2_ERROR_NOSUBSTRING(X) X(PCRE2_ERROR_NOSUBSTRING)
#else
#  define HANDLE_PCRE2_ERROR_NOSUBSTRING(X)
#endif
#ifdef PCRE2_ERROR_NOUNIQUESUBSTRING
#  define HANDLE_PCRE2_ERROR_NOUNIQUESUBSTRING(X) X(PCRE2_ERROR_NOUNIQUESUBSTRING)
#else
#  define HANDLE_PCRE2_ERROR_NOUNIQUESUBSTRING(X)
#endif
#ifdef PCRE2_ERROR_NULL
#  define HANDLE_PCRE2_ERROR_NULL(X) X(PCRE2_ERROR_NULL)
#else
#  define HANDLE_PCRE2_ERROR_NULL(X)
#endif
#ifdef PCRE2_ERROR_RECURSELOOP
#  define HANDLE_PCRE2_ERROR_RECURSELOOP(X) X(PCRE2_ERROR_RECURSELOOP)
#else
#  define HANDLE_PCRE2_ERROR_RECURSELOOP(X)
#endif
#ifdef PCRE2_ERROR_DEPTHLIMIT
#  define HANDLE_PCRE2_ERROR_DEPTHLIMIT(X) X(PCRE2_ERROR_DEPTHLIMIT)
#else
#  define HANDLE_PCRE2_ERROR_DEPTHLIMIT(X)
#endif
#ifdef PCRE2_ERROR_RECURSIONLIMIT
#  define HANDLE_PCRE2_ERROR_RECURSIONLIMIT(X) X(PCRE2_ERROR_RECURSIONLIMIT)
#else
#  define HANDLE_PCRE2_ERROR_RECURSIONLIMIT(X)
#endif
#ifdef PCRE2_ERROR_UNAVAILABLE
#  define HANDLE_PCRE2_ERROR_UNAVAILABLE(X) X(PCRE2_ERROR_UNAVAILABLE)
#else
#  define HANDLE_PCRE2_ERROR_UNAVAILABLE(X)
#endif
#ifdef PCRE2_ERROR_UNSET
#  define HANDLE_PCRE2_ERROR_UNSET(X) X(PCRE2_ERROR_UNSET)
#else
#  define HANDLE_PCRE2_ERROR_UNSET(X)
#endif
#ifdef PCRE2_ERROR_BADOFFSETLIMIT
#  define HANDLE_PCRE2_ERROR_BADOFFSETLIMIT(X) X(PCRE2_ERROR_BADOFFSETLIMIT)
#else
#  define HANDLE_PCRE2_ERROR_BADOFFSETLIMIT(X)
#endif
#ifdef PCRE2_ERROR_BADREPESCAPE
#  define HANDLE_PCRE2_ERROR_BADREPESCAPE(X) X(PCRE2_ERROR_BADREPESCAPE)
#else
#  define HANDLE_PCRE2_ERROR_BADREPESCAPE(X)
#endif
#ifdef PCRE2_ERROR_REPMISSINGBRACE
#  define HANDLE_PCRE2_ERROR_REPMISSINGBRACE(X) X(PCRE2_ERROR_REPMISSINGBRACE)
#else
#  define HANDLE_PCRE2_ERROR_REPMISSINGBRACE(X)
#endif
#ifdef PCRE2_ERROR_BADSUBSTITUTION
#  define HANDLE_PCRE2_ERROR_BADSUBSTITUTION(X) X(PCRE2_ERROR_BADSUBSTITUTION)
#else
#  define HANDLE_PCRE2_ERROR_BADSUBSTITUTION(X)
#endif
#ifdef PCRE2_ERROR_BADSUBSPATTERN
#  define HANDLE_PCRE2_ERROR_BADSUBSPATTERN(X) X(PCRE2_ERROR_BADSUBSPATTERN)
#else
#  define HANDLE_PCRE2_ERROR_BADSUBSPATTERN(X)
#endif
#ifdef PCRE2_ERROR_TOOMANYREPLACE
#  define HANDLE_PCRE2_ERROR_TOOMANYREPLACE(X) X(PCRE2_ERROR_TOOMANYREPLACE)
#else
#  define HANDLE_PCRE2_ERROR_TOOMANYREPLACE(X)
#endif
#ifdef PCRE2_ERROR_BADSERIALIZEDDATA
#  define HANDLE_PCRE2_ERROR_BADSERIALIZEDDATA(X) X(PCRE2_ERROR_BADSERIALIZEDDATA)
#else
#  define HANDLE_PCRE2_ERROR_BADSERIALIZEDDATA(X)
#endif
#ifdef PCRE2_ERROR_HEAPLIMIT
#  define HANDLE_PCRE2_ERROR_HEAPLIMIT(X) X(PCRE2_ERROR_HEAPLIMIT)
#else
#  define HANDLE_PCRE2_ERROR_HEAPLIMIT(X)
#endif
#ifdef PCRE2_ERROR_CONVERT_SYNTAX
#  define HANDLE_PCRE2_ERROR_CONVERT_SYNTAX(X) X(PCRE2_ERROR_CONVERT_SYNTAX)
#else
#  define HANDLE_PCRE2_ERROR_CONVERT_SYNTAX(X)
#endif
#ifdef PCRE2_ERROR_INTERNAL_DUPMATCH
#  define HANDLE_PCRE2_ERROR_INTERNAL_DUPMATCH(X) X(PCRE2_ERROR_INTERNAL_DUPMATCH)
#else
#  define HANDLE_PCRE2_ERROR_INTERNAL_DUPMATCH(X)
#endif
#ifdef PCRE2_ERROR_DFA_UINVALID_UTF
#  define HANDLE_PCRE2_ERROR_DFA_UINVALID_UTF(X) X(PCRE2_ERROR_DFA_UINVALID_UTF)
#else
#  define HANDLE_PCRE2_ERROR_DFA_UINVALID_UTF(X)
#endif
#ifdef PCRE2_ERROR_INVALIDOFFSET
#  define HANDLE_PCRE2_ERROR_INVALIDOFFSET(X) X(PCRE2_ERROR_INVALIDOFFSET)
#else
#  define HANDLE_PCRE2_ERROR_INVALIDOFFSET(X)
#endif
#ifdef PCRE2_ERROR_JIT_UNSUPPORTED
#  define HANDLE_PCRE2_ERROR_JIT_UNSUPPORTED(X) X(PCRE2_ERROR_JIT_UNSUPPORTED)
#else
#  define HANDLE_PCRE2_ERROR_JIT_UNSUPPORTED(X)
#endif
#ifdef PCRE2_ERROR_REPLACECASE
#  define HANDLE_PCRE2_ERROR_REPLACECASE(X) X(PCRE2_ERROR_REPLACECASE)
#else
#  define HANDLE_PCRE2_ERROR_REPLACECASE(X)
#endif
#ifdef PCRE2_ERROR_TOOLARGEREPLACE
#  define HANDLE_PCRE2_ERROR_TOOLARGEREPLACE(X) X(PCRE2_ERROR_TOOLARGEREPLACE)
#else
#  define HANDLE_PCRE2_ERROR_TOOLARGEREPLACE(X)
#endif
#ifdef PCRE2_ERROR_DIFFSUBSPATTERN
#  define HANDLE_PCRE2_ERROR_DIFFSUBSPATTERN(X) X(PCRE2_ERROR_DIFFSUBSPATTERN)
#else
#  define HANDLE_PCRE2_ERROR_DIFFSUBSPATTERN(X)
#endif
#ifdef PCRE2_ERROR_DIFFSUBSSUBJECT
#  define HANDLE_PCRE2_ERROR_DIFFSUBSSUBJECT(X) X(PCRE2_ERROR_DIFFSUBSSUBJECT)
#else
#  define HANDLE_PCRE2_ERROR_DIFFSUBSSUBJECT(X)
#endif
#ifdef PCRE2_ERROR_DIFFSUBSOFFSET
#  define HANDLE_PCRE2_ERROR_DIFFSUBSOFFSET(X) X(PCRE2_ERROR_DIFFSUBSOFFSET)
#else
#  define HANDLE_PCRE2_ERROR_DIFFSUBSOFFSET(X)
#endif
#ifdef PCRE2_ERROR_DIFFSUBSOPTIONS
#  define HANDLE_PCRE2_ERROR_DIFFSUBSOPTIONS(X) X(PCRE2_ERROR_DIFFSUBSOPTIONS)
#else
#  define HANDLE_PCRE2_ERROR_DIFFSUBSOPTIONS(X)
#endif

#define PCRE2_ERROR_LIST(X) \
    HANDLE_PCRE2_ERROR_END_BACKSLASH(X) \
    HANDLE_PCRE2_ERROR_END_BACKSLASH_C(X) \
    HANDLE_PCRE2_ERROR_UNKNOWN_ESCAPE(X) \
    HANDLE_PCRE2_ERROR_QUANTIFIER_OUT_OF_ORDER(X) \
    HANDLE_PCRE2_ERROR_QUANTIFIER_TOO_BIG(X) \
    HANDLE_PCRE2_ERROR_MISSING_SQUARE_BRACKET(X) \
    HANDLE_PCRE2_ERROR_ESCAPE_INVALID_IN_CLASS(X) \
    HANDLE_PCRE2_ERROR_CLASS_RANGE_ORDER(X) \
    HANDLE_PCRE2_ERROR_QUANTIFIER_INVALID(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_UNEXPECTED_REPEAT(X) \
    HANDLE_PCRE2_ERROR_INVALID_AFTER_PARENS_QUERY(X) \
    HANDLE_PCRE2_ERROR_POSIX_CLASS_NOT_IN_CLASS(X) \
    HANDLE_PCRE2_ERROR_POSIX_NO_SUPPORT_COLLATING(X) \
    HANDLE_PCRE2_ERROR_MISSING_CLOSING_PARENTHESIS(X) \
    HANDLE_PCRE2_ERROR_BAD_SUBPATTERN_REFERENCE(X) \
    HANDLE_PCRE2_ERROR_NULL_PATTERN(X) \
    HANDLE_PCRE2_ERROR_BAD_OPTIONS(X) \
    HANDLE_PCRE2_ERROR_MISSING_COMMENT_CLOSING(X) \
    HANDLE_PCRE2_ERROR_PARENTHESES_NEST_TOO_DEEP(X) \
    HANDLE_PCRE2_ERROR_PATTERN_TOO_LARGE(X) \
    HANDLE_PCRE2_ERROR_HEAP_FAILED(X) \
    HANDLE_PCRE2_ERROR_UNMATCHED_CLOSING_PARENTHESIS(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_CODE_OVERFLOW(X) \
    HANDLE_PCRE2_ERROR_MISSING_CONDITION_CLOSING(X) \
    HANDLE_PCRE2_ERROR_LOOKBEHIND_NOT_FIXED_LENGTH(X) \
    HANDLE_PCRE2_ERROR_ZERO_RELATIVE_REFERENCE(X) \
    HANDLE_PCRE2_ERROR_TOO_MANY_CONDITION_BRANCHES(X) \
    HANDLE_PCRE2_ERROR_CONDITION_ASSERTION_EXPECTED(X) \
    HANDLE_PCRE2_ERROR_BAD_RELATIVE_REFERENCE(X) \
    HANDLE_PCRE2_ERROR_UNKNOWN_POSIX_CLASS(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_STUDY_ERROR(X) \
    HANDLE_PCRE2_ERROR_UNICODE_NOT_SUPPORTED(X) \
    HANDLE_PCRE2_ERROR_PARENTHESES_STACK_CHECK(X) \
    HANDLE_PCRE2_ERROR_CODE_POINT_TOO_BIG(X) \
    HANDLE_PCRE2_ERROR_LOOKBEHIND_TOO_COMPLICATED(X) \
    HANDLE_PCRE2_ERROR_LOOKBEHIND_INVALID_BACKSLASH_C(X) \
    HANDLE_PCRE2_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE(X) \
    HANDLE_PCRE2_ERROR_CALLOUT_NUMBER_TOO_BIG(X) \
    HANDLE_PCRE2_ERROR_MISSING_CALLOUT_CLOSING(X) \
    HANDLE_PCRE2_ERROR_ESCAPE_INVALID_IN_VERB(X) \
    HANDLE_PCRE2_ERROR_UNRECOGNIZED_AFTER_QUERY_P(X) \
    HANDLE_PCRE2_ERROR_MISSING_NAME_TERMINATOR(X) \
    HANDLE_PCRE2_ERROR_DUPLICATE_SUBPATTERN_NAME(X) \
    HANDLE_PCRE2_ERROR_INVALID_SUBPATTERN_NAME(X) \
    HANDLE_PCRE2_ERROR_UNICODE_PROPERTIES_UNAVAILABLE(X) \
    HANDLE_PCRE2_ERROR_MALFORMED_UNICODE_PROPERTY(X) \
    HANDLE_PCRE2_ERROR_UNKNOWN_UNICODE_PROPERTY(X) \
    HANDLE_PCRE2_ERROR_SUBPATTERN_NAME_TOO_LONG(X) \
    HANDLE_PCRE2_ERROR_TOO_MANY_NAMED_SUBPATTERNS(X) \
    HANDLE_PCRE2_ERROR_CLASS_INVALID_RANGE(X) \
    HANDLE_PCRE2_ERROR_OCTAL_BYTE_TOO_BIG(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_OVERRAN_WORKSPACE(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_MISSING_SUBPATTERN(X) \
    HANDLE_PCRE2_ERROR_DEFINE_TOO_MANY_BRANCHES(X) \
    HANDLE_PCRE2_ERROR_BACKSLASH_O_MISSING_BRACE(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_UNKNOWN_NEWLINE(X) \
    HANDLE_PCRE2_ERROR_BACKSLASH_G_SYNTAX(X) \
    HANDLE_PCRE2_ERROR_PARENS_QUERY_R_MISSING_CLOSING(X) \
    HANDLE_PCRE2_ERROR_VERB_ARGUMENT_NOT_ALLOWED(X) \
    HANDLE_PCRE2_ERROR_VERB_UNKNOWN(X) \
    HANDLE_PCRE2_ERROR_SUBPATTERN_NUMBER_TOO_BIG(X) \
    HANDLE_PCRE2_ERROR_SUBPATTERN_NAME_EXPECTED(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_PARSED_OVERFLOW(X) \
    HANDLE_PCRE2_ERROR_INVALID_OCTAL(X) \
    HANDLE_PCRE2_ERROR_SUBPATTERN_NAMES_MISMATCH(X) \
    HANDLE_PCRE2_ERROR_MARK_MISSING_ARGUMENT(X) \
    HANDLE_PCRE2_ERROR_INVALID_HEXADECIMAL(X) \
    HANDLE_PCRE2_ERROR_BACKSLASH_C_SYNTAX(X) \
    HANDLE_PCRE2_ERROR_BACKSLASH_K_SYNTAX(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE_LOOKBEHINDS(X) \
    HANDLE_PCRE2_ERROR_BACKSLASH_N_IN_CLASS(X) \
    HANDLE_PCRE2_ERROR_CALLOUT_STRING_TOO_LONG(X) \
    HANDLE_PCRE2_ERROR_UNICODE_DISALLOWED_CODE_POINT(X) \
    HANDLE_PCRE2_ERROR_UTF_IS_DISABLED(X) \
    HANDLE_PCRE2_ERROR_UCP_IS_DISABLED(X) \
    HANDLE_PCRE2_ERROR_VERB_NAME_TOO_LONG(X) \
    HANDLE_PCRE2_ERROR_BACKSLASH_U_CODE_POINT_TOO_BIG(X) \
    HANDLE_PCRE2_ERROR_MISSING_OCTAL_OR_HEX_DIGITS(X) \
    HANDLE_PCRE2_ERROR_VERSION_CONDITION_SYNTAX(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE_AUTO_POSSESS(X) \
    HANDLE_PCRE2_ERROR_CALLOUT_NO_STRING_DELIMITER(X) \
    HANDLE_PCRE2_ERROR_CALLOUT_BAD_STRING_DELIMITER(X) \
    HANDLE_PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED(X) \
    HANDLE_PCRE2_ERROR_QUERY_BARJX_NEST_TOO_DEEP(X) \
    HANDLE_PCRE2_ERROR_BACKSLASH_C_LIBRARY_DISABLED(X) \
    HANDLE_PCRE2_ERROR_PATTERN_TOO_COMPLICATED(X) \
    HANDLE_PCRE2_ERROR_LOOKBEHIND_TOO_LONG(X) \
    HANDLE_PCRE2_ERROR_PATTERN_STRING_TOO_LONG(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_BAD_CODE_IN_SKIP(X) \
    HANDLE_PCRE2_ERROR_NO_SURROGATES_IN_UTF16(X) \
    HANDLE_PCRE2_ERROR_BAD_LITERAL_OPTIONS(X) \
    HANDLE_PCRE2_ERROR_SUPPORTED_ONLY_IN_UNICODE(X) \
    HANDLE_PCRE2_ERROR_INVALID_HYPHEN_IN_OPTIONS(X) \
    HANDLE_PCRE2_ERROR_ALPHA_ASSERTION_UNKNOWN(X) \
    HANDLE_PCRE2_ERROR_SCRIPT_RUN_NOT_AVAILABLE(X) \
    HANDLE_PCRE2_ERROR_TOO_MANY_CAPTURES(X) \
    HANDLE_PCRE2_ERROR_MISSING_OCTAL_DIGIT(X) \
    HANDLE_PCRE2_ERROR_BACKSLASH_K_IN_LOOKAROUND(X) \
    HANDLE_PCRE2_ERROR_MAX_VAR_LOOKBEHIND_EXCEEDED(X) \
    HANDLE_PCRE2_ERROR_PATTERN_COMPILED_SIZE_TOO_BIG(X) \
    HANDLE_PCRE2_ERROR_OVERSIZE_PYTHON_OCTAL(X) \
    HANDLE_PCRE2_ERROR_CALLOUT_CALLER_DISABLED(X) \
    HANDLE_PCRE2_ERROR_EXTRA_CASING_REQUIRES_UNICODE(X) \
    HANDLE_PCRE2_ERROR_TURKISH_CASING_REQUIRES_UTF(X) \
    HANDLE_PCRE2_ERROR_EXTRA_CASING_INCOMPATIBLE(X) \
    HANDLE_PCRE2_ERROR_ECLASS_NEST_TOO_DEEP(X) \
    HANDLE_PCRE2_ERROR_ECLASS_INVALID_OPERATOR(X) \
    HANDLE_PCRE2_ERROR_ECLASS_UNEXPECTED_OPERATOR(X) \
    HANDLE_PCRE2_ERROR_ECLASS_EXPECTED_OPERAND(X) \
    HANDLE_PCRE2_ERROR_ECLASS_MIXED_OPERATORS(X) \
    HANDLE_PCRE2_ERROR_ECLASS_HINT_SQUARE_BRACKET(X) \
    HANDLE_PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_EXPR(X) \
    HANDLE_PCRE2_ERROR_PERL_ECLASS_EMPTY_EXPR(X) \
    HANDLE_PCRE2_ERROR_PERL_ECLASS_MISSING_CLOSE(X) \
    HANDLE_PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_CHAR(X) \
    HANDLE_PCRE2_ERROR_EXPECTED_CAPTURE_GROUP(X) \
    HANDLE_PCRE2_ERROR_MISSING_OPENING_PARENTHESIS(X) \
    HANDLE_PCRE2_ERROR_MISSING_NUMBER_TERMINATOR(X) \
    HANDLE_PCRE2_ERROR_NULL_ERROROFFSET(X) \
    HANDLE_PCRE2_ERROR_NOMATCH(X) \
    HANDLE_PCRE2_ERROR_PARTIAL(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR1(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR2(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR3(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR4(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR5(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR6(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR7(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR8(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR9(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR10(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR11(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR12(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR13(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR14(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR15(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR16(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR17(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR18(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR19(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR20(X) \
    HANDLE_PCRE2_ERROR_UTF8_ERR21(X) \
    HANDLE_PCRE2_ERROR_UTF16_ERR1(X) \
    HANDLE_PCRE2_ERROR_UTF16_ERR2(X) \
    HANDLE_PCRE2_ERROR_UTF16_ERR3(X) \
    HANDLE_PCRE2_ERROR_UTF32_ERR1(X) \
    HANDLE_PCRE2_ERROR_UTF32_ERR2(X) \
    HANDLE_PCRE2_ERROR_BADDATA(X) \
    HANDLE_PCRE2_ERROR_MIXEDTABLES(X) \
    HANDLE_PCRE2_ERROR_BADMAGIC(X) \
    HANDLE_PCRE2_ERROR_BADMODE(X) \
    HANDLE_PCRE2_ERROR_BADOFFSET(X) \
    HANDLE_PCRE2_ERROR_BADOPTION(X) \
    HANDLE_PCRE2_ERROR_BADREPLACEMENT(X) \
    HANDLE_PCRE2_ERROR_BADUTFOFFSET(X) \
    HANDLE_PCRE2_ERROR_CALLOUT(X) \
    HANDLE_PCRE2_ERROR_DFA_BADRESTART(X) \
    HANDLE_PCRE2_ERROR_DFA_RECURSE(X) \
    HANDLE_PCRE2_ERROR_DFA_UCOND(X) \
    HANDLE_PCRE2_ERROR_DFA_UFUNC(X) \
    HANDLE_PCRE2_ERROR_DFA_UITEM(X) \
    HANDLE_PCRE2_ERROR_DFA_WSSIZE(X) \
    HANDLE_PCRE2_ERROR_INTERNAL(X) \
    HANDLE_PCRE2_ERROR_JIT_BADOPTION(X) \
    HANDLE_PCRE2_ERROR_JIT_STACKLIMIT(X) \
    HANDLE_PCRE2_ERROR_MATCHLIMIT(X) \
    HANDLE_PCRE2_ERROR_NOMEMORY(X) \
    HANDLE_PCRE2_ERROR_NOSUBSTRING(X) \
    HANDLE_PCRE2_ERROR_NOUNIQUESUBSTRING(X) \
    HANDLE_PCRE2_ERROR_NULL(X) \
    HANDLE_PCRE2_ERROR_RECURSELOOP(X) \
    HANDLE_PCRE2_ERROR_DEPTHLIMIT(X) \
    HANDLE_PCRE2_ERROR_RECURSIONLIMIT(X) \
    HANDLE_PCRE2_ERROR_UNAVAILABLE(X) \
    HANDLE_PCRE2_ERROR_UNSET(X) \
    HANDLE_PCRE2_ERROR_BADOFFSETLIMIT(X) \
    HANDLE_PCRE2_ERROR_BADREPESCAPE(X) \
    HANDLE_PCRE2_ERROR_REPMISSINGBRACE(X) \
    HANDLE_PCRE2_ERROR_BADSUBSTITUTION(X) \
    HANDLE_PCRE2_ERROR_BADSUBSPATTERN(X) \
    HANDLE_PCRE2_ERROR_TOOMANYREPLACE(X) \
    HANDLE_PCRE2_ERROR_BADSERIALIZEDDATA(X) \
    HANDLE_PCRE2_ERROR_HEAPLIMIT(X) \
    HANDLE_PCRE2_ERROR_CONVERT_SYNTAX(X) \
    HANDLE_PCRE2_ERROR_INTERNAL_DUPMATCH(X) \
    HANDLE_PCRE2_ERROR_DFA_UINVALID_UTF(X) \
    HANDLE_PCRE2_ERROR_INVALIDOFFSET(X) \
    HANDLE_PCRE2_ERROR_JIT_UNSUPPORTED(X) \
    HANDLE_PCRE2_ERROR_REPLACECASE(X) \
    HANDLE_PCRE2_ERROR_TOOLARGEREPLACE(X) \
    HANDLE_PCRE2_ERROR_DIFFSUBSPATTERN(X) \
    HANDLE_PCRE2_ERROR_DIFFSUBSSUBJECT(X) \
    HANDLE_PCRE2_ERROR_DIFFSUBSOFFSET(X) \
    HANDLE_PCRE2_ERROR_DIFFSUBSOPTIONS(X) \

typedef struct {
    int code;
    const char *macro_name;
} PcreErrorInfo;

static const PcreErrorInfo pcre_error_info_list[] = {
#define DECLARE_PCRE2_ERROR_INFO(name) {name, #name},
    PCRE2_ERROR_LIST(DECLARE_PCRE2_ERROR_INFO)
#undef DECLARE_PCRE2_ERROR_INFO
};

static const size_t pcre_error_info_count = sizeof(pcre_error_info_list) / sizeof(pcre_error_info_list[0]);

PyObject *PcreError = NULL;
static PyObject *PcreErrorByCode = NULL;

static char *
macro_name_to_camel(const char *macro_name)
{
    static const char prefix[] = "PCRE2_ERROR_";
    const size_t prefix_len = sizeof(prefix) - 1;
    const char *cursor = macro_name;

    if (strncmp(cursor, prefix, prefix_len) == 0) {
        cursor += prefix_len;
    }

    size_t length = 0;
    int new_component = 1;
    for (const char *p = cursor; *p != '\0'; ++p) {
        if (*p == '_') {
            new_component = 1;
            continue;
        }
        length++;
        new_component = 0;
    }

    char *result = pcre_malloc(length + 1);
    if (result == NULL) {
        PyErr_NoMemory();
        return NULL;
    }

    size_t out_index = 0;
    new_component = 1;
    for (const char *p = cursor; *p != '\0'; ++p) {
        unsigned char uc = (unsigned char)*p;
        if (uc == '_') {
            new_component = 1;
            continue;
        }
        char c = (char)uc;
        if (isalpha(uc)) {
            c = (char)(new_component ? toupper(uc) : tolower(uc));
        }
        result[out_index++] = c;
        new_component = 0;
    }
    result[out_index] = '\0';
    return result;
}

static PyObject *
get_error_type_for_code(int error_code)
{
    if (PcreErrorByCode == NULL) {
        Py_INCREF(PcreError);
        return PcreError;
    }

    PyObject *code_obj = PyLong_FromLong(error_code);
    if (code_obj == NULL) {
        return NULL;
    }

    PyObject *exc_type = PyDict_GetItemWithError(PcreErrorByCode, code_obj);
    Py_DECREF(code_obj);
    if (exc_type == NULL) {
        if (PyErr_Occurred()) {
            return NULL;
        }
        Py_INCREF(PcreError);
        return PcreError;
    }

    Py_INCREF(exc_type);
    return exc_type;
}

void
raise_pcre_error(const char *context, int error_code, PCRE2_SIZE error_offset)
{
    PCRE2_UCHAR buffer[256];
    int rc = pcre2_get_error_message(error_code, buffer,
                                     (PCRE2_SIZE)(sizeof(buffer) / sizeof(PCRE2_UCHAR)));
    const char *message = rc >= 0 ? (const char *)buffer : "unknown PCRE2 error";

    PyObject *exc_type = get_error_type_for_code(error_code);
    if (exc_type == NULL) {
        return;
    }

    PyObject *exc = PyObject_CallFunction(exc_type, "ss", context, message);
    if (exc == NULL) {
        Py_DECREF(exc_type);
        return;
    }

    PyObject *code_obj = PyLong_FromLong(error_code);
    if (code_obj != NULL) {
        if (PyObject_SetAttrString(exc, "code", code_obj) < 0) {
            PyErr_Clear();
        }
    }
    Py_XDECREF(code_obj);

    PyObject *offset_obj = PyLong_FromSize_t((size_t)error_offset);
    if (offset_obj != NULL) {
        if (PyObject_SetAttrString(exc, "offset", offset_obj) < 0) {
            PyErr_Clear();
        }
    }
    Py_XDECREF(offset_obj);

    PyErr_SetObject(exc_type, exc);
    Py_DECREF(exc_type);
    Py_DECREF(exc);
}

static int
register_pcre_error_types(PyObject *module)
{
    if (PcreErrorByCode != NULL) {
        return 0;
    }

    PcreErrorByCode = PyDict_New();
    if (PcreErrorByCode == NULL) {
        return -1;
    }

    for (size_t i = 0; i < pcre_error_info_count; ++i) {
        const PcreErrorInfo *info = &pcre_error_info_list[i];
        char *camel = macro_name_to_camel(info->macro_name);
        if (camel == NULL) {
            goto error;
        }

        size_t camel_len = strlen(camel);
        size_t class_name_len = strlen("PcreError") + camel_len;
        char *class_name = pcre_malloc(class_name_len + 1);
        if (class_name == NULL) {
            PyErr_NoMemory();
            pcre_free(camel);
            goto error;
        }
        snprintf(class_name, class_name_len + 1, "PcreError%s", camel);

        size_t qual_name_len = strlen("pcre.") + class_name_len;
        char *qual_name = pcre_malloc(qual_name_len + 1);
        if (qual_name == NULL) {
            PyErr_NoMemory();
            pcre_free(class_name);
            pcre_free(camel);
            goto error;
        }
        snprintf(qual_name, qual_name_len + 1, "pcre.%s", class_name);

        PyObject *exc_type = PyErr_NewException(qual_name, PcreError, NULL);
        pcre_free(qual_name);
        pcre_free(camel);
        if (exc_type == NULL) {
            pcre_free(class_name);
            goto error;
        }

        PyObject *code_obj = PyLong_FromLong(info->code);
        if (code_obj == NULL) {
            Py_DECREF(exc_type);
            pcre_free(class_name);
            goto error;
        }

        if (PyObject_SetAttrString(exc_type, "code", code_obj) < 0) {
            Py_DECREF(code_obj);
            Py_DECREF(exc_type);
            pcre_free(class_name);
            goto error;
        }

        PyObject *macro_str = PyUnicode_FromString(info->macro_name);
        if (macro_str == NULL) {
            Py_DECREF(code_obj);
            Py_DECREF(exc_type);
            pcre_free(class_name);
            goto error;
        }
        if (PyObject_SetAttrString(exc_type, "macro", macro_str) < 0) {
            Py_DECREF(macro_str);
            Py_DECREF(code_obj);
            Py_DECREF(exc_type);
            pcre_free(class_name);
            goto error;
        }
        Py_DECREF(macro_str);

        int contains = PyDict_Contains(PcreErrorByCode, code_obj);
        if (contains < 0) {
            Py_DECREF(code_obj);
            Py_DECREF(exc_type);
            pcre_free(class_name);
            goto error;
        }
        if (!contains) {
            if (PyDict_SetItem(PcreErrorByCode, code_obj, exc_type) < 0) {
                Py_DECREF(code_obj);
                Py_DECREF(exc_type);
                pcre_free(class_name);
                goto error;
            }
        }

        if (PyModule_AddObject(module, class_name, exc_type) < 0) {
            if (!contains) {
                PyDict_DelItem(PcreErrorByCode, code_obj);
            }
            Py_DECREF(code_obj);
            Py_DECREF(exc_type);
            pcre_free(class_name);
            goto error;
        }
        pcre_free(class_name);
        Py_DECREF(code_obj);
    }

#define ADD_PCRE2_ERROR_CONSTANT(name)                                                     \
    if (PyModule_AddIntConstant(module, #name, name) < 0) {                               \
        goto error;                                                                        \
    }
    PCRE2_ERROR_LIST(ADD_PCRE2_ERROR_CONSTANT)
#undef ADD_PCRE2_ERROR_CONSTANT

    return 0;

error:
    Py_CLEAR(PcreErrorByCode);
    return -1;
}

int
pcre_error_init(PyObject *module)
{
    if (PcreError == NULL) {
        PcreError = PyErr_NewExceptionWithDoc("pcre.PcreError",
                                              "Exception raised for PCRE2-related errors.",
                                              NULL,
                                              NULL);
        if (PcreError == NULL) {
            return -1;
        }
    }

    if (register_pcre_error_types(module) < 0) {
        return -1;
    }

    Py_INCREF(PcreError);
    if (PyModule_AddObject(module, "PcreError", PcreError) < 0) {
        Py_DECREF(PcreError);
        return -1;
    }

    return 0;
}

void
pcre_error_teardown(void)
{
    Py_XDECREF(PcreError);
    PcreError = NULL;
    Py_CLEAR(PcreErrorByCode);
}
