1# 2# 3# Nim's Runtime Library 4# (c) Copyright 2015 Andreas Rumpf 5# 6# See the file "copying.txt", included in this 7# distribution, for details about the copyright. 8# 9 10# The current PCRE version information. 11 12const 13 PCRE_MAJOR* = 8 14 PCRE_MINOR* = 36 15 PCRE_PRERELEASE* = true 16 PCRE_DATE* = "2014-09-26" 17 18# When an application links to a PCRE DLL in Windows, the symbols that are 19# imported have to be identified as such. When building PCRE, the appropriate 20# export setting is defined in pcre_internal.h, which includes this file. So we 21# don't change existing definitions of PCRE_EXP_DECL and PCRECPP_EXP_DECL. 22 23# By default, we use the standard "extern" declarations. 24 25# Allow for C++ users 26 27# Public options. Some are compile-time only, some are run-time only, and some 28# are both. Most of the compile-time options are saved with the compiled regex 29# so that they can be inspected during studying (and therefore JIT compiling). 30# Note that pcre_study() has its own set of options. Originally, all the options 31# defined here used distinct bits. However, almost all the bits in a 32-bit word 32# are now used, so in order to conserve them, option bits that were previously 33# only recognized at matching time (i.e. by pcre_exec() or pcre_dfa_exec()) may 34# also be used for compile-time options that affect only compiling and are not 35# relevant for studying or JIT compiling. 36# 37# Some options for pcre_compile() change its behaviour but do not affect the 38# behaviour of the execution functions. Other options are passed through to the 39# execution functions and affect their behaviour, with or without affecting the 40# behaviour of pcre_compile(). 41# 42# Options that can be passed to pcre_compile() are tagged Cx below, with these 43# variants: 44# 45# C1 Affects compile only 46# C2 Does not affect compile; affects exec, dfa_exec 47# C3 Affects compile, exec, dfa_exec 48# C4 Affects compile, exec, dfa_exec, study 49# C5 Affects compile, exec, study 50# 51# Options that can be set for pcre_exec() and/or pcre_dfa_exec() are flagged 52# with E and D, respectively. They take precedence over C3, C4, and C5 settings 53# passed from pcre_compile(). Those that are compatible with JIT execution are 54# flagged with J. 55 56const 57 CASELESS* = 0x00000001 # C1 58 MULTILINE* = 0x00000002 # C1 59 DOTALL* = 0x00000004 # C1 60 EXTENDED* = 0x00000008 # C1 61 ANCHORED* = 0x00000010 # C4 E D 62 DOLLAR_ENDONLY* = 0x00000020 # C2 63 EXTRA* = 0x00000040 # C1 64 NOTBOL* = 0x00000080 # E D J 65 NOTEOL* = 0x00000100 # E D J 66 UNGREEDY* = 0x00000200 # C1 67 NOTEMPTY* = 0x00000400 # E D J 68 UTF8* = 0x00000800 # C4 ) 69 UTF16* = 0x00000800 # C4 ) Synonyms 70 UTF32* = 0x00000800 # C4 ) 71 NO_AUTO_CAPTURE* = 0x00001000 # C1 72 NO_UTF8_CHECK* = 0x00002000 # C1 E D J ) 73 NO_UTF16_CHECK* = 0x00002000 # C1 E D J ) Synonyms 74 NO_UTF32_CHECK* = 0x00002000 # C1 E D J ) 75 AUTO_CALLOUT* = 0x00004000 # C1 76 PARTIAL_SOFT* = 0x00008000 # E D J ) Synonyms 77 PARTIAL* = 0x00008000 # E D J ) 78 79# This pair use the same bit. 80const 81 NEVER_UTF* = 0x00010000 # C1 ) Overlaid 82 DFA_SHORTEST* = 0x00010000 # D ) Overlaid 83 84# This pair use the same bit. 85const 86 NO_AUTO_POSSESS* = 0x00020000 # C1 ) Overlaid 87 DFA_RESTART* = 0x00020000 # D ) Overlaid 88 89const 90 FIRSTLINE* = 0x00040000 # C3 91 DUPNAMES* = 0x00080000 # C1 92 NEWLINE_CR* = 0x00100000 # C3 E D 93 NEWLINE_LF* = 0x00200000 # C3 E D 94 NEWLINE_CRLF* = 0x00300000 # C3 E D 95 NEWLINE_ANY* = 0x00400000 # C3 E D 96 NEWLINE_ANYCRLF* = 0x00500000 # C3 E D 97 BSR_ANYCRLF* = 0x00800000 # C3 E D 98 BSR_UNICODE* = 0x01000000 # C3 E D 99 JAVASCRIPT_COMPAT* = 0x02000000 # C5 100 NO_START_OPTIMIZE* = 0x04000000 # C2 E D ) Synonyms 101 NO_START_OPTIMISE* = 0x04000000 # C2 E D ) 102 PARTIAL_HARD* = 0x08000000 # E D J 103 NOTEMPTY_ATSTART* = 0x10000000 # E D J 104 UCP* = 0x20000000 # C3 105 106# Exec-time and get/set-time error codes 107const 108 ERROR_NOMATCH* = -1 109 ERROR_NULL* = -2 110 ERROR_BADOPTION* = -3 111 ERROR_BADMAGIC* = -4 112 ERROR_UNKNOWN_OPCODE* = -5 113 ERROR_UNKNOWN_NODE* = -5 ## For backward compatibility 114 ERROR_NOMEMORY* = -6 115 ERROR_NOSUBSTRING* = -7 116 ERROR_MATCHLIMIT* = -8 117 ERROR_CALLOUT* = -9 ## Never used by PCRE itself 118 ERROR_BADUTF8* = -10 ## Same for 8/16/32 119 ERROR_BADUTF16* = -10 ## Same for 8/16/32 120 ERROR_BADUTF32* = -10 ## Same for 8/16/32 121 ERROR_BADUTF8_OFFSET* = -11 ## Same for 8/16 122 ERROR_BADUTF16_OFFSET* = -11 ## Same for 8/16 123 ERROR_PARTIAL* = -12 124 ERROR_BADPARTIAL* = -13 125 ERROR_INTERNAL* = -14 126 ERROR_BADCOUNT* = -15 127 ERROR_DFA_UITEM* = -16 128 ERROR_DFA_UCOND* = -17 129 ERROR_DFA_UMLIMIT* = -18 130 ERROR_DFA_WSSIZE* = -19 131 ERROR_DFA_RECURSE* = -20 132 ERROR_RECURSIONLIMIT* = -21 133 ERROR_NULLWSLIMIT* = -22 ## No longer actually used 134 ERROR_BADNEWLINE* = -23 135 ERROR_BADOFFSET* = -24 136 ERROR_SHORTUTF8* = -25 137 ERROR_SHORTUTF16* = -25 ## Same for 8/16 138 ERROR_RECURSELOOP* = -26 139 ERROR_JIT_STACKLIMIT* = -27 140 ERROR_BADMODE* = -28 141 ERROR_BADENDIANNESS* = -29 142 ERROR_DFA_BADRESTART* = -30 143 ERROR_JIT_BADOPTION* = -31 144 ERROR_BADLENGTH* = -32 145 ERROR_UNSET* = -33 146 147# Specific error codes for UTF-8 validity checks 148const 149 UTF8_ERR0* = 0 150 UTF8_ERR1* = 1 151 UTF8_ERR2* = 2 152 UTF8_ERR3* = 3 153 UTF8_ERR4* = 4 154 UTF8_ERR5* = 5 155 UTF8_ERR6* = 6 156 UTF8_ERR7* = 7 157 UTF8_ERR8* = 8 158 UTF8_ERR9* = 9 159 UTF8_ERR10* = 10 160 UTF8_ERR11* = 11 161 UTF8_ERR12* = 12 162 UTF8_ERR13* = 13 163 UTF8_ERR14* = 14 164 UTF8_ERR15* = 15 165 UTF8_ERR16* = 16 166 UTF8_ERR17* = 17 167 UTF8_ERR18* = 18 168 UTF8_ERR19* = 19 169 UTF8_ERR20* = 20 170 UTF8_ERR21* = 21 171 UTF8_ERR22* = 22 # Unused (was non-character) 172 173# Specific error codes for UTF-16 validity checks 174const 175 UTF16_ERR0* = 0 176 UTF16_ERR1* = 1 177 UTF16_ERR2* = 2 178 UTF16_ERR3* = 3 179 UTF16_ERR4* = 4 # Unused (was non-character) 180 181# Specific error codes for UTF-32 validity checks 182const 183 UTF32_ERR0* = 0 184 UTF32_ERR1* = 1 185 UTF32_ERR2* = 2 # Unused (was non-character) 186 UTF32_ERR3* = 3 187 188# Request types for pcre_fullinfo() 189const 190 INFO_OPTIONS* = 0 191 INFO_SIZE* = 1 192 INFO_CAPTURECOUNT* = 2 193 INFO_BACKREFMAX* = 3 194 INFO_FIRSTBYTE* = 4 195 INFO_FIRSTCHAR* = 4 ## For backwards compatibility 196 INFO_FIRSTTABLE* = 5 197 INFO_LASTLITERAL* = 6 198 INFO_NAMEENTRYSIZE* = 7 199 INFO_NAMECOUNT* = 8 200 INFO_NAMETABLE* = 9 201 INFO_STUDYSIZE* = 10 202 INFO_DEFAULT_TABLES* = 11 203 INFO_OKPARTIAL* = 12 204 INFO_JCHANGED* = 13 205 INFO_HASCRORLF* = 14 206 INFO_MINLENGTH* = 15 207 INFO_JIT* = 16 208 INFO_JITSIZE* = 17 209 INFO_MAXLOOKBEHIND* = 18 210 INFO_FIRSTCHARACTER* = 19 211 INFO_FIRSTCHARACTERFLAGS* = 20 212 INFO_REQUIREDCHAR* = 21 213 INFO_REQUIREDCHARFLAGS* = 22 214 INFO_MATCHLIMIT* = 23 215 INFO_RECURSIONLIMIT* = 24 216 INFO_MATCH_EMPTY* = 25 217 218# Request types for pcre_config(). Do not re-arrange, in order to remain 219# compatible. 220const 221 CONFIG_UTF8* = 0 222 CONFIG_NEWLINE* = 1 223 CONFIG_LINK_SIZE* = 2 224 CONFIG_POSIX_MALLOC_THRESHOLD* = 3 225 CONFIG_MATCH_LIMIT* = 4 226 CONFIG_STACKRECURSE* = 5 227 CONFIG_UNICODE_PROPERTIES* = 6 228 CONFIG_MATCH_LIMIT_RECURSION* = 7 229 CONFIG_BSR* = 8 230 CONFIG_JIT* = 9 231 CONFIG_UTF16* = 10 232 CONFIG_JITTARGET* = 11 233 CONFIG_UTF32* = 12 234 CONFIG_PARENS_LIMIT* = 13 235 236# Request types for pcre_study(). Do not re-arrange, in order to remain 237# compatible. 238const 239 STUDY_JIT_COMPILE* = 0x0001 240 STUDY_JIT_PARTIAL_SOFT_COMPILE* = 0x0002 241 STUDY_JIT_PARTIAL_HARD_COMPILE* = 0x0004 242 STUDY_EXTRA_NEEDED* = 0x0008 243 244# Bit flags for the pcre[16|32]_extra structure. Do not re-arrange or redefine 245# these bits, just add new ones on the end, in order to remain compatible. 246const 247 EXTRA_STUDY_DATA* = 0x0001 248 EXTRA_MATCH_LIMIT* = 0x0002 249 EXTRA_CALLOUT_DATA* = 0x0004 250 EXTRA_TABLES* = 0x0008 251 EXTRA_MATCH_LIMIT_RECURSION* = 0x0010 252 EXTRA_MARK* = 0x0020 253 EXTRA_EXECUTABLE_JIT* = 0x0040 254 255# Types 256type 257 Pcre* = object 258 Pcre16* = object 259 Pcre32* = object 260 JitStack* = object 261 JitStack16* = object 262 JitStack32* = object 263 264when defined(nimHasStyleChecks): 265 {.push styleChecks: off.} 266 267# The structure for passing additional data to pcre_exec(). This is defined in 268# such as way as to be extensible. Always add new fields at the end, in order 269# to remain compatible. 270type 271 ExtraData* = object 272 flags*: clong ## Bits for which fields are set 273 study_data*: pointer ## Opaque data from pcre_study() 274 match_limit*: clong ## Maximum number of calls to match() 275 callout_data*: pointer ## Data passed back in callouts 276 tables*: pointer ## Pointer to character tables 277 match_limit_recursion*: clong ## Max recursive calls to match() 278 mark*: pointer ## For passing back a mark pointer 279 executable_jit*: pointer ## Contains a pointer to a compiled jit code 280 281# The structure for passing out data via the pcre_callout_function. We use a 282# structure so that new fields can be added on the end in future versions, 283# without changing the API of the function, thereby allowing old clients to 284# work without modification. 285type 286 CalloutBlock* = object 287 version* : cint ## Identifies version of block 288 # ------------------------ Version 0 ------------------------------- 289 callout_number* : cint ## Number compiled into pattern 290 offset_vector* : ptr cint ## The offset vector 291 subject* : cstring ## The subject being matched 292 subject_length* : cint ## The length of the subject 293 start_match* : cint ## Offset to start of this match attempt 294 current_position*: cint ## Where we currently are in the subject 295 capture_top* : cint ## Max current capture 296 capture_last* : cint ## Most recently closed capture 297 callout_data* : pointer ## Data passed in with the call 298 # ------------------- Added for Version 1 -------------------------- 299 pattern_position*: cint ## Offset to next item in the pattern 300 next_item_length*: cint ## Length of next item in the pattern 301 # ------------------- Added for Version 2 -------------------------- 302 mark* : pointer ## Pointer to current mark or NULL 303 # ------------------------------------------------------------------ 304 305when defined(nimHasStyleChecks): 306 {.pop.} 307 308# User defined callback which provides a stack just before the match starts. 309type 310 JitCallback* = proc (a: pointer): ptr JitStack {.cdecl.} 311 312 313when not defined(usePcreHeader): 314 when hostOS == "windows": 315 when defined(nimOldDlls): 316 const pcreDll = "pcre.dll" 317 elif defined(cpu64): 318 const pcreDll = "pcre64.dll" 319 else: 320 const pcreDll = "pcre32.dll" 321 elif hostOS == "macosx": 322 const pcreDll = "libpcre(.3|.1|).dylib" 323 else: 324 const pcreDll = "libpcre.so(.3|.1|)" 325 {.push dynlib: pcreDll.} 326else: 327 {.push header: "<pcre.h>".} 328 329{.push cdecl, importc: "pcre_$1".} 330 331# Exported PCRE functions 332 333proc compile*(pattern: cstring, 334 options: cint, 335 errptr: ptr cstring, 336 erroffset: ptr cint, 337 tableptr: pointer): ptr Pcre 338 339proc compile2*(pattern: cstring, 340 options: cint, 341 errorcodeptr: ptr cint, 342 errptr: ptr cstring, 343 erroffset: ptr cint, 344 tableptr: pointer): ptr Pcre 345 346proc config*(what: cint, 347 where: pointer): cint 348 349proc copy_named_substring*(code: ptr Pcre, 350 subject: cstring, 351 ovector: ptr cint, 352 stringcount: cint, 353 stringname: cstring, 354 buffer: cstring, 355 buffersize: cint): cint 356 357proc copy_substring*(subject: cstring, 358 ovector: ptr cint, 359 stringcount: cint, 360 stringnumber: cint, 361 buffer: cstring, 362 buffersize: cint): cint 363 364proc dfa_exec*(code: ptr Pcre, 365 extra: ptr ExtraData, 366 subject: cstring, 367 length: cint, 368 startoffset: cint, 369 options: cint, 370 ovector: ptr cint, 371 ovecsize: cint, 372 workspace: ptr cint, 373 wscount: cint): cint 374 375proc exec*(code: ptr Pcre, 376 extra: ptr ExtraData, 377 subject: cstring, 378 length: cint, 379 startoffset: cint, 380 options: cint, 381 ovector: ptr cint, 382 ovecsize: cint): cint 383 384proc jit_exec*(code: ptr Pcre, 385 extra: ptr ExtraData, 386 subject: cstring, 387 length: cint, 388 startoffset: cint, 389 options: cint, 390 ovector: ptr cint, 391 ovecsize: cint, 392 jstack: ptr JitStack): cint 393 394proc free_substring*(stringptr: cstring) 395 396proc free_substring_list*(stringptr: cstringArray) 397 398proc fullinfo*(code: ptr Pcre, 399 extra: ptr ExtraData, 400 what: cint, 401 where: pointer): cint 402 403proc get_named_substring*(code: ptr Pcre, 404 subject: cstring, 405 ovector: ptr cint, 406 stringcount: cint, 407 stringname: cstring, 408 stringptr: cstringArray): cint 409 410proc get_stringnumber*(code: ptr Pcre, 411 name: cstring): cint 412 413proc get_stringtable_entries*(code: ptr Pcre, 414 name: cstring, 415 first: cstringArray, 416 last: cstringArray): cint 417 418proc get_substring*(subject: cstring, 419 ovector: ptr cint, 420 stringcount: cint, 421 stringnumber: cint, 422 stringptr: cstringArray): cint 423 424proc get_substring_list*(subject: cstring, 425 ovector: ptr cint, 426 stringcount: cint, 427 listptr: ptr cstringArray): cint 428 429proc maketables*(): pointer 430 431proc refcount*(code: ptr Pcre, 432 adjust: cint): cint 433 434proc study*(code: ptr Pcre, 435 options: cint, 436 errptr: ptr cstring): ptr ExtraData 437 438proc free_study*(extra: ptr ExtraData) 439 440proc version*(): cstring 441 442# Utility functions for byte order swaps. 443 444proc pattern_to_host_byte_order*(code: ptr Pcre, 445 extra: ptr ExtraData, 446 tables: pointer): cint 447 448# JIT compiler related functions. 449 450proc jit_stack_alloc*(startsize: cint, 451 maxsize: cint): ptr JitStack 452 453proc jit_stack_free*(stack: ptr JitStack) 454 455proc assign_jit_stack*(extra: ptr ExtraData, 456 callback: JitCallback, 457 data: pointer) 458 459proc jit_free_unused_memory*() 460 461 462# There was an odd function with `var cstring` instead of `ptr` 463proc study*(code: ptr Pcre, 464 options: cint, 465 errptr: var cstring): ptr ExtraData {.deprecated.} 466 467{.pop.} 468{.pop.} 469 470 471type 472 PPcre* {.deprecated.} = ptr Pcre 473 PJitStack* {.deprecated.} = ptr JitStack 474