pcre2_internal.h 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004
  1. /*************************************************
  2. * Perl-Compatible Regular Expressions *
  3. *************************************************/
  4. /* PCRE2 is a library of functions to support regular expressions whose syntax
  5. and semantics are as close as possible to those of the Perl 5 language.
  6. Written by Philip Hazel
  7. Original API code Copyright (c) 1997-2012 University of Cambridge
  8. New API code Copyright (c) 2016-2020 University of Cambridge
  9. -----------------------------------------------------------------------------
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions are met:
  12. * Redistributions of source code must retain the above copyright notice,
  13. this list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright
  15. notice, this list of conditions and the following disclaimer in the
  16. documentation and/or other materials provided with the distribution.
  17. * Neither the name of the University of Cambridge nor the names of its
  18. contributors may be used to endorse or promote products derived from
  19. this software without specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  24. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. POSSIBILITY OF SUCH DAMAGE.
  31. -----------------------------------------------------------------------------
  32. */
  33. #ifndef PCRE2_INTERNAL_H_IDEMPOTENT_GUARD
  34. #define PCRE2_INTERNAL_H_IDEMPOTENT_GUARD
  35. /* We do not support both EBCDIC and Unicode at the same time. The "configure"
  36. script prevents both being selected, but not everybody uses "configure". EBCDIC
  37. is only supported for the 8-bit library, but the check for this has to be later
  38. in this file, because the first part is not width-dependent, and is included by
  39. pcre2test.c with CODE_UNIT_WIDTH == 0. */
  40. #if defined EBCDIC && defined SUPPORT_UNICODE
  41. #error The use of both EBCDIC and SUPPORT_UNICODE is not supported.
  42. #endif
  43. /* Standard C headers */
  44. #include <ctype.h>
  45. #include <limits.h>
  46. #include <stddef.h>
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <string.h>
  50. /* Macros to make boolean values more obvious. The #ifndef is to pacify
  51. compiler warnings in environments where these macros are defined elsewhere.
  52. Unfortunately, there is no way to do the same for the typedef. */
  53. typedef int BOOL;
  54. #ifndef FALSE
  55. #define FALSE 0
  56. #define TRUE 1
  57. #endif
  58. /* Valgrind (memcheck) support */
  59. #ifdef SUPPORT_VALGRIND
  60. #include <valgrind/memcheck.h>
  61. #endif
  62. /* -ftrivial-auto-var-init support supports initializing all local variables
  63. to avoid some classes of bug, but this can cause an unacceptable slowdown
  64. for large on-stack arrays in hot functions. This macro lets us annotate
  65. such arrays. */
  66. #ifdef HAVE_ATTRIBUTE_UNINITIALIZED
  67. #define PCRE2_KEEP_UNINITIALIZED __attribute__((uninitialized))
  68. #else
  69. #define PCRE2_KEEP_UNINITIALIZED
  70. #endif
  71. /* Older versions of MSVC lack snprintf(). This define allows for
  72. warning/error-free compilation and testing with MSVC compilers back to at least
  73. MSVC 10/2010. Except for VC6 (which is missing some fundamentals and fails). */
  74. #if defined(_MSC_VER) && (_MSC_VER < 1900)
  75. #define snprintf _snprintf
  76. #endif
  77. /* When compiling a DLL for Windows, the exported symbols have to be declared
  78. using some MS magic. I found some useful information on this web page:
  79. http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the
  80. information there, using __declspec(dllexport) without "extern" we have a
  81. definition; with "extern" we have a declaration. The settings here override the
  82. setting in pcre2.h (which is included below); it defines only PCRE2_EXP_DECL,
  83. which is all that is needed for applications (they just import the symbols). We
  84. use:
  85. PCRE2_EXP_DECL for declarations
  86. PCRE2_EXP_DEFN for definitions
  87. The reason for wrapping this in #ifndef PCRE2_EXP_DECL is so that pcre2test,
  88. which is an application, but needs to import this file in order to "peek" at
  89. internals, can #include pcre2.h first to get an application's-eye view.
  90. In principle, people compiling for non-Windows, non-Unix-like (i.e. uncommon,
  91. special-purpose environments) might want to stick other stuff in front of
  92. exported symbols. That's why, in the non-Windows case, we set PCRE2_EXP_DEFN
  93. only if it is not already set. */
  94. #ifndef PCRE2_EXP_DECL
  95. # ifdef _WIN32
  96. # ifndef PCRE2_STATIC
  97. # define PCRE2_EXP_DECL extern __declspec(dllexport)
  98. # define PCRE2_EXP_DEFN __declspec(dllexport)
  99. # else
  100. # define PCRE2_EXP_DECL extern
  101. # define PCRE2_EXP_DEFN
  102. # endif
  103. # else
  104. # ifdef __cplusplus
  105. # define PCRE2_EXP_DECL extern "C"
  106. # else
  107. # define PCRE2_EXP_DECL extern
  108. # endif
  109. # ifndef PCRE2_EXP_DEFN
  110. # define PCRE2_EXP_DEFN PCRE2_EXP_DECL
  111. # endif
  112. # endif
  113. #endif
  114. /* Include the public PCRE2 header and the definitions of UCP character
  115. property values. This must follow the setting of PCRE2_EXP_DECL above. */
  116. #include "pcre2.h"
  117. #include "pcre2_ucp.h"
  118. /* When PCRE2 is compiled as a C++ library, the subject pointer can be replaced
  119. with a custom type. This makes it possible, for example, to allow pcre2_match()
  120. to process subject strings that are discontinuous by using a smart pointer
  121. class. It must always be possible to inspect all of the subject string in
  122. pcre2_match() because of the way it backtracks. */
  123. /* WARNING: This is as yet untested for PCRE2. */
  124. #ifdef CUSTOM_SUBJECT_PTR
  125. #undef PCRE2_SPTR
  126. #define PCRE2_SPTR CUSTOM_SUBJECT_PTR
  127. #endif
  128. /* When checking for integer overflow in pcre2_compile(), we need to handle
  129. large integers. If a 64-bit integer type is available, we can use that.
  130. Otherwise we have to cast to double, which of course requires floating point
  131. arithmetic. Handle this by defining a macro for the appropriate type. */
  132. #if defined INT64_MAX || defined int64_t
  133. #define INT64_OR_DOUBLE int64_t
  134. #else
  135. #define INT64_OR_DOUBLE double
  136. #endif
  137. /* External (in the C sense) functions and tables that are private to the
  138. libraries are always referenced using the PRIV macro. This makes it possible
  139. for pcre2test.c to include some of the source files from the libraries using a
  140. different PRIV definition to avoid name clashes. It also makes it clear in the
  141. code that a non-static object is being referenced. */
  142. #ifndef PRIV
  143. #define PRIV(name) _pcre2_##name
  144. #endif
  145. /* When compiling for use with the Virtual Pascal compiler, these functions
  146. need to have their names changed. PCRE2 must be compiled with the -DVPCOMPAT
  147. option on the command line. */
  148. #ifdef VPCOMPAT
  149. #define strlen(s) _strlen(s)
  150. #define strncmp(s1,s2,m) _strncmp(s1,s2,m)
  151. #define memcmp(s,c,n) _memcmp(s,c,n)
  152. #define memcpy(d,s,n) _memcpy(d,s,n)
  153. #define memmove(d,s,n) _memmove(d,s,n)
  154. #define memset(s,c,n) _memset(s,c,n)
  155. #else /* VPCOMPAT */
  156. /* Otherwise, to cope with SunOS4 and other systems that lack memmove(), define
  157. a macro that calls an emulating function. */
  158. #ifndef HAVE_MEMMOVE
  159. #undef memmove /* Some systems may have a macro */
  160. #define memmove(a, b, c) PRIV(memmove)(a, b, c)
  161. #endif /* not HAVE_MEMMOVE */
  162. #endif /* not VPCOMPAT */
  163. /* This is an unsigned int value that no UTF character can ever have, as
  164. Unicode doesn't go beyond 0x0010ffff. */
  165. #define NOTACHAR 0xffffffff
  166. /* This is the largest valid UTF/Unicode code point. */
  167. #define MAX_UTF_CODE_POINT 0x10ffff
  168. /* Compile-time positive error numbers (all except UTF errors, which are
  169. negative) start at this value. It should probably never be changed, in case
  170. some application is checking for specific numbers. There is a copy of this
  171. #define in pcre2posix.c (which now no longer includes this file). Ideally, a
  172. way of having a single definition should be found, but as the number is
  173. unlikely to change, this is not a pressing issue. The original reason for
  174. having a base other than 0 was to keep the absolute values of compile-time and
  175. run-time error numbers numerically different, but in the event the code does
  176. not rely on this. */
  177. #define COMPILE_ERROR_BASE 100
  178. /* The initial frames vector for remembering backtracking points in
  179. pcre2_match() is allocated on the system stack, of this size (bytes). The size
  180. must be a multiple of sizeof(PCRE2_SPTR) in all environments, so making it a
  181. multiple of 8 is best. Typical frame sizes are a few hundred bytes (it depends
  182. on the number of capturing parentheses) so 20KiB handles quite a few frames. A
  183. larger vector on the heap is obtained for patterns that need more frames. The
  184. maximum size of this can be limited. */
  185. #define START_FRAMES_SIZE 20480
  186. /* Similarly, for DFA matching, an initial internal workspace vector is
  187. allocated on the stack. */
  188. #define DFA_START_RWS_SIZE 30720
  189. /* Define the default BSR convention. */
  190. #ifdef BSR_ANYCRLF
  191. #define BSR_DEFAULT PCRE2_BSR_ANYCRLF
  192. #else
  193. #define BSR_DEFAULT PCRE2_BSR_UNICODE
  194. #endif
  195. /* ---------------- Basic UTF-8 macros ---------------- */
  196. /* These UTF-8 macros are always defined because they are used in pcre2test for
  197. handling wide characters in 16-bit and 32-bit modes, even if an 8-bit library
  198. is not supported. */
  199. /* Tests whether a UTF-8 code point needs extra bytes to decode. */
  200. #define HASUTF8EXTRALEN(c) ((c) >= 0xc0)
  201. /* The following macros were originally written in the form of loops that used
  202. data from the tables whose names start with PRIV(utf8_table). They were
  203. rewritten by a user so as not to use loops, because in some environments this
  204. gives a significant performance advantage, and it seems never to do any harm.
  205. */
  206. /* Base macro to pick up the remaining bytes of a UTF-8 character, not
  207. advancing the pointer. */
  208. #define GETUTF8(c, eptr) \
  209. { \
  210. if ((c & 0x20u) == 0) \
  211. c = ((c & 0x1fu) << 6) | (eptr[1] & 0x3fu); \
  212. else if ((c & 0x10u) == 0) \
  213. c = ((c & 0x0fu) << 12) | ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
  214. else if ((c & 0x08u) == 0) \
  215. c = ((c & 0x07u) << 18) | ((eptr[1] & 0x3fu) << 12) | \
  216. ((eptr[2] & 0x3fu) << 6) | (eptr[3] & 0x3fu); \
  217. else if ((c & 0x04u) == 0) \
  218. c = ((c & 0x03u) << 24) | ((eptr[1] & 0x3fu) << 18) | \
  219. ((eptr[2] & 0x3fu) << 12) | ((eptr[3] & 0x3fu) << 6) | \
  220. (eptr[4] & 0x3fu); \
  221. else \
  222. c = ((c & 0x01u) << 30) | ((eptr[1] & 0x3fu) << 24) | \
  223. ((eptr[2] & 0x3fu) << 18) | ((eptr[3] & 0x3fu) << 12) | \
  224. ((eptr[4] & 0x3fu) << 6) | (eptr[5] & 0x3fu); \
  225. }
  226. /* Base macro to pick up the remaining bytes of a UTF-8 character, advancing
  227. the pointer. */
  228. #define GETUTF8INC(c, eptr) \
  229. { \
  230. if ((c & 0x20u) == 0) \
  231. c = ((c & 0x1fu) << 6) | (*eptr++ & 0x3fu); \
  232. else if ((c & 0x10u) == 0) \
  233. { \
  234. c = ((c & 0x0fu) << 12) | ((*eptr & 0x3fu) << 6) | (eptr[1] & 0x3fu); \
  235. eptr += 2; \
  236. } \
  237. else if ((c & 0x08u) == 0) \
  238. { \
  239. c = ((c & 0x07u) << 18) | ((*eptr & 0x3fu) << 12) | \
  240. ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
  241. eptr += 3; \
  242. } \
  243. else if ((c & 0x04u) == 0) \
  244. { \
  245. c = ((c & 0x03u) << 24) | ((*eptr & 0x3fu) << 18) | \
  246. ((eptr[1] & 0x3fu) << 12) | ((eptr[2] & 0x3fu) << 6) | \
  247. (eptr[3] & 0x3fu); \
  248. eptr += 4; \
  249. } \
  250. else \
  251. { \
  252. c = ((c & 0x01u) << 30) | ((*eptr & 0x3fu) << 24) | \
  253. ((eptr[1] & 0x3fu) << 18) | ((eptr[2] & 0x3fu) << 12) | \
  254. ((eptr[3] & 0x3fu) << 6) | (eptr[4] & 0x3fu); \
  255. eptr += 5; \
  256. } \
  257. }
  258. /* Base macro to pick up the remaining bytes of a UTF-8 character, not
  259. advancing the pointer, incrementing the length. */
  260. #define GETUTF8LEN(c, eptr, len) \
  261. { \
  262. if ((c & 0x20u) == 0) \
  263. { \
  264. c = ((c & 0x1fu) << 6) | (eptr[1] & 0x3fu); \
  265. len++; \
  266. } \
  267. else if ((c & 0x10u) == 0) \
  268. { \
  269. c = ((c & 0x0fu) << 12) | ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
  270. len += 2; \
  271. } \
  272. else if ((c & 0x08u) == 0) \
  273. {\
  274. c = ((c & 0x07u) << 18) | ((eptr[1] & 0x3fu) << 12) | \
  275. ((eptr[2] & 0x3fu) << 6) | (eptr[3] & 0x3fu); \
  276. len += 3; \
  277. } \
  278. else if ((c & 0x04u) == 0) \
  279. { \
  280. c = ((c & 0x03u) << 24) | ((eptr[1] & 0x3fu) << 18) | \
  281. ((eptr[2] & 0x3fu) << 12) | ((eptr[3] & 0x3fu) << 6) | \
  282. (eptr[4] & 0x3fu); \
  283. len += 4; \
  284. } \
  285. else \
  286. {\
  287. c = ((c & 0x01u) << 30) | ((eptr[1] & 0x3fu) << 24) | \
  288. ((eptr[2] & 0x3fu) << 18) | ((eptr[3] & 0x3fu) << 12) | \
  289. ((eptr[4] & 0x3fu) << 6) | (eptr[5] & 0x3fu); \
  290. len += 5; \
  291. } \
  292. }
  293. /* --------------- Whitespace macros ---------------- */
  294. /* Tests for Unicode horizontal and vertical whitespace characters must check a
  295. number of different values. Using a switch statement for this generates the
  296. fastest code (no loop, no memory access), and there are several places in the
  297. interpreter code where this happens. In order to ensure that all the case lists
  298. remain in step, we use macros so that there is only one place where the lists
  299. are defined.
  300. These values are also required as lists in pcre2_compile.c when processing \h,
  301. \H, \v and \V in a character class. The lists are defined in pcre2_tables.c,
  302. but macros that define the values are here so that all the definitions are
  303. together. The lists must be in ascending character order, terminated by
  304. NOTACHAR (which is 0xffffffff).
  305. Any changes should ensure that the various macros are kept in step with each
  306. other. NOTE: The values also appear in pcre2_jit_compile.c. */
  307. /* -------------- ASCII/Unicode environments -------------- */
  308. #ifndef EBCDIC
  309. /* Character U+180E (Mongolian Vowel Separator) is not included in the list of
  310. spaces in the Unicode file PropList.txt, and Perl does not recognize it as a
  311. space. However, in many other sources it is listed as a space and has been in
  312. PCRE (both APIs) for a long time. */
  313. #define HSPACE_LIST \
  314. CHAR_HT, CHAR_SPACE, CHAR_NBSP, \
  315. 0x1680, 0x180e, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, \
  316. 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202f, 0x205f, 0x3000, \
  317. NOTACHAR
  318. #define HSPACE_MULTIBYTE_CASES \
  319. case 0x1680: /* OGHAM SPACE MARK */ \
  320. case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ \
  321. case 0x2000: /* EN QUAD */ \
  322. case 0x2001: /* EM QUAD */ \
  323. case 0x2002: /* EN SPACE */ \
  324. case 0x2003: /* EM SPACE */ \
  325. case 0x2004: /* THREE-PER-EM SPACE */ \
  326. case 0x2005: /* FOUR-PER-EM SPACE */ \
  327. case 0x2006: /* SIX-PER-EM SPACE */ \
  328. case 0x2007: /* FIGURE SPACE */ \
  329. case 0x2008: /* PUNCTUATION SPACE */ \
  330. case 0x2009: /* THIN SPACE */ \
  331. case 0x200A: /* HAIR SPACE */ \
  332. case 0x202f: /* NARROW NO-BREAK SPACE */ \
  333. case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ \
  334. case 0x3000 /* IDEOGRAPHIC SPACE */
  335. #define HSPACE_BYTE_CASES \
  336. case CHAR_HT: \
  337. case CHAR_SPACE: \
  338. case CHAR_NBSP
  339. #define HSPACE_CASES \
  340. HSPACE_BYTE_CASES: \
  341. HSPACE_MULTIBYTE_CASES
  342. #define VSPACE_LIST \
  343. CHAR_LF, CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, 0x2028, 0x2029, NOTACHAR
  344. #define VSPACE_MULTIBYTE_CASES \
  345. case 0x2028: /* LINE SEPARATOR */ \
  346. case 0x2029 /* PARAGRAPH SEPARATOR */
  347. #define VSPACE_BYTE_CASES \
  348. case CHAR_LF: \
  349. case CHAR_VT: \
  350. case CHAR_FF: \
  351. case CHAR_CR: \
  352. case CHAR_NEL
  353. #define VSPACE_CASES \
  354. VSPACE_BYTE_CASES: \
  355. VSPACE_MULTIBYTE_CASES
  356. /* -------------- EBCDIC environments -------------- */
  357. #else
  358. #define HSPACE_LIST CHAR_HT, CHAR_SPACE, CHAR_NBSP, NOTACHAR
  359. #define HSPACE_BYTE_CASES \
  360. case CHAR_HT: \
  361. case CHAR_SPACE: \
  362. case CHAR_NBSP
  363. #define HSPACE_CASES HSPACE_BYTE_CASES
  364. #ifdef EBCDIC_NL25
  365. #define VSPACE_LIST \
  366. CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, CHAR_LF, NOTACHAR
  367. #else
  368. #define VSPACE_LIST \
  369. CHAR_VT, CHAR_FF, CHAR_CR, CHAR_LF, CHAR_NEL, NOTACHAR
  370. #endif
  371. #define VSPACE_BYTE_CASES \
  372. case CHAR_LF: \
  373. case CHAR_VT: \
  374. case CHAR_FF: \
  375. case CHAR_CR: \
  376. case CHAR_NEL
  377. #define VSPACE_CASES VSPACE_BYTE_CASES
  378. #endif /* EBCDIC */
  379. /* -------------- End of whitespace macros -------------- */
  380. /* PCRE2 is able to support several different kinds of newline (CR, LF, CRLF,
  381. "any" and "anycrlf" at present). The following macros are used to package up
  382. testing for newlines. NLBLOCK, PSSTART, and PSEND are defined in the various
  383. modules to indicate in which datablock the parameters exist, and what the
  384. start/end of string field names are. */
  385. #define NLTYPE_FIXED 0 /* Newline is a fixed length string */
  386. #define NLTYPE_ANY 1 /* Newline is any Unicode line ending */
  387. #define NLTYPE_ANYCRLF 2 /* Newline is CR, LF, or CRLF */
  388. /* This macro checks for a newline at the given position */
  389. #define IS_NEWLINE(p) \
  390. ((NLBLOCK->nltype != NLTYPE_FIXED)? \
  391. ((p) < NLBLOCK->PSEND && \
  392. PRIV(is_newline)((p), NLBLOCK->nltype, NLBLOCK->PSEND, \
  393. &(NLBLOCK->nllen), utf)) \
  394. : \
  395. ((p) <= NLBLOCK->PSEND - NLBLOCK->nllen && \
  396. UCHAR21TEST(p) == NLBLOCK->nl[0] && \
  397. (NLBLOCK->nllen == 1 || UCHAR21TEST(p+1) == NLBLOCK->nl[1]) \
  398. ) \
  399. )
  400. /* This macro checks for a newline immediately preceding the given position */
  401. #define WAS_NEWLINE(p) \
  402. ((NLBLOCK->nltype != NLTYPE_FIXED)? \
  403. ((p) > NLBLOCK->PSSTART && \
  404. PRIV(was_newline)((p), NLBLOCK->nltype, NLBLOCK->PSSTART, \
  405. &(NLBLOCK->nllen), utf)) \
  406. : \
  407. ((p) >= NLBLOCK->PSSTART + NLBLOCK->nllen && \
  408. UCHAR21TEST(p - NLBLOCK->nllen) == NLBLOCK->nl[0] && \
  409. (NLBLOCK->nllen == 1 || UCHAR21TEST(p - NLBLOCK->nllen + 1) == NLBLOCK->nl[1]) \
  410. ) \
  411. )
  412. /* Private flags containing information about the compiled pattern. The first
  413. three must not be changed, because whichever is set is actually the number of
  414. bytes in a code unit in that mode. */
  415. #define PCRE2_MODE8 0x00000001 /* compiled in 8 bit mode */
  416. #define PCRE2_MODE16 0x00000002 /* compiled in 16 bit mode */
  417. #define PCRE2_MODE32 0x00000004 /* compiled in 32 bit mode */
  418. #define PCRE2_FIRSTSET 0x00000010 /* first_code unit is set */
  419. #define PCRE2_FIRSTCASELESS 0x00000020 /* caseless first code unit */
  420. #define PCRE2_FIRSTMAPSET 0x00000040 /* bitmap of first code units is set */
  421. #define PCRE2_LASTSET 0x00000080 /* last code unit is set */
  422. #define PCRE2_LASTCASELESS 0x00000100 /* caseless last code unit */
  423. #define PCRE2_STARTLINE 0x00000200 /* start after \n for multiline */
  424. #define PCRE2_JCHANGED 0x00000400 /* j option used in pattern */
  425. #define PCRE2_HASCRORLF 0x00000800 /* explicit \r or \n in pattern */
  426. #define PCRE2_HASTHEN 0x00001000 /* pattern contains (*THEN) */
  427. #define PCRE2_MATCH_EMPTY 0x00002000 /* pattern can match empty string */
  428. #define PCRE2_BSR_SET 0x00004000 /* BSR was set in the pattern */
  429. #define PCRE2_NL_SET 0x00008000 /* newline was set in the pattern */
  430. #define PCRE2_NOTEMPTY_SET 0x00010000 /* (*NOTEMPTY) used ) keep */
  431. #define PCRE2_NE_ATST_SET 0x00020000 /* (*NOTEMPTY_ATSTART) used) together */
  432. #define PCRE2_DEREF_TABLES 0x00040000 /* release character tables */
  433. #define PCRE2_NOJIT 0x00080000 /* (*NOJIT) used */
  434. #define PCRE2_HASBKPORX 0x00100000 /* contains \P, \p, or \X */
  435. #define PCRE2_DUPCAPUSED 0x00200000 /* contains (?| */
  436. #define PCRE2_HASBKC 0x00400000 /* contains \C */
  437. #define PCRE2_HASACCEPT 0x00800000 /* contains (*ACCEPT) */
  438. #define PCRE2_MODE_MASK (PCRE2_MODE8 | PCRE2_MODE16 | PCRE2_MODE32)
  439. /* Values for the matchedby field in a match data block. */
  440. enum { PCRE2_MATCHEDBY_INTERPRETER, /* pcre2_match() */
  441. PCRE2_MATCHEDBY_DFA_INTERPRETER, /* pcre2_dfa_match() */
  442. PCRE2_MATCHEDBY_JIT }; /* pcre2_jit_match() */
  443. /* Values for the flags field in a match data block. */
  444. #define PCRE2_MD_COPIED_SUBJECT 0x01u
  445. /* Magic number to provide a small check against being handed junk. */
  446. #define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */
  447. /* The maximum remaining length of subject we are prepared to search for a
  448. req_unit match from an anchored pattern. In 8-bit mode, memchr() is used and is
  449. much faster than the search loop that has to be used in 16-bit and 32-bit
  450. modes. */
  451. #if PCRE2_CODE_UNIT_WIDTH == 8
  452. #define REQ_CU_MAX 5000
  453. #else
  454. #define REQ_CU_MAX 2000
  455. #endif
  456. /* Offsets for the bitmap tables in the cbits set of tables. Each table
  457. contains a set of bits for a class map. Some classes are built by combining
  458. these tables. */
  459. #define cbit_space 0 /* [:space:] or \s */
  460. #define cbit_xdigit 32 /* [:xdigit:] */
  461. #define cbit_digit 64 /* [:digit:] or \d */
  462. #define cbit_upper 96 /* [:upper:] */
  463. #define cbit_lower 128 /* [:lower:] */
  464. #define cbit_word 160 /* [:word:] or \w */
  465. #define cbit_graph 192 /* [:graph:] */
  466. #define cbit_print 224 /* [:print:] */
  467. #define cbit_punct 256 /* [:punct:] */
  468. #define cbit_cntrl 288 /* [:cntrl:] */
  469. #define cbit_length 320 /* Length of the cbits table */
  470. /* Bit definitions for entries in the ctypes table. Do not change these values
  471. without checking pcre2_jit_compile.c, which has an assertion to ensure that
  472. ctype_word has the value 16. */
  473. #define ctype_space 0x01
  474. #define ctype_letter 0x02
  475. #define ctype_lcletter 0x04
  476. #define ctype_digit 0x08
  477. #define ctype_word 0x10 /* alphanumeric or '_' */
  478. /* Offsets of the various tables from the base tables pointer, and
  479. total length of the tables. */
  480. #define lcc_offset 0 /* Lower case */
  481. #define fcc_offset 256 /* Flip case */
  482. #define cbits_offset 512 /* Character classes */
  483. #define ctypes_offset (cbits_offset + cbit_length) /* Character types */
  484. #define TABLES_LENGTH (ctypes_offset + 256)
  485. /* -------------------- Character and string names ------------------------ */
  486. /* If PCRE2 is to support UTF-8 on EBCDIC platforms, we cannot use normal
  487. character constants like '*' because the compiler would emit their EBCDIC code,
  488. which is different from their ASCII/UTF-8 code. Instead we define macros for
  489. the characters so that they always use the ASCII/UTF-8 code when UTF-8 support
  490. is enabled. When UTF-8 support is not enabled, the definitions use character
  491. literals. Both character and string versions of each character are needed, and
  492. there are some longer strings as well.
  493. This means that, on EBCDIC platforms, the PCRE2 library can handle either
  494. EBCDIC, or UTF-8, but not both. To support both in the same compiled library
  495. would need different lookups depending on whether PCRE2_UTF was set or not.
  496. This would make it impossible to use characters in switch/case statements,
  497. which would reduce performance. For a theoretical use (which nobody has asked
  498. for) in a minority area (EBCDIC platforms), this is not sensible. Any
  499. application that did need both could compile two versions of the library, using
  500. macros to give the functions distinct names. */
  501. #ifndef SUPPORT_UNICODE
  502. /* UTF-8 support is not enabled; use the platform-dependent character literals
  503. so that PCRE2 works in both ASCII and EBCDIC environments, but only in non-UTF
  504. mode. Newline characters are problematic in EBCDIC. Though it has CR and LF
  505. characters, a common practice has been to use its NL (0x15) character as the
  506. line terminator in C-like processing environments. However, sometimes the LF
  507. (0x25) character is used instead, according to this Unicode document:
  508. http://unicode.org/standard/reports/tr13/tr13-5.html
  509. PCRE2 defaults EBCDIC NL to 0x15, but has a build-time option to select 0x25
  510. instead. Whichever is *not* chosen is defined as NEL.
  511. In both ASCII and EBCDIC environments, CHAR_NL and CHAR_LF are synonyms for the
  512. same code point. */
  513. #ifdef EBCDIC
  514. #ifndef EBCDIC_NL25
  515. #define CHAR_NL '\x15'
  516. #define CHAR_NEL '\x25'
  517. #define STR_NL "\x15"
  518. #define STR_NEL "\x25"
  519. #else
  520. #define CHAR_NL '\x25'
  521. #define CHAR_NEL '\x15'
  522. #define STR_NL "\x25"
  523. #define STR_NEL "\x15"
  524. #endif
  525. #define CHAR_LF CHAR_NL
  526. #define STR_LF STR_NL
  527. #define CHAR_ESC '\047'
  528. #define CHAR_DEL '\007'
  529. #define CHAR_NBSP ((unsigned char)'\x41')
  530. #define STR_ESC "\047"
  531. #define STR_DEL "\007"
  532. #else /* Not EBCDIC */
  533. /* In ASCII/Unicode, linefeed is '\n' and we equate this to NL for
  534. compatibility. NEL is the Unicode newline character; make sure it is
  535. a positive value. */
  536. #define CHAR_LF '\n'
  537. #define CHAR_NL CHAR_LF
  538. #define CHAR_NEL ((unsigned char)'\x85')
  539. #define CHAR_ESC '\033'
  540. #define CHAR_DEL '\177'
  541. #define CHAR_NBSP ((unsigned char)'\xa0')
  542. #define STR_LF "\n"
  543. #define STR_NL STR_LF
  544. #define STR_NEL "\x85"
  545. #define STR_ESC "\033"
  546. #define STR_DEL "\177"
  547. #endif /* EBCDIC */
  548. /* The remaining definitions work in both environments. */
  549. #define CHAR_NUL '\0'
  550. #define CHAR_HT '\t'
  551. #define CHAR_VT '\v'
  552. #define CHAR_FF '\f'
  553. #define CHAR_CR '\r'
  554. #define CHAR_BS '\b'
  555. #define CHAR_BEL '\a'
  556. #define CHAR_SPACE ' '
  557. #define CHAR_EXCLAMATION_MARK '!'
  558. #define CHAR_QUOTATION_MARK '"'
  559. #define CHAR_NUMBER_SIGN '#'
  560. #define CHAR_DOLLAR_SIGN '$'
  561. #define CHAR_PERCENT_SIGN '%'
  562. #define CHAR_AMPERSAND '&'
  563. #define CHAR_APOSTROPHE '\''
  564. #define CHAR_LEFT_PARENTHESIS '('
  565. #define CHAR_RIGHT_PARENTHESIS ')'
  566. #define CHAR_ASTERISK '*'
  567. #define CHAR_PLUS '+'
  568. #define CHAR_COMMA ','
  569. #define CHAR_MINUS '-'
  570. #define CHAR_DOT '.'
  571. #define CHAR_SLASH '/'
  572. #define CHAR_0 '0'
  573. #define CHAR_1 '1'
  574. #define CHAR_2 '2'
  575. #define CHAR_3 '3'
  576. #define CHAR_4 '4'
  577. #define CHAR_5 '5'
  578. #define CHAR_6 '6'
  579. #define CHAR_7 '7'
  580. #define CHAR_8 '8'
  581. #define CHAR_9 '9'
  582. #define CHAR_COLON ':'
  583. #define CHAR_SEMICOLON ';'
  584. #define CHAR_LESS_THAN_SIGN '<'
  585. #define CHAR_EQUALS_SIGN '='
  586. #define CHAR_GREATER_THAN_SIGN '>'
  587. #define CHAR_QUESTION_MARK '?'
  588. #define CHAR_COMMERCIAL_AT '@'
  589. #define CHAR_A 'A'
  590. #define CHAR_B 'B'
  591. #define CHAR_C 'C'
  592. #define CHAR_D 'D'
  593. #define CHAR_E 'E'
  594. #define CHAR_F 'F'
  595. #define CHAR_G 'G'
  596. #define CHAR_H 'H'
  597. #define CHAR_I 'I'
  598. #define CHAR_J 'J'
  599. #define CHAR_K 'K'
  600. #define CHAR_L 'L'
  601. #define CHAR_M 'M'
  602. #define CHAR_N 'N'
  603. #define CHAR_O 'O'
  604. #define CHAR_P 'P'
  605. #define CHAR_Q 'Q'
  606. #define CHAR_R 'R'
  607. #define CHAR_S 'S'
  608. #define CHAR_T 'T'
  609. #define CHAR_U 'U'
  610. #define CHAR_V 'V'
  611. #define CHAR_W 'W'
  612. #define CHAR_X 'X'
  613. #define CHAR_Y 'Y'
  614. #define CHAR_Z 'Z'
  615. #define CHAR_LEFT_SQUARE_BRACKET '['
  616. #define CHAR_BACKSLASH '\\'
  617. #define CHAR_RIGHT_SQUARE_BRACKET ']'
  618. #define CHAR_CIRCUMFLEX_ACCENT '^'
  619. #define CHAR_UNDERSCORE '_'
  620. #define CHAR_GRAVE_ACCENT '`'
  621. #define CHAR_a 'a'
  622. #define CHAR_b 'b'
  623. #define CHAR_c 'c'
  624. #define CHAR_d 'd'
  625. #define CHAR_e 'e'
  626. #define CHAR_f 'f'
  627. #define CHAR_g 'g'
  628. #define CHAR_h 'h'
  629. #define CHAR_i 'i'
  630. #define CHAR_j 'j'
  631. #define CHAR_k 'k'
  632. #define CHAR_l 'l'
  633. #define CHAR_m 'm'
  634. #define CHAR_n 'n'
  635. #define CHAR_o 'o'
  636. #define CHAR_p 'p'
  637. #define CHAR_q 'q'
  638. #define CHAR_r 'r'
  639. #define CHAR_s 's'
  640. #define CHAR_t 't'
  641. #define CHAR_u 'u'
  642. #define CHAR_v 'v'
  643. #define CHAR_w 'w'
  644. #define CHAR_x 'x'
  645. #define CHAR_y 'y'
  646. #define CHAR_z 'z'
  647. #define CHAR_LEFT_CURLY_BRACKET '{'
  648. #define CHAR_VERTICAL_LINE '|'
  649. #define CHAR_RIGHT_CURLY_BRACKET '}'
  650. #define CHAR_TILDE '~'
  651. #define STR_HT "\t"
  652. #define STR_VT "\v"
  653. #define STR_FF "\f"
  654. #define STR_CR "\r"
  655. #define STR_BS "\b"
  656. #define STR_BEL "\a"
  657. #define STR_SPACE " "
  658. #define STR_EXCLAMATION_MARK "!"
  659. #define STR_QUOTATION_MARK "\""
  660. #define STR_NUMBER_SIGN "#"
  661. #define STR_DOLLAR_SIGN "$"
  662. #define STR_PERCENT_SIGN "%"
  663. #define STR_AMPERSAND "&"
  664. #define STR_APOSTROPHE "'"
  665. #define STR_LEFT_PARENTHESIS "("
  666. #define STR_RIGHT_PARENTHESIS ")"
  667. #define STR_ASTERISK "*"
  668. #define STR_PLUS "+"
  669. #define STR_COMMA ","
  670. #define STR_MINUS "-"
  671. #define STR_DOT "."
  672. #define STR_SLASH "/"
  673. #define STR_0 "0"
  674. #define STR_1 "1"
  675. #define STR_2 "2"
  676. #define STR_3 "3"
  677. #define STR_4 "4"
  678. #define STR_5 "5"
  679. #define STR_6 "6"
  680. #define STR_7 "7"
  681. #define STR_8 "8"
  682. #define STR_9 "9"
  683. #define STR_COLON ":"
  684. #define STR_SEMICOLON ";"
  685. #define STR_LESS_THAN_SIGN "<"
  686. #define STR_EQUALS_SIGN "="
  687. #define STR_GREATER_THAN_SIGN ">"
  688. #define STR_QUESTION_MARK "?"
  689. #define STR_COMMERCIAL_AT "@"
  690. #define STR_A "A"
  691. #define STR_B "B"
  692. #define STR_C "C"
  693. #define STR_D "D"
  694. #define STR_E "E"
  695. #define STR_F "F"
  696. #define STR_G "G"
  697. #define STR_H "H"
  698. #define STR_I "I"
  699. #define STR_J "J"
  700. #define STR_K "K"
  701. #define STR_L "L"
  702. #define STR_M "M"
  703. #define STR_N "N"
  704. #define STR_O "O"
  705. #define STR_P "P"
  706. #define STR_Q "Q"
  707. #define STR_R "R"
  708. #define STR_S "S"
  709. #define STR_T "T"
  710. #define STR_U "U"
  711. #define STR_V "V"
  712. #define STR_W "W"
  713. #define STR_X "X"
  714. #define STR_Y "Y"
  715. #define STR_Z "Z"
  716. #define STR_LEFT_SQUARE_BRACKET "["
  717. #define STR_BACKSLASH "\\"
  718. #define STR_RIGHT_SQUARE_BRACKET "]"
  719. #define STR_CIRCUMFLEX_ACCENT "^"
  720. #define STR_UNDERSCORE "_"
  721. #define STR_GRAVE_ACCENT "`"
  722. #define STR_a "a"
  723. #define STR_b "b"
  724. #define STR_c "c"
  725. #define STR_d "d"
  726. #define STR_e "e"
  727. #define STR_f "f"
  728. #define STR_g "g"
  729. #define STR_h "h"
  730. #define STR_i "i"
  731. #define STR_j "j"
  732. #define STR_k "k"
  733. #define STR_l "l"
  734. #define STR_m "m"
  735. #define STR_n "n"
  736. #define STR_o "o"
  737. #define STR_p "p"
  738. #define STR_q "q"
  739. #define STR_r "r"
  740. #define STR_s "s"
  741. #define STR_t "t"
  742. #define STR_u "u"
  743. #define STR_v "v"
  744. #define STR_w "w"
  745. #define STR_x "x"
  746. #define STR_y "y"
  747. #define STR_z "z"
  748. #define STR_LEFT_CURLY_BRACKET "{"
  749. #define STR_VERTICAL_LINE "|"
  750. #define STR_RIGHT_CURLY_BRACKET "}"
  751. #define STR_TILDE "~"
  752. #define STRING_ACCEPT0 "ACCEPT\0"
  753. #define STRING_COMMIT0 "COMMIT\0"
  754. #define STRING_F0 "F\0"
  755. #define STRING_FAIL0 "FAIL\0"
  756. #define STRING_MARK0 "MARK\0"
  757. #define STRING_PRUNE0 "PRUNE\0"
  758. #define STRING_SKIP0 "SKIP\0"
  759. #define STRING_THEN "THEN"
  760. #define STRING_atomic0 "atomic\0"
  761. #define STRING_pla0 "pla\0"
  762. #define STRING_plb0 "plb\0"
  763. #define STRING_napla0 "napla\0"
  764. #define STRING_naplb0 "naplb\0"
  765. #define STRING_nla0 "nla\0"
  766. #define STRING_nlb0 "nlb\0"
  767. #define STRING_sr0 "sr\0"
  768. #define STRING_asr0 "asr\0"
  769. #define STRING_positive_lookahead0 "positive_lookahead\0"
  770. #define STRING_positive_lookbehind0 "positive_lookbehind\0"
  771. #define STRING_non_atomic_positive_lookahead0 "non_atomic_positive_lookahead\0"
  772. #define STRING_non_atomic_positive_lookbehind0 "non_atomic_positive_lookbehind\0"
  773. #define STRING_negative_lookahead0 "negative_lookahead\0"
  774. #define STRING_negative_lookbehind0 "negative_lookbehind\0"
  775. #define STRING_script_run0 "script_run\0"
  776. #define STRING_atomic_script_run "atomic_script_run"
  777. #define STRING_alpha0 "alpha\0"
  778. #define STRING_lower0 "lower\0"
  779. #define STRING_upper0 "upper\0"
  780. #define STRING_alnum0 "alnum\0"
  781. #define STRING_ascii0 "ascii\0"
  782. #define STRING_blank0 "blank\0"
  783. #define STRING_cntrl0 "cntrl\0"
  784. #define STRING_digit0 "digit\0"
  785. #define STRING_graph0 "graph\0"
  786. #define STRING_print0 "print\0"
  787. #define STRING_punct0 "punct\0"
  788. #define STRING_space0 "space\0"
  789. #define STRING_word0 "word\0"
  790. #define STRING_xdigit "xdigit"
  791. #define STRING_DEFINE "DEFINE"
  792. #define STRING_VERSION "VERSION"
  793. #define STRING_WEIRD_STARTWORD "[:<:]]"
  794. #define STRING_WEIRD_ENDWORD "[:>:]]"
  795. #define STRING_CR_RIGHTPAR "CR)"
  796. #define STRING_LF_RIGHTPAR "LF)"
  797. #define STRING_CRLF_RIGHTPAR "CRLF)"
  798. #define STRING_ANY_RIGHTPAR "ANY)"
  799. #define STRING_ANYCRLF_RIGHTPAR "ANYCRLF)"
  800. #define STRING_NUL_RIGHTPAR "NUL)"
  801. #define STRING_BSR_ANYCRLF_RIGHTPAR "BSR_ANYCRLF)"
  802. #define STRING_BSR_UNICODE_RIGHTPAR "BSR_UNICODE)"
  803. #define STRING_UTF8_RIGHTPAR "UTF8)"
  804. #define STRING_UTF16_RIGHTPAR "UTF16)"
  805. #define STRING_UTF32_RIGHTPAR "UTF32)"
  806. #define STRING_UTF_RIGHTPAR "UTF)"
  807. #define STRING_UCP_RIGHTPAR "UCP)"
  808. #define STRING_NO_AUTO_POSSESS_RIGHTPAR "NO_AUTO_POSSESS)"
  809. #define STRING_NO_DOTSTAR_ANCHOR_RIGHTPAR "NO_DOTSTAR_ANCHOR)"
  810. #define STRING_NO_JIT_RIGHTPAR "NO_JIT)"
  811. #define STRING_NO_START_OPT_RIGHTPAR "NO_START_OPT)"
  812. #define STRING_NOTEMPTY_RIGHTPAR "NOTEMPTY)"
  813. #define STRING_NOTEMPTY_ATSTART_RIGHTPAR "NOTEMPTY_ATSTART)"
  814. #define STRING_LIMIT_HEAP_EQ "LIMIT_HEAP="
  815. #define STRING_LIMIT_MATCH_EQ "LIMIT_MATCH="
  816. #define STRING_LIMIT_DEPTH_EQ "LIMIT_DEPTH="
  817. #define STRING_LIMIT_RECURSION_EQ "LIMIT_RECURSION="
  818. #define STRING_MARK "MARK"
  819. #else /* SUPPORT_UNICODE */
  820. /* UTF-8 support is enabled; always use UTF-8 (=ASCII) character codes. This
  821. works in both modes non-EBCDIC platforms, and on EBCDIC platforms in UTF-8 mode
  822. only. */
  823. #define CHAR_HT '\011'
  824. #define CHAR_VT '\013'
  825. #define CHAR_FF '\014'
  826. #define CHAR_CR '\015'
  827. #define CHAR_LF '\012'
  828. #define CHAR_NL CHAR_LF
  829. #define CHAR_NEL ((unsigned char)'\x85')
  830. #define CHAR_BS '\010'
  831. #define CHAR_BEL '\007'
  832. #define CHAR_ESC '\033'
  833. #define CHAR_DEL '\177'
  834. #define CHAR_NUL '\0'
  835. #define CHAR_SPACE '\040'
  836. #define CHAR_EXCLAMATION_MARK '\041'
  837. #define CHAR_QUOTATION_MARK '\042'
  838. #define CHAR_NUMBER_SIGN '\043'
  839. #define CHAR_DOLLAR_SIGN '\044'
  840. #define CHAR_PERCENT_SIGN '\045'
  841. #define CHAR_AMPERSAND '\046'
  842. #define CHAR_APOSTROPHE '\047'
  843. #define CHAR_LEFT_PARENTHESIS '\050'
  844. #define CHAR_RIGHT_PARENTHESIS '\051'
  845. #define CHAR_ASTERISK '\052'
  846. #define CHAR_PLUS '\053'
  847. #define CHAR_COMMA '\054'
  848. #define CHAR_MINUS '\055'
  849. #define CHAR_DOT '\056'
  850. #define CHAR_SLASH '\057'
  851. #define CHAR_0 '\060'
  852. #define CHAR_1 '\061'
  853. #define CHAR_2 '\062'
  854. #define CHAR_3 '\063'
  855. #define CHAR_4 '\064'
  856. #define CHAR_5 '\065'
  857. #define CHAR_6 '\066'
  858. #define CHAR_7 '\067'
  859. #define CHAR_8 '\070'
  860. #define CHAR_9 '\071'
  861. #define CHAR_COLON '\072'
  862. #define CHAR_SEMICOLON '\073'
  863. #define CHAR_LESS_THAN_SIGN '\074'
  864. #define CHAR_EQUALS_SIGN '\075'
  865. #define CHAR_GREATER_THAN_SIGN '\076'
  866. #define CHAR_QUESTION_MARK '\077'
  867. #define CHAR_COMMERCIAL_AT '\100'
  868. #define CHAR_A '\101'
  869. #define CHAR_B '\102'
  870. #define CHAR_C '\103'
  871. #define CHAR_D '\104'
  872. #define CHAR_E '\105'
  873. #define CHAR_F '\106'
  874. #define CHAR_G '\107'
  875. #define CHAR_H '\110'
  876. #define CHAR_I '\111'
  877. #define CHAR_J '\112'
  878. #define CHAR_K '\113'
  879. #define CHAR_L '\114'
  880. #define CHAR_M '\115'
  881. #define CHAR_N '\116'
  882. #define CHAR_O '\117'
  883. #define CHAR_P '\120'
  884. #define CHAR_Q '\121'
  885. #define CHAR_R '\122'
  886. #define CHAR_S '\123'
  887. #define CHAR_T '\124'
  888. #define CHAR_U '\125'
  889. #define CHAR_V '\126'
  890. #define CHAR_W '\127'
  891. #define CHAR_X '\130'
  892. #define CHAR_Y '\131'
  893. #define CHAR_Z '\132'
  894. #define CHAR_LEFT_SQUARE_BRACKET '\133'
  895. #define CHAR_BACKSLASH '\134'
  896. #define CHAR_RIGHT_SQUARE_BRACKET '\135'
  897. #define CHAR_CIRCUMFLEX_ACCENT '\136'
  898. #define CHAR_UNDERSCORE '\137'
  899. #define CHAR_GRAVE_ACCENT '\140'
  900. #define CHAR_a '\141'
  901. #define CHAR_b '\142'
  902. #define CHAR_c '\143'
  903. #define CHAR_d '\144'
  904. #define CHAR_e '\145'
  905. #define CHAR_f '\146'
  906. #define CHAR_g '\147'
  907. #define CHAR_h '\150'
  908. #define CHAR_i '\151'
  909. #define CHAR_j '\152'
  910. #define CHAR_k '\153'
  911. #define CHAR_l '\154'
  912. #define CHAR_m '\155'
  913. #define CHAR_n '\156'
  914. #define CHAR_o '\157'
  915. #define CHAR_p '\160'
  916. #define CHAR_q '\161'
  917. #define CHAR_r '\162'
  918. #define CHAR_s '\163'
  919. #define CHAR_t '\164'
  920. #define CHAR_u '\165'
  921. #define CHAR_v '\166'
  922. #define CHAR_w '\167'
  923. #define CHAR_x '\170'
  924. #define CHAR_y '\171'
  925. #define CHAR_z '\172'
  926. #define CHAR_LEFT_CURLY_BRACKET '\173'
  927. #define CHAR_VERTICAL_LINE '\174'
  928. #define CHAR_RIGHT_CURLY_BRACKET '\175'
  929. #define CHAR_TILDE '\176'
  930. #define CHAR_NBSP ((unsigned char)'\xa0')
  931. #define STR_HT "\011"
  932. #define STR_VT "\013"
  933. #define STR_FF "\014"
  934. #define STR_CR "\015"
  935. #define STR_NL "\012"
  936. #define STR_BS "\010"
  937. #define STR_BEL "\007"
  938. #define STR_ESC "\033"
  939. #define STR_DEL "\177"
  940. #define STR_SPACE "\040"
  941. #define STR_EXCLAMATION_MARK "\041"
  942. #define STR_QUOTATION_MARK "\042"
  943. #define STR_NUMBER_SIGN "\043"
  944. #define STR_DOLLAR_SIGN "\044"
  945. #define STR_PERCENT_SIGN "\045"
  946. #define STR_AMPERSAND "\046"
  947. #define STR_APOSTROPHE "\047"
  948. #define STR_LEFT_PARENTHESIS "\050"
  949. #define STR_RIGHT_PARENTHESIS "\051"
  950. #define STR_ASTERISK "\052"
  951. #define STR_PLUS "\053"
  952. #define STR_COMMA "\054"
  953. #define STR_MINUS "\055"
  954. #define STR_DOT "\056"
  955. #define STR_SLASH "\057"
  956. #define STR_0 "\060"
  957. #define STR_1 "\061"
  958. #define STR_2 "\062"
  959. #define STR_3 "\063"
  960. #define STR_4 "\064"
  961. #define STR_5 "\065"
  962. #define STR_6 "\066"
  963. #define STR_7 "\067"
  964. #define STR_8 "\070"
  965. #define STR_9 "\071"
  966. #define STR_COLON "\072"
  967. #define STR_SEMICOLON "\073"
  968. #define STR_LESS_THAN_SIGN "\074"
  969. #define STR_EQUALS_SIGN "\075"
  970. #define STR_GREATER_THAN_SIGN "\076"
  971. #define STR_QUESTION_MARK "\077"
  972. #define STR_COMMERCIAL_AT "\100"
  973. #define STR_A "\101"
  974. #define STR_B "\102"
  975. #define STR_C "\103"
  976. #define STR_D "\104"
  977. #define STR_E "\105"
  978. #define STR_F "\106"
  979. #define STR_G "\107"
  980. #define STR_H "\110"
  981. #define STR_I "\111"
  982. #define STR_J "\112"
  983. #define STR_K "\113"
  984. #define STR_L "\114"
  985. #define STR_M "\115"
  986. #define STR_N "\116"
  987. #define STR_O "\117"
  988. #define STR_P "\120"
  989. #define STR_Q "\121"
  990. #define STR_R "\122"
  991. #define STR_S "\123"
  992. #define STR_T "\124"
  993. #define STR_U "\125"
  994. #define STR_V "\126"
  995. #define STR_W "\127"
  996. #define STR_X "\130"
  997. #define STR_Y "\131"
  998. #define STR_Z "\132"
  999. #define STR_LEFT_SQUARE_BRACKET "\133"
  1000. #define STR_BACKSLASH "\134"
  1001. #define STR_RIGHT_SQUARE_BRACKET "\135"
  1002. #define STR_CIRCUMFLEX_ACCENT "\136"
  1003. #define STR_UNDERSCORE "\137"
  1004. #define STR_GRAVE_ACCENT "\140"
  1005. #define STR_a "\141"
  1006. #define STR_b "\142"
  1007. #define STR_c "\143"
  1008. #define STR_d "\144"
  1009. #define STR_e "\145"
  1010. #define STR_f "\146"
  1011. #define STR_g "\147"
  1012. #define STR_h "\150"
  1013. #define STR_i "\151"
  1014. #define STR_j "\152"
  1015. #define STR_k "\153"
  1016. #define STR_l "\154"
  1017. #define STR_m "\155"
  1018. #define STR_n "\156"
  1019. #define STR_o "\157"
  1020. #define STR_p "\160"
  1021. #define STR_q "\161"
  1022. #define STR_r "\162"
  1023. #define STR_s "\163"
  1024. #define STR_t "\164"
  1025. #define STR_u "\165"
  1026. #define STR_v "\166"
  1027. #define STR_w "\167"
  1028. #define STR_x "\170"
  1029. #define STR_y "\171"
  1030. #define STR_z "\172"
  1031. #define STR_LEFT_CURLY_BRACKET "\173"
  1032. #define STR_VERTICAL_LINE "\174"
  1033. #define STR_RIGHT_CURLY_BRACKET "\175"
  1034. #define STR_TILDE "\176"
  1035. #define STRING_ACCEPT0 STR_A STR_C STR_C STR_E STR_P STR_T "\0"
  1036. #define STRING_COMMIT0 STR_C STR_O STR_M STR_M STR_I STR_T "\0"
  1037. #define STRING_F0 STR_F "\0"
  1038. #define STRING_FAIL0 STR_F STR_A STR_I STR_L "\0"
  1039. #define STRING_MARK0 STR_M STR_A STR_R STR_K "\0"
  1040. #define STRING_PRUNE0 STR_P STR_R STR_U STR_N STR_E "\0"
  1041. #define STRING_SKIP0 STR_S STR_K STR_I STR_P "\0"
  1042. #define STRING_THEN STR_T STR_H STR_E STR_N
  1043. #define STRING_atomic0 STR_a STR_t STR_o STR_m STR_i STR_c "\0"
  1044. #define STRING_pla0 STR_p STR_l STR_a "\0"
  1045. #define STRING_plb0 STR_p STR_l STR_b "\0"
  1046. #define STRING_napla0 STR_n STR_a STR_p STR_l STR_a "\0"
  1047. #define STRING_naplb0 STR_n STR_a STR_p STR_l STR_b "\0"
  1048. #define STRING_nla0 STR_n STR_l STR_a "\0"
  1049. #define STRING_nlb0 STR_n STR_l STR_b "\0"
  1050. #define STRING_sr0 STR_s STR_r "\0"
  1051. #define STRING_asr0 STR_a STR_s STR_r "\0"
  1052. #define STRING_positive_lookahead0 STR_p STR_o STR_s STR_i STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_a STR_h STR_e STR_a STR_d "\0"
  1053. #define STRING_positive_lookbehind0 STR_p STR_o STR_s STR_i STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_b STR_e STR_h STR_i STR_n STR_d "\0"
  1054. #define STRING_non_atomic_positive_lookahead0 STR_n STR_o STR_n STR_UNDERSCORE STR_a STR_t STR_o STR_m STR_i STR_c STR_UNDERSCORE STR_p STR_o STR_s STR_i STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_a STR_h STR_e STR_a STR_d "\0"
  1055. #define STRING_non_atomic_positive_lookbehind0 STR_n STR_o STR_n STR_UNDERSCORE STR_a STR_t STR_o STR_m STR_i STR_c STR_UNDERSCORE STR_p STR_o STR_s STR_i STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_b STR_e STR_h STR_i STR_n STR_d "\0"
  1056. #define STRING_negative_lookahead0 STR_n STR_e STR_g STR_a STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_a STR_h STR_e STR_a STR_d "\0"
  1057. #define STRING_negative_lookbehind0 STR_n STR_e STR_g STR_a STR_t STR_i STR_v STR_e STR_UNDERSCORE STR_l STR_o STR_o STR_k STR_b STR_e STR_h STR_i STR_n STR_d "\0"
  1058. #define STRING_script_run0 STR_s STR_c STR_r STR_i STR_p STR_t STR_UNDERSCORE STR_r STR_u STR_n "\0"
  1059. #define STRING_atomic_script_run STR_a STR_t STR_o STR_m STR_i STR_c STR_UNDERSCORE STR_s STR_c STR_r STR_i STR_p STR_t STR_UNDERSCORE STR_r STR_u STR_n
  1060. #define STRING_alpha0 STR_a STR_l STR_p STR_h STR_a "\0"
  1061. #define STRING_lower0 STR_l STR_o STR_w STR_e STR_r "\0"
  1062. #define STRING_upper0 STR_u STR_p STR_p STR_e STR_r "\0"
  1063. #define STRING_alnum0 STR_a STR_l STR_n STR_u STR_m "\0"
  1064. #define STRING_ascii0 STR_a STR_s STR_c STR_i STR_i "\0"
  1065. #define STRING_blank0 STR_b STR_l STR_a STR_n STR_k "\0"
  1066. #define STRING_cntrl0 STR_c STR_n STR_t STR_r STR_l "\0"
  1067. #define STRING_digit0 STR_d STR_i STR_g STR_i STR_t "\0"
  1068. #define STRING_graph0 STR_g STR_r STR_a STR_p STR_h "\0"
  1069. #define STRING_print0 STR_p STR_r STR_i STR_n STR_t "\0"
  1070. #define STRING_punct0 STR_p STR_u STR_n STR_c STR_t "\0"
  1071. #define STRING_space0 STR_s STR_p STR_a STR_c STR_e "\0"
  1072. #define STRING_word0 STR_w STR_o STR_r STR_d "\0"
  1073. #define STRING_xdigit STR_x STR_d STR_i STR_g STR_i STR_t
  1074. #define STRING_DEFINE STR_D STR_E STR_F STR_I STR_N STR_E
  1075. #define STRING_VERSION STR_V STR_E STR_R STR_S STR_I STR_O STR_N
  1076. #define STRING_WEIRD_STARTWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_LESS_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET
  1077. #define STRING_WEIRD_ENDWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_GREATER_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET
  1078. #define STRING_CR_RIGHTPAR STR_C STR_R STR_RIGHT_PARENTHESIS
  1079. #define STRING_LF_RIGHTPAR STR_L STR_F STR_RIGHT_PARENTHESIS
  1080. #define STRING_CRLF_RIGHTPAR STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
  1081. #define STRING_ANY_RIGHTPAR STR_A STR_N STR_Y STR_RIGHT_PARENTHESIS
  1082. #define STRING_ANYCRLF_RIGHTPAR STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
  1083. #define STRING_NUL_RIGHTPAR STR_N STR_U STR_L STR_RIGHT_PARENTHESIS
  1084. #define STRING_BSR_ANYCRLF_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
  1085. #define STRING_BSR_UNICODE_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_U STR_N STR_I STR_C STR_O STR_D STR_E STR_RIGHT_PARENTHESIS
  1086. #define STRING_UTF8_RIGHTPAR STR_U STR_T STR_F STR_8 STR_RIGHT_PARENTHESIS
  1087. #define STRING_UTF16_RIGHTPAR STR_U STR_T STR_F STR_1 STR_6 STR_RIGHT_PARENTHESIS
  1088. #define STRING_UTF32_RIGHTPAR STR_U STR_T STR_F STR_3 STR_2 STR_RIGHT_PARENTHESIS
  1089. #define STRING_UTF_RIGHTPAR STR_U STR_T STR_F STR_RIGHT_PARENTHESIS
  1090. #define STRING_UCP_RIGHTPAR STR_U STR_C STR_P STR_RIGHT_PARENTHESIS
  1091. #define STRING_NO_AUTO_POSSESS_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_A STR_U STR_T STR_O STR_UNDERSCORE STR_P STR_O STR_S STR_S STR_E STR_S STR_S STR_RIGHT_PARENTHESIS
  1092. #define STRING_NO_DOTSTAR_ANCHOR_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_D STR_O STR_T STR_S STR_T STR_A STR_R STR_UNDERSCORE STR_A STR_N STR_C STR_H STR_O STR_R STR_RIGHT_PARENTHESIS
  1093. #define STRING_NO_JIT_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_J STR_I STR_T STR_RIGHT_PARENTHESIS
  1094. #define STRING_NO_START_OPT_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_S STR_T STR_A STR_R STR_T STR_UNDERSCORE STR_O STR_P STR_T STR_RIGHT_PARENTHESIS
  1095. #define STRING_NOTEMPTY_RIGHTPAR STR_N STR_O STR_T STR_E STR_M STR_P STR_T STR_Y STR_RIGHT_PARENTHESIS
  1096. #define STRING_NOTEMPTY_ATSTART_RIGHTPAR STR_N STR_O STR_T STR_E STR_M STR_P STR_T STR_Y STR_UNDERSCORE STR_A STR_T STR_S STR_T STR_A STR_R STR_T STR_RIGHT_PARENTHESIS
  1097. #define STRING_LIMIT_HEAP_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_H STR_E STR_A STR_P STR_EQUALS_SIGN
  1098. #define STRING_LIMIT_MATCH_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_M STR_A STR_T STR_C STR_H STR_EQUALS_SIGN
  1099. #define STRING_LIMIT_DEPTH_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_D STR_E STR_P STR_T STR_H STR_EQUALS_SIGN
  1100. #define STRING_LIMIT_RECURSION_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_R STR_E STR_C STR_U STR_R STR_S STR_I STR_O STR_N STR_EQUALS_SIGN
  1101. #define STRING_MARK STR_M STR_A STR_R STR_K
  1102. #endif /* SUPPORT_UNICODE */
  1103. /* -------------------- End of character and string names -------------------*/
  1104. /* -------------------- Definitions for compiled patterns -------------------*/
  1105. /* Codes for different types of Unicode property */
  1106. #define PT_ANY 0 /* Any property - matches all chars */
  1107. #define PT_LAMP 1 /* L& - the union of Lu, Ll, Lt */
  1108. #define PT_GC 2 /* Specified general characteristic (e.g. L) */
  1109. #define PT_PC 3 /* Specified particular characteristic (e.g. Lu) */
  1110. #define PT_SC 4 /* Script (e.g. Han) */
  1111. #define PT_ALNUM 5 /* Alphanumeric - the union of L and N */
  1112. #define PT_SPACE 6 /* Perl space - Z plus 9,10,12,13 */
  1113. #define PT_PXSPACE 7 /* POSIX space - Z plus 9,10,11,12,13 */
  1114. #define PT_WORD 8 /* Word - L plus N plus underscore */
  1115. #define PT_CLIST 9 /* Pseudo-property: match character list */
  1116. #define PT_UCNC 10 /* Universal Character nameable character */
  1117. #define PT_TABSIZE 11 /* Size of square table for autopossessify tests */
  1118. /* The following special properties are used only in XCLASS items, when POSIX
  1119. classes are specified and PCRE2_UCP is set - in other words, for Unicode
  1120. handling of these classes. They are not available via the \p or \P escapes like
  1121. those in the above list, and so they do not take part in the autopossessifying
  1122. table. */
  1123. #define PT_PXGRAPH 11 /* [:graph:] - characters that mark the paper */
  1124. #define PT_PXPRINT 12 /* [:print:] - [:graph:] plus non-control spaces */
  1125. #define PT_PXPUNCT 13 /* [:punct:] - punctuation characters */
  1126. /* Flag bits and data types for the extended class (OP_XCLASS) for classes that
  1127. contain characters with values greater than 255. */
  1128. #define XCL_NOT 0x01 /* Flag: this is a negative class */
  1129. #define XCL_MAP 0x02 /* Flag: a 32-byte map is present */
  1130. #define XCL_HASPROP 0x04 /* Flag: property checks are present. */
  1131. #define XCL_END 0 /* Marks end of individual items */
  1132. #define XCL_SINGLE 1 /* Single item (one multibyte char) follows */
  1133. #define XCL_RANGE 2 /* A range (two multibyte chars) follows */
  1134. #define XCL_PROP 3 /* Unicode property (2-byte property code follows) */
  1135. #define XCL_NOTPROP 4 /* Unicode inverted property (ditto) */
  1136. /* These are escaped items that aren't just an encoding of a particular data
  1137. value such as \n. They must have non-zero values, as check_escape() returns 0
  1138. for a data character. In the escapes[] table in pcre2_compile.c their values
  1139. are negated in order to distinguish them from data values.
  1140. They must appear here in the same order as in the opcode definitions below, up
  1141. to ESC_z. There's a dummy for OP_ALLANY because it corresponds to "." in DOTALL
  1142. mode rather than an escape sequence. It is also used for [^] in JavaScript
  1143. compatibility mode, and for \C in non-utf mode. In non-DOTALL mode, "." behaves
  1144. like \N.
  1145. Negative numbers are used to encode a backreference (\1, \2, \3, etc.) in
  1146. check_escape(). There are tests in the code for an escape greater than ESC_b
  1147. and less than ESC_Z to detect the types that may be repeated. These are the
  1148. types that consume characters. If any new escapes are put in between that don't
  1149. consume a character, that code will have to change. */
  1150. enum { ESC_A = 1, ESC_G, ESC_K, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s,
  1151. ESC_W, ESC_w, ESC_N, ESC_dum, ESC_C, ESC_P, ESC_p, ESC_R, ESC_H,
  1152. ESC_h, ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z,
  1153. ESC_E, ESC_Q, ESC_g, ESC_k };
  1154. /********************** Opcode definitions ******************/
  1155. /****** NOTE NOTE NOTE ******
  1156. Starting from 1 (i.e. after OP_END), the values up to OP_EOD must correspond in
  1157. order to the list of escapes immediately above. Furthermore, values up to
  1158. OP_DOLLM must not be changed without adjusting the table called autoposstab in
  1159. pcre2_auto_possess.c.
  1160. Whenever this list is updated, the two macro definitions that follow must be
  1161. updated to match. The possessification table called "opcode_possessify" in
  1162. pcre2_compile.c must also be updated, and also the tables called "coptable"
  1163. and "poptable" in pcre2_dfa_match.c.
  1164. ****** NOTE NOTE NOTE ******/
  1165. /* The values between FIRST_AUTOTAB_OP and LAST_AUTOTAB_RIGHT_OP, inclusive,
  1166. are used in a table for deciding whether a repeated character type can be
  1167. auto-possessified. */
  1168. #define FIRST_AUTOTAB_OP OP_NOT_DIGIT
  1169. #define LAST_AUTOTAB_LEFT_OP OP_EXTUNI
  1170. #define LAST_AUTOTAB_RIGHT_OP OP_DOLLM
  1171. enum {
  1172. OP_END, /* 0 End of pattern */
  1173. /* Values corresponding to backslashed metacharacters */
  1174. OP_SOD, /* 1 Start of data: \A */
  1175. OP_SOM, /* 2 Start of match (subject + offset): \G */
  1176. OP_SET_SOM, /* 3 Set start of match (\K) */
  1177. OP_NOT_WORD_BOUNDARY, /* 4 \B */
  1178. OP_WORD_BOUNDARY, /* 5 \b */
  1179. OP_NOT_DIGIT, /* 6 \D */
  1180. OP_DIGIT, /* 7 \d */
  1181. OP_NOT_WHITESPACE, /* 8 \S */
  1182. OP_WHITESPACE, /* 9 \s */
  1183. OP_NOT_WORDCHAR, /* 10 \W */
  1184. OP_WORDCHAR, /* 11 \w */
  1185. OP_ANY, /* 12 Match any character except newline (\N) */
  1186. OP_ALLANY, /* 13 Match any character */
  1187. OP_ANYBYTE, /* 14 Match any byte (\C); different to OP_ANY for UTF-8 */
  1188. OP_NOTPROP, /* 15 \P (not Unicode property) */
  1189. OP_PROP, /* 16 \p (Unicode property) */
  1190. OP_ANYNL, /* 17 \R (any newline sequence) */
  1191. OP_NOT_HSPACE, /* 18 \H (not horizontal whitespace) */
  1192. OP_HSPACE, /* 19 \h (horizontal whitespace) */
  1193. OP_NOT_VSPACE, /* 20 \V (not vertical whitespace) */
  1194. OP_VSPACE, /* 21 \v (vertical whitespace) */
  1195. OP_EXTUNI, /* 22 \X (extended Unicode sequence */
  1196. OP_EODN, /* 23 End of data or \n at end of data (\Z) */
  1197. OP_EOD, /* 24 End of data (\z) */
  1198. /* Line end assertions */
  1199. OP_DOLL, /* 25 End of line - not multiline */
  1200. OP_DOLLM, /* 26 End of line - multiline */
  1201. OP_CIRC, /* 27 Start of line - not multiline */
  1202. OP_CIRCM, /* 28 Start of line - multiline */
  1203. /* Single characters; caseful must precede the caseless ones, and these
  1204. must remain in this order, and adjacent. */
  1205. OP_CHAR, /* 29 Match one character, casefully */
  1206. OP_CHARI, /* 30 Match one character, caselessly */
  1207. OP_NOT, /* 31 Match one character, not the given one, casefully */
  1208. OP_NOTI, /* 32 Match one character, not the given one, caselessly */
  1209. /* The following sets of 13 opcodes must always be kept in step because
  1210. the offset from the first one is used to generate the others. */
  1211. /* Repeated characters; caseful must precede the caseless ones */
  1212. OP_STAR, /* 33 The maximizing and minimizing versions of */
  1213. OP_MINSTAR, /* 34 these six opcodes must come in pairs, with */
  1214. OP_PLUS, /* 35 the minimizing one second. */
  1215. OP_MINPLUS, /* 36 */
  1216. OP_QUERY, /* 37 */
  1217. OP_MINQUERY, /* 38 */
  1218. OP_UPTO, /* 39 From 0 to n matches of one character, caseful*/
  1219. OP_MINUPTO, /* 40 */
  1220. OP_EXACT, /* 41 Exactly n matches */
  1221. OP_POSSTAR, /* 42 Possessified star, caseful */
  1222. OP_POSPLUS, /* 43 Possessified plus, caseful */
  1223. OP_POSQUERY, /* 44 Posesssified query, caseful */
  1224. OP_POSUPTO, /* 45 Possessified upto, caseful */
  1225. /* Repeated characters; caseless must follow the caseful ones */
  1226. OP_STARI, /* 46 */
  1227. OP_MINSTARI, /* 47 */
  1228. OP_PLUSI, /* 48 */
  1229. OP_MINPLUSI, /* 49 */
  1230. OP_QUERYI, /* 50 */
  1231. OP_MINQUERYI, /* 51 */
  1232. OP_UPTOI, /* 52 From 0 to n matches of one character, caseless */
  1233. OP_MINUPTOI, /* 53 */
  1234. OP_EXACTI, /* 54 */
  1235. OP_POSSTARI, /* 55 Possessified star, caseless */
  1236. OP_POSPLUSI, /* 56 Possessified plus, caseless */
  1237. OP_POSQUERYI, /* 57 Posesssified query, caseless */
  1238. OP_POSUPTOI, /* 58 Possessified upto, caseless */
  1239. /* The negated ones must follow the non-negated ones, and match them */
  1240. /* Negated repeated character, caseful; must precede the caseless ones */
  1241. OP_NOTSTAR, /* 59 The maximizing and minimizing versions of */
  1242. OP_NOTMINSTAR, /* 60 these six opcodes must come in pairs, with */
  1243. OP_NOTPLUS, /* 61 the minimizing one second. They must be in */
  1244. OP_NOTMINPLUS, /* 62 exactly the same order as those above. */
  1245. OP_NOTQUERY, /* 63 */
  1246. OP_NOTMINQUERY, /* 64 */
  1247. OP_NOTUPTO, /* 65 From 0 to n matches, caseful */
  1248. OP_NOTMINUPTO, /* 66 */
  1249. OP_NOTEXACT, /* 67 Exactly n matches */
  1250. OP_NOTPOSSTAR, /* 68 Possessified versions, caseful */
  1251. OP_NOTPOSPLUS, /* 69 */
  1252. OP_NOTPOSQUERY, /* 70 */
  1253. OP_NOTPOSUPTO, /* 71 */
  1254. /* Negated repeated character, caseless; must follow the caseful ones */
  1255. OP_NOTSTARI, /* 72 */
  1256. OP_NOTMINSTARI, /* 73 */
  1257. OP_NOTPLUSI, /* 74 */
  1258. OP_NOTMINPLUSI, /* 75 */
  1259. OP_NOTQUERYI, /* 76 */
  1260. OP_NOTMINQUERYI, /* 77 */
  1261. OP_NOTUPTOI, /* 78 From 0 to n matches, caseless */
  1262. OP_NOTMINUPTOI, /* 79 */
  1263. OP_NOTEXACTI, /* 80 Exactly n matches */
  1264. OP_NOTPOSSTARI, /* 81 Possessified versions, caseless */
  1265. OP_NOTPOSPLUSI, /* 82 */
  1266. OP_NOTPOSQUERYI, /* 83 */
  1267. OP_NOTPOSUPTOI, /* 84 */
  1268. /* Character types */
  1269. OP_TYPESTAR, /* 85 The maximizing and minimizing versions of */
  1270. OP_TYPEMINSTAR, /* 86 these six opcodes must come in pairs, with */
  1271. OP_TYPEPLUS, /* 87 the minimizing one second. These codes must */
  1272. OP_TYPEMINPLUS, /* 88 be in exactly the same order as those above. */
  1273. OP_TYPEQUERY, /* 89 */
  1274. OP_TYPEMINQUERY, /* 90 */
  1275. OP_TYPEUPTO, /* 91 From 0 to n matches */
  1276. OP_TYPEMINUPTO, /* 92 */
  1277. OP_TYPEEXACT, /* 93 Exactly n matches */
  1278. OP_TYPEPOSSTAR, /* 94 Possessified versions */
  1279. OP_TYPEPOSPLUS, /* 95 */
  1280. OP_TYPEPOSQUERY, /* 96 */
  1281. OP_TYPEPOSUPTO, /* 97 */
  1282. /* These are used for character classes and back references; only the
  1283. first six are the same as the sets above. */
  1284. OP_CRSTAR, /* 98 The maximizing and minimizing versions of */
  1285. OP_CRMINSTAR, /* 99 all these opcodes must come in pairs, with */
  1286. OP_CRPLUS, /* 100 the minimizing one second. These codes must */
  1287. OP_CRMINPLUS, /* 101 be in exactly the same order as those above. */
  1288. OP_CRQUERY, /* 102 */
  1289. OP_CRMINQUERY, /* 103 */
  1290. OP_CRRANGE, /* 104 These are different to the three sets above. */
  1291. OP_CRMINRANGE, /* 105 */
  1292. OP_CRPOSSTAR, /* 106 Possessified versions */
  1293. OP_CRPOSPLUS, /* 107 */
  1294. OP_CRPOSQUERY, /* 108 */
  1295. OP_CRPOSRANGE, /* 109 */
  1296. /* End of quantifier opcodes */
  1297. OP_CLASS, /* 110 Match a character class, chars < 256 only */
  1298. OP_NCLASS, /* 111 Same, but the bitmap was created from a negative
  1299. class - the difference is relevant only when a
  1300. character > 255 is encountered. */
  1301. OP_XCLASS, /* 112 Extended class for handling > 255 chars within the
  1302. class. This does both positive and negative. */
  1303. OP_REF, /* 113 Match a back reference, casefully */
  1304. OP_REFI, /* 114 Match a back reference, caselessly */
  1305. OP_DNREF, /* 115 Match a duplicate name backref, casefully */
  1306. OP_DNREFI, /* 116 Match a duplicate name backref, caselessly */
  1307. OP_RECURSE, /* 117 Match a numbered subpattern (possibly recursive) */
  1308. OP_CALLOUT, /* 118 Call out to external function if provided */
  1309. OP_CALLOUT_STR, /* 119 Call out with string argument */
  1310. OP_ALT, /* 120 Start of alternation */
  1311. OP_KET, /* 121 End of group that doesn't have an unbounded repeat */
  1312. OP_KETRMAX, /* 122 These two must remain together and in this */
  1313. OP_KETRMIN, /* 123 order. They are for groups the repeat for ever. */
  1314. OP_KETRPOS, /* 124 Possessive unlimited repeat. */
  1315. /* The assertions must come before BRA, CBRA, ONCE, and COND. */
  1316. OP_REVERSE, /* 125 Move pointer back - used in lookbehind assertions */
  1317. OP_ASSERT, /* 126 Positive lookahead */
  1318. OP_ASSERT_NOT, /* 127 Negative lookahead */
  1319. OP_ASSERTBACK, /* 128 Positive lookbehind */
  1320. OP_ASSERTBACK_NOT, /* 129 Negative lookbehind */
  1321. OP_ASSERT_NA, /* 130 Positive non-atomic lookahead */
  1322. OP_ASSERTBACK_NA, /* 131 Positive non-atomic lookbehind */
  1323. /* ONCE, SCRIPT_RUN, BRA, BRAPOS, CBRA, CBRAPOS, and COND must come
  1324. immediately after the assertions, with ONCE first, as there's a test for >=
  1325. ONCE for a subpattern that isn't an assertion. The POS versions must
  1326. immediately follow the non-POS versions in each case. */
  1327. OP_ONCE, /* 132 Atomic group, contains captures */
  1328. OP_SCRIPT_RUN, /* 133 Non-capture, but check characters' scripts */
  1329. OP_BRA, /* 134 Start of non-capturing bracket */
  1330. OP_BRAPOS, /* 135 Ditto, with unlimited, possessive repeat */
  1331. OP_CBRA, /* 136 Start of capturing bracket */
  1332. OP_CBRAPOS, /* 137 Ditto, with unlimited, possessive repeat */
  1333. OP_COND, /* 138 Conditional group */
  1334. /* These five must follow the previous five, in the same order. There's a
  1335. check for >= SBRA to distinguish the two sets. */
  1336. OP_SBRA, /* 139 Start of non-capturing bracket, check empty */
  1337. OP_SBRAPOS, /* 149 Ditto, with unlimited, possessive repeat */
  1338. OP_SCBRA, /* 141 Start of capturing bracket, check empty */
  1339. OP_SCBRAPOS, /* 142 Ditto, with unlimited, possessive repeat */
  1340. OP_SCOND, /* 143 Conditional group, check empty */
  1341. /* The next two pairs must (respectively) be kept together. */
  1342. OP_CREF, /* 144 Used to hold a capture number as condition */
  1343. OP_DNCREF, /* 145 Used to point to duplicate names as a condition */
  1344. OP_RREF, /* 146 Used to hold a recursion number as condition */
  1345. OP_DNRREF, /* 147 Used to point to duplicate names as a condition */
  1346. OP_FALSE, /* 148 Always false (used by DEFINE and VERSION) */
  1347. OP_TRUE, /* 149 Always true (used by VERSION) */
  1348. OP_BRAZERO, /* 150 These two must remain together and in this */
  1349. OP_BRAMINZERO, /* 151 order. */
  1350. OP_BRAPOSZERO, /* 152 */
  1351. /* These are backtracking control verbs */
  1352. OP_MARK, /* 153 always has an argument */
  1353. OP_PRUNE, /* 154 */
  1354. OP_PRUNE_ARG, /* 155 same, but with argument */
  1355. OP_SKIP, /* 156 */
  1356. OP_SKIP_ARG, /* 157 same, but with argument */
  1357. OP_THEN, /* 158 */
  1358. OP_THEN_ARG, /* 159 same, but with argument */
  1359. OP_COMMIT, /* 160 */
  1360. OP_COMMIT_ARG, /* 161 same, but with argument */
  1361. /* These are forced failure and success verbs. FAIL and ACCEPT do accept an
  1362. argument, but these cases can be compiled as, for example, (*MARK:X)(*FAIL)
  1363. without the need for a special opcode. */
  1364. OP_FAIL, /* 162 */
  1365. OP_ACCEPT, /* 163 */
  1366. OP_ASSERT_ACCEPT, /* 164 Used inside assertions */
  1367. OP_CLOSE, /* 165 Used before OP_ACCEPT to close open captures */
  1368. /* This is used to skip a subpattern with a {0} quantifier */
  1369. OP_SKIPZERO, /* 166 */
  1370. /* This is used to identify a DEFINE group during compilation so that it can
  1371. be checked for having only one branch. It is changed to OP_FALSE before
  1372. compilation finishes. */
  1373. OP_DEFINE, /* 167 */
  1374. /* This is not an opcode, but is used to check that tables indexed by opcode
  1375. are the correct length, in order to catch updating errors - there have been
  1376. some in the past. */
  1377. OP_TABLE_LENGTH
  1378. };
  1379. /* *** NOTE NOTE NOTE *** Whenever the list above is updated, the two macro
  1380. definitions that follow must also be updated to match. There are also tables
  1381. called "opcode_possessify" in pcre2_compile.c and "coptable" and "poptable" in
  1382. pcre2_dfa_match.c that must be updated. */
  1383. /* This macro defines textual names for all the opcodes. These are used only
  1384. for debugging, and some of them are only partial names. The macro is referenced
  1385. only in pcre2_printint.c, which fills out the full names in many cases (and in
  1386. some cases doesn't actually use these names at all). */
  1387. #define OP_NAME_LIST \
  1388. "End", "\\A", "\\G", "\\K", "\\B", "\\b", "\\D", "\\d", \
  1389. "\\S", "\\s", "\\W", "\\w", "Any", "AllAny", "Anybyte", \
  1390. "notprop", "prop", "\\R", "\\H", "\\h", "\\V", "\\v", \
  1391. "extuni", "\\Z", "\\z", \
  1392. "$", "$", "^", "^", "char", "chari", "not", "noti", \
  1393. "*", "*?", "+", "+?", "?", "??", \
  1394. "{", "{", "{", \
  1395. "*+","++", "?+", "{", \
  1396. "*", "*?", "+", "+?", "?", "??", \
  1397. "{", "{", "{", \
  1398. "*+","++", "?+", "{", \
  1399. "*", "*?", "+", "+?", "?", "??", \
  1400. "{", "{", "{", \
  1401. "*+","++", "?+", "{", \
  1402. "*", "*?", "+", "+?", "?", "??", \
  1403. "{", "{", "{", \
  1404. "*+","++", "?+", "{", \
  1405. "*", "*?", "+", "+?", "?", "??", "{", "{", "{", \
  1406. "*+","++", "?+", "{", \
  1407. "*", "*?", "+", "+?", "?", "??", "{", "{", \
  1408. "*+","++", "?+", "{", \
  1409. "class", "nclass", "xclass", "Ref", "Refi", "DnRef", "DnRefi", \
  1410. "Recurse", "Callout", "CalloutStr", \
  1411. "Alt", "Ket", "KetRmax", "KetRmin", "KetRpos", \
  1412. "Reverse", "Assert", "Assert not", \
  1413. "Assert back", "Assert back not", \
  1414. "Non-atomic assert", "Non-atomic assert back", \
  1415. "Once", \
  1416. "Script run", \
  1417. "Bra", "BraPos", "CBra", "CBraPos", \
  1418. "Cond", \
  1419. "SBra", "SBraPos", "SCBra", "SCBraPos", \
  1420. "SCond", \
  1421. "Cond ref", "Cond dnref", "Cond rec", "Cond dnrec", \
  1422. "Cond false", "Cond true", \
  1423. "Brazero", "Braminzero", "Braposzero", \
  1424. "*MARK", "*PRUNE", "*PRUNE", "*SKIP", "*SKIP", \
  1425. "*THEN", "*THEN", "*COMMIT", "*COMMIT", "*FAIL", \
  1426. "*ACCEPT", "*ASSERT_ACCEPT", \
  1427. "Close", "Skip zero", "Define"
  1428. /* This macro defines the length of fixed length operations in the compiled
  1429. regex. The lengths are used when searching for specific things, and also in the
  1430. debugging printing of a compiled regex. We use a macro so that it can be
  1431. defined close to the definitions of the opcodes themselves.
  1432. As things have been extended, some of these are no longer fixed lenths, but are
  1433. minima instead. For example, the length of a single-character repeat may vary
  1434. in UTF-8 mode. The code that uses this table must know about such things. */
  1435. #define OP_LENGTHS \
  1436. 1, /* End */ \
  1437. 1, 1, 1, 1, 1, /* \A, \G, \K, \B, \b */ \
  1438. 1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */ \
  1439. 1, 1, 1, /* Any, AllAny, Anybyte */ \
  1440. 3, 3, /* \P, \p */ \
  1441. 1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */ \
  1442. 1, /* \X */ \
  1443. 1, 1, 1, 1, 1, 1, /* \Z, \z, $, $M ^, ^M */ \
  1444. 2, /* Char - the minimum length */ \
  1445. 2, /* Chari - the minimum length */ \
  1446. 2, /* not */ \
  1447. 2, /* noti */ \
  1448. /* Positive single-char repeats ** These are */ \
  1449. 2, 2, 2, 2, 2, 2, /* *, *?, +, +?, ?, ?? ** minima in */ \
  1450. 2+IMM2_SIZE, 2+IMM2_SIZE, /* upto, minupto ** mode */ \
  1451. 2+IMM2_SIZE, /* exact */ \
  1452. 2, 2, 2, 2+IMM2_SIZE, /* *+, ++, ?+, upto+ */ \
  1453. 2, 2, 2, 2, 2, 2, /* *I, *?I, +I, +?I, ?I, ??I ** UTF-8 */ \
  1454. 2+IMM2_SIZE, 2+IMM2_SIZE, /* upto I, minupto I */ \
  1455. 2+IMM2_SIZE, /* exact I */ \
  1456. 2, 2, 2, 2+IMM2_SIZE, /* *+I, ++I, ?+I, upto+I */ \
  1457. /* Negative single-char repeats - only for chars < 256 */ \
  1458. 2, 2, 2, 2, 2, 2, /* NOT *, *?, +, +?, ?, ?? */ \
  1459. 2+IMM2_SIZE, 2+IMM2_SIZE, /* NOT upto, minupto */ \
  1460. 2+IMM2_SIZE, /* NOT exact */ \
  1461. 2, 2, 2, 2+IMM2_SIZE, /* Possessive NOT *, +, ?, upto */ \
  1462. 2, 2, 2, 2, 2, 2, /* NOT *I, *?I, +I, +?I, ?I, ??I */ \
  1463. 2+IMM2_SIZE, 2+IMM2_SIZE, /* NOT upto I, minupto I */ \
  1464. 2+IMM2_SIZE, /* NOT exact I */ \
  1465. 2, 2, 2, 2+IMM2_SIZE, /* Possessive NOT *I, +I, ?I, upto I */ \
  1466. /* Positive type repeats */ \
  1467. 2, 2, 2, 2, 2, 2, /* Type *, *?, +, +?, ?, ?? */ \
  1468. 2+IMM2_SIZE, 2+IMM2_SIZE, /* Type upto, minupto */ \
  1469. 2+IMM2_SIZE, /* Type exact */ \
  1470. 2, 2, 2, 2+IMM2_SIZE, /* Possessive *+, ++, ?+, upto+ */ \
  1471. /* Character class & ref repeats */ \
  1472. 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ \
  1473. 1+2*IMM2_SIZE, 1+2*IMM2_SIZE, /* CRRANGE, CRMINRANGE */ \
  1474. 1, 1, 1, 1+2*IMM2_SIZE, /* Possessive *+, ++, ?+, CRPOSRANGE */ \
  1475. 1+(32/sizeof(PCRE2_UCHAR)), /* CLASS */ \
  1476. 1+(32/sizeof(PCRE2_UCHAR)), /* NCLASS */ \
  1477. 0, /* XCLASS - variable length */ \
  1478. 1+IMM2_SIZE, /* REF */ \
  1479. 1+IMM2_SIZE, /* REFI */ \
  1480. 1+2*IMM2_SIZE, /* DNREF */ \
  1481. 1+2*IMM2_SIZE, /* DNREFI */ \
  1482. 1+LINK_SIZE, /* RECURSE */ \
  1483. 1+2*LINK_SIZE+1, /* CALLOUT */ \
  1484. 0, /* CALLOUT_STR - variable length */ \
  1485. 1+LINK_SIZE, /* Alt */ \
  1486. 1+LINK_SIZE, /* Ket */ \
  1487. 1+LINK_SIZE, /* KetRmax */ \
  1488. 1+LINK_SIZE, /* KetRmin */ \
  1489. 1+LINK_SIZE, /* KetRpos */ \
  1490. 1+LINK_SIZE, /* Reverse */ \
  1491. 1+LINK_SIZE, /* Assert */ \
  1492. 1+LINK_SIZE, /* Assert not */ \
  1493. 1+LINK_SIZE, /* Assert behind */ \
  1494. 1+LINK_SIZE, /* Assert behind not */ \
  1495. 1+LINK_SIZE, /* NA Assert */ \
  1496. 1+LINK_SIZE, /* NA Assert behind */ \
  1497. 1+LINK_SIZE, /* ONCE */ \
  1498. 1+LINK_SIZE, /* SCRIPT_RUN */ \
  1499. 1+LINK_SIZE, /* BRA */ \
  1500. 1+LINK_SIZE, /* BRAPOS */ \
  1501. 1+LINK_SIZE+IMM2_SIZE, /* CBRA */ \
  1502. 1+LINK_SIZE+IMM2_SIZE, /* CBRAPOS */ \
  1503. 1+LINK_SIZE, /* COND */ \
  1504. 1+LINK_SIZE, /* SBRA */ \
  1505. 1+LINK_SIZE, /* SBRAPOS */ \
  1506. 1+LINK_SIZE+IMM2_SIZE, /* SCBRA */ \
  1507. 1+LINK_SIZE+IMM2_SIZE, /* SCBRAPOS */ \
  1508. 1+LINK_SIZE, /* SCOND */ \
  1509. 1+IMM2_SIZE, 1+2*IMM2_SIZE, /* CREF, DNCREF */ \
  1510. 1+IMM2_SIZE, 1+2*IMM2_SIZE, /* RREF, DNRREF */ \
  1511. 1, 1, /* FALSE, TRUE */ \
  1512. 1, 1, 1, /* BRAZERO, BRAMINZERO, BRAPOSZERO */ \
  1513. 3, 1, 3, /* MARK, PRUNE, PRUNE_ARG */ \
  1514. 1, 3, /* SKIP, SKIP_ARG */ \
  1515. 1, 3, /* THEN, THEN_ARG */ \
  1516. 1, 3, /* COMMIT, COMMIT_ARG */ \
  1517. 1, 1, 1, /* FAIL, ACCEPT, ASSERT_ACCEPT */ \
  1518. 1+IMM2_SIZE, 1, /* CLOSE, SKIPZERO */ \
  1519. 1 /* DEFINE */
  1520. /* A magic value for OP_RREF to indicate the "any recursion" condition. */
  1521. #define RREF_ANY 0xffff
  1522. /* ---------- Private structures that are mode-independent. ---------- */
  1523. /* Structure to hold data for custom memory management. */
  1524. typedef struct pcre2_memctl {
  1525. void * (*malloc)(size_t, void *);
  1526. void (*free)(void *, void *);
  1527. void *memory_data;
  1528. } pcre2_memctl;
  1529. /* Structure for building a chain of open capturing subpatterns during
  1530. compiling, so that instructions to close them can be compiled when (*ACCEPT) is
  1531. encountered. */
  1532. typedef struct open_capitem {
  1533. struct open_capitem *next; /* Chain link */
  1534. uint16_t number; /* Capture number */
  1535. uint16_t assert_depth; /* Assertion depth when opened */
  1536. } open_capitem;
  1537. /* Layout of the UCP type table that translates property names into types and
  1538. codes. Each entry used to point directly to a name, but to reduce the number of
  1539. relocations in shared libraries, it now has an offset into a single string
  1540. instead. */
  1541. typedef struct {
  1542. uint16_t name_offset;
  1543. uint16_t type;
  1544. uint16_t value;
  1545. } ucp_type_table;
  1546. /* Unicode character database (UCD) record format */
  1547. typedef struct {
  1548. uint8_t script; /* ucp_Arabic, etc. */
  1549. uint8_t chartype; /* ucp_Cc, etc. (general categories) */
  1550. uint8_t gbprop; /* ucp_gbControl, etc. (grapheme break property) */
  1551. uint8_t caseset; /* offset to multichar other cases or zero */
  1552. int32_t other_case; /* offset to other case, or zero if none */
  1553. int16_t scriptx; /* script extension value */
  1554. int16_t dummy; /* spare - to round to multiple of 4 bytes */
  1555. } ucd_record;
  1556. /* UCD access macros */
  1557. #define UCD_BLOCK_SIZE 128
  1558. #define REAL_GET_UCD(ch) (PRIV(ucd_records) + \
  1559. PRIV(ucd_stage2)[PRIV(ucd_stage1)[(int)(ch) / UCD_BLOCK_SIZE] * \
  1560. UCD_BLOCK_SIZE + (int)(ch) % UCD_BLOCK_SIZE])
  1561. #if PCRE2_CODE_UNIT_WIDTH == 32
  1562. #define GET_UCD(ch) ((ch > MAX_UTF_CODE_POINT)? \
  1563. PRIV(dummy_ucd_record) : REAL_GET_UCD(ch))
  1564. #else
  1565. #define GET_UCD(ch) REAL_GET_UCD(ch)
  1566. #endif
  1567. #define UCD_CHARTYPE(ch) GET_UCD(ch)->chartype
  1568. #define UCD_SCRIPT(ch) GET_UCD(ch)->script
  1569. #define UCD_CATEGORY(ch) PRIV(ucp_gentype)[UCD_CHARTYPE(ch)]
  1570. #define UCD_GRAPHBREAK(ch) GET_UCD(ch)->gbprop
  1571. #define UCD_CASESET(ch) GET_UCD(ch)->caseset
  1572. #define UCD_OTHERCASE(ch) ((uint32_t)((int)ch + (int)(GET_UCD(ch)->other_case)))
  1573. #define UCD_SCRIPTX(ch) GET_UCD(ch)->scriptx
  1574. /* Header for serialized pcre2 codes. */
  1575. typedef struct pcre2_serialized_data {
  1576. uint32_t magic;
  1577. uint32_t version;
  1578. uint32_t config;
  1579. int32_t number_of_codes;
  1580. } pcre2_serialized_data;
  1581. /* ----------------- Items that need PCRE2_CODE_UNIT_WIDTH ----------------- */
  1582. /* When this file is included by pcre2test, PCRE2_CODE_UNIT_WIDTH is defined as
  1583. 0, so the following items are omitted. */
  1584. #if defined PCRE2_CODE_UNIT_WIDTH && PCRE2_CODE_UNIT_WIDTH != 0
  1585. /* EBCDIC is supported only for the 8-bit library. */
  1586. #if defined EBCDIC && PCRE2_CODE_UNIT_WIDTH != 8
  1587. #error EBCDIC is not supported for the 16-bit or 32-bit libraries
  1588. #endif
  1589. /* This is the largest non-UTF code point. */
  1590. #define MAX_NON_UTF_CHAR (0xffffffffU >> (32 - PCRE2_CODE_UNIT_WIDTH))
  1591. /* Internal shared data tables and variables. These are used by more than one
  1592. of the exported public functions. They have to be "external" in the C sense,
  1593. but are not part of the PCRE2 public API. Although the data for some of them is
  1594. identical in all libraries, they must have different names so that multiple
  1595. libraries can be simultaneously linked to a single application. However, UTF-8
  1596. tables are needed only when compiling the 8-bit library. */
  1597. #if PCRE2_CODE_UNIT_WIDTH == 8
  1598. extern const int PRIV(utf8_table1)[];
  1599. extern const int PRIV(utf8_table1_size);
  1600. extern const int PRIV(utf8_table2)[];
  1601. extern const int PRIV(utf8_table3)[];
  1602. extern const uint8_t PRIV(utf8_table4)[];
  1603. #endif
  1604. #define _pcre2_OP_lengths PCRE2_SUFFIX(_pcre2_OP_lengths_)
  1605. #define _pcre2_callout_end_delims PCRE2_SUFFIX(_pcre2_callout_end_delims_)
  1606. #define _pcre2_callout_start_delims PCRE2_SUFFIX(_pcre2_callout_start_delims_)
  1607. #define _pcre2_default_compile_context PCRE2_SUFFIX(_pcre2_default_compile_context_)
  1608. #define _pcre2_default_convert_context PCRE2_SUFFIX(_pcre2_default_convert_context_)
  1609. #define _pcre2_default_match_context PCRE2_SUFFIX(_pcre2_default_match_context_)
  1610. #define _pcre2_default_tables PCRE2_SUFFIX(_pcre2_default_tables_)
  1611. #if PCRE2_CODE_UNIT_WIDTH == 32
  1612. #define _pcre2_dummy_ucd_record PCRE2_SUFFIX(_pcre2_dummy_ucd_record_)
  1613. #endif
  1614. #define _pcre2_hspace_list PCRE2_SUFFIX(_pcre2_hspace_list_)
  1615. #define _pcre2_vspace_list PCRE2_SUFFIX(_pcre2_vspace_list_)
  1616. #define _pcre2_ucd_caseless_sets PCRE2_SUFFIX(_pcre2_ucd_caseless_sets_)
  1617. #define _pcre2_ucd_digit_sets PCRE2_SUFFIX(_pcre2_ucd_digit_sets_)
  1618. #define _pcre2_ucd_script_sets PCRE2_SUFFIX(_pcre2_ucd_script_sets_)
  1619. #define _pcre2_ucd_records PCRE2_SUFFIX(_pcre2_ucd_records_)
  1620. #define _pcre2_ucd_stage1 PCRE2_SUFFIX(_pcre2_ucd_stage1_)
  1621. #define _pcre2_ucd_stage2 PCRE2_SUFFIX(_pcre2_ucd_stage2_)
  1622. #define _pcre2_ucp_gbtable PCRE2_SUFFIX(_pcre2_ucp_gbtable_)
  1623. #define _pcre2_ucp_gentype PCRE2_SUFFIX(_pcre2_ucp_gentype_)
  1624. #define _pcre2_ucp_typerange PCRE2_SUFFIX(_pcre2_ucp_typerange_)
  1625. #define _pcre2_unicode_version PCRE2_SUFFIX(_pcre2_unicode_version_)
  1626. #define _pcre2_utt PCRE2_SUFFIX(_pcre2_utt_)
  1627. #define _pcre2_utt_names PCRE2_SUFFIX(_pcre2_utt_names_)
  1628. #define _pcre2_utt_size PCRE2_SUFFIX(_pcre2_utt_size_)
  1629. extern const uint8_t PRIV(OP_lengths)[];
  1630. extern const uint32_t PRIV(callout_end_delims)[];
  1631. extern const uint32_t PRIV(callout_start_delims)[];
  1632. extern const pcre2_compile_context PRIV(default_compile_context);
  1633. extern const pcre2_convert_context PRIV(default_convert_context);
  1634. extern const pcre2_match_context PRIV(default_match_context);
  1635. extern const uint8_t PRIV(default_tables)[];
  1636. extern const uint32_t PRIV(hspace_list)[];
  1637. extern const uint32_t PRIV(vspace_list)[];
  1638. extern const uint32_t PRIV(ucd_caseless_sets)[];
  1639. extern const uint32_t PRIV(ucd_digit_sets)[];
  1640. extern const uint8_t PRIV(ucd_script_sets)[];
  1641. extern const ucd_record PRIV(ucd_records)[];
  1642. #if PCRE2_CODE_UNIT_WIDTH == 32
  1643. extern const ucd_record PRIV(dummy_ucd_record)[];
  1644. #endif
  1645. extern const uint16_t PRIV(ucd_stage1)[];
  1646. extern const uint16_t PRIV(ucd_stage2)[];
  1647. extern const uint32_t PRIV(ucp_gbtable)[];
  1648. extern const uint32_t PRIV(ucp_gentype)[];
  1649. #ifdef SUPPORT_JIT
  1650. extern const int PRIV(ucp_typerange)[];
  1651. #endif
  1652. extern const char *PRIV(unicode_version);
  1653. extern const ucp_type_table PRIV(utt)[];
  1654. extern const char PRIV(utt_names)[];
  1655. extern const size_t PRIV(utt_size);
  1656. /* Mode-dependent macros and hidden and private structures are defined in a
  1657. separate file so that pcre2test can include them at all supported widths. When
  1658. compiling the library, PCRE2_CODE_UNIT_WIDTH will be defined, and we can
  1659. include them at the appropriate width, after setting up suffix macros for the
  1660. private structures. */
  1661. #define branch_chain PCRE2_SUFFIX(branch_chain_)
  1662. #define compile_block PCRE2_SUFFIX(compile_block_)
  1663. #define dfa_match_block PCRE2_SUFFIX(dfa_match_block_)
  1664. #define match_block PCRE2_SUFFIX(match_block_)
  1665. #define named_group PCRE2_SUFFIX(named_group_)
  1666. #include "pcre2_intmodedep.h"
  1667. /* Private "external" functions. These are internal functions that are called
  1668. from modules other than the one in which they are defined. They have to be
  1669. "external" in the C sense, but are not part of the PCRE2 public API. They are
  1670. not referenced from pcre2test, and must not be defined when no code unit width
  1671. is available. */
  1672. #define _pcre2_auto_possessify PCRE2_SUFFIX(_pcre2_auto_possessify_)
  1673. #define _pcre2_check_escape PCRE2_SUFFIX(_pcre2_check_escape_)
  1674. #define _pcre2_extuni PCRE2_SUFFIX(_pcre2_extuni_)
  1675. #define _pcre2_find_bracket PCRE2_SUFFIX(_pcre2_find_bracket_)
  1676. #define _pcre2_is_newline PCRE2_SUFFIX(_pcre2_is_newline_)
  1677. #define _pcre2_jit_free_rodata PCRE2_SUFFIX(_pcre2_jit_free_rodata_)
  1678. #define _pcre2_jit_free PCRE2_SUFFIX(_pcre2_jit_free_)
  1679. #define _pcre2_jit_get_size PCRE2_SUFFIX(_pcre2_jit_get_size_)
  1680. #define _pcre2_jit_get_target PCRE2_SUFFIX(_pcre2_jit_get_target_)
  1681. #define _pcre2_memctl_malloc PCRE2_SUFFIX(_pcre2_memctl_malloc_)
  1682. #define _pcre2_ord2utf PCRE2_SUFFIX(_pcre2_ord2utf_)
  1683. #define _pcre2_script_run PCRE2_SUFFIX(_pcre2_script_run_)
  1684. #define _pcre2_strcmp PCRE2_SUFFIX(_pcre2_strcmp_)
  1685. #define _pcre2_strcmp_c8 PCRE2_SUFFIX(_pcre2_strcmp_c8_)
  1686. #define _pcre2_strcpy_c8 PCRE2_SUFFIX(_pcre2_strcpy_c8_)
  1687. #define _pcre2_strlen PCRE2_SUFFIX(_pcre2_strlen_)
  1688. #define _pcre2_strncmp PCRE2_SUFFIX(_pcre2_strncmp_)
  1689. #define _pcre2_strncmp_c8 PCRE2_SUFFIX(_pcre2_strncmp_c8_)
  1690. #define _pcre2_study PCRE2_SUFFIX(_pcre2_study_)
  1691. #define _pcre2_valid_utf PCRE2_SUFFIX(_pcre2_valid_utf_)
  1692. #define _pcre2_was_newline PCRE2_SUFFIX(_pcre2_was_newline_)
  1693. #define _pcre2_xclass PCRE2_SUFFIX(_pcre2_xclass_)
  1694. extern int _pcre2_auto_possessify(PCRE2_UCHAR *,
  1695. const compile_block *);
  1696. extern int _pcre2_check_escape(PCRE2_SPTR *, PCRE2_SPTR, uint32_t *,
  1697. int *, uint32_t, uint32_t, BOOL, compile_block *);
  1698. extern PCRE2_SPTR _pcre2_extuni(uint32_t, PCRE2_SPTR, PCRE2_SPTR, PCRE2_SPTR,
  1699. BOOL, int *);
  1700. extern PCRE2_SPTR _pcre2_find_bracket(PCRE2_SPTR, BOOL, int);
  1701. extern BOOL _pcre2_is_newline(PCRE2_SPTR, uint32_t, PCRE2_SPTR,
  1702. uint32_t *, BOOL);
  1703. extern void _pcre2_jit_free_rodata(void *, void *);
  1704. extern void _pcre2_jit_free(void *, pcre2_memctl *);
  1705. extern size_t _pcre2_jit_get_size(void *);
  1706. const char * _pcre2_jit_get_target(void);
  1707. extern void * _pcre2_memctl_malloc(size_t, pcre2_memctl *);
  1708. extern unsigned int _pcre2_ord2utf(uint32_t, PCRE2_UCHAR *);
  1709. extern BOOL _pcre2_script_run(PCRE2_SPTR, PCRE2_SPTR, BOOL);
  1710. extern int _pcre2_strcmp(PCRE2_SPTR, PCRE2_SPTR);
  1711. extern int _pcre2_strcmp_c8(PCRE2_SPTR, const char *);
  1712. extern PCRE2_SIZE _pcre2_strcpy_c8(PCRE2_UCHAR *, const char *);
  1713. extern PCRE2_SIZE _pcre2_strlen(PCRE2_SPTR);
  1714. extern int _pcre2_strncmp(PCRE2_SPTR, PCRE2_SPTR, size_t);
  1715. extern int _pcre2_strncmp_c8(PCRE2_SPTR, const char *, size_t);
  1716. extern int _pcre2_study(pcre2_real_code *);
  1717. extern int _pcre2_valid_utf(PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE *);
  1718. extern BOOL _pcre2_was_newline(PCRE2_SPTR, uint32_t, PCRE2_SPTR,
  1719. uint32_t *, BOOL);
  1720. extern BOOL _pcre2_xclass(uint32_t, PCRE2_SPTR, BOOL);
  1721. /* This function is needed only when memmove() is not available. */
  1722. #if !defined(VPCOMPAT) && !defined(HAVE_MEMMOVE)
  1723. #define _pcre2_memmove PCRE2_SUFFIX(_pcre2_memmove)
  1724. extern void * _pcre2_memmove(void *, const void *, size_t);
  1725. #endif
  1726. #endif /* PCRE2_CODE_UNIT_WIDTH */
  1727. #endif /* PCRE2_INTERNAL_H_IDEMPOTENT_GUARD */
  1728. /* End of pcre2_internal.h */