2 * Regular expression structs, constants, and bytecode defines.
5 #ifndef DUK_REGEXP_H_INCLUDED
6 #define DUK_REGEXP_H_INCLUDED
8 /* maximum bytecode copies for {n,m} quantifiers */
9 #define DUK_RE_MAX_ATOM_COPIES 1000
11 /* regexp compilation limits */
12 #define DUK_RE_COMPILE_TOKEN_LIMIT 100000000L /* 1e8 */
14 /* regexp execution limits */
15 #define DUK_RE_EXECUTE_STEPS_LIMIT 1000000000L /* 1e9 */
18 #define DUK_REOP_MATCH 1
19 #define DUK_REOP_CHAR 2
20 #define DUK_REOP_PERIOD 3
21 #define DUK_REOP_RANGES 4
22 #define DUK_REOP_INVRANGES 5
23 #define DUK_REOP_JUMP 6
24 #define DUK_REOP_SPLIT1 7
25 #define DUK_REOP_SPLIT2 8
26 #define DUK_REOP_SQMINIMAL 9
27 #define DUK_REOP_SQGREEDY 10
28 #define DUK_REOP_SAVE 11
29 #define DUK_REOP_WIPERANGE 12
30 #define DUK_REOP_LOOKPOS 13
31 #define DUK_REOP_LOOKNEG 14
32 #define DUK_REOP_BACKREFERENCE 15
33 #define DUK_REOP_ASSERT_START 16
34 #define DUK_REOP_ASSERT_END 17
35 #define DUK_REOP_ASSERT_WORD_BOUNDARY 18
36 #define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY 19
39 #define DUK_RE_FLAG_GLOBAL (1 << 0)
40 #define DUK_RE_FLAG_IGNORE_CASE (1 << 1)
41 #define DUK_RE_FLAG_MULTILINE (1 << 2)
43 struct duk_re_matcher_ctx
{
46 duk_uint32_t re_flags
;
47 const duk_uint8_t
*input
;
48 const duk_uint8_t
*input_end
;
49 const duk_uint8_t
*bytecode
;
50 const duk_uint8_t
*bytecode_end
;
51 const duk_uint8_t
**saved
; /* allocated from valstack (fixed buffer) */
53 duk_uint32_t recursion_depth
;
54 duk_uint32_t recursion_limit
;
55 duk_uint32_t steps_count
;
56 duk_uint32_t steps_limit
;
59 struct duk_re_compiler_ctx
{
62 duk_uint32_t re_flags
;
64 duk_re_token curr_token
;
66 duk_uint32_t captures
; /* highest capture number emitted so far (used as: ++captures) */
67 duk_uint32_t highest_backref
;
68 duk_uint32_t recursion_depth
;
69 duk_uint32_t recursion_limit
;
70 duk_uint32_t nranges
; /* internal temporary value, used for char classes */
77 DUK_INTERNAL_DECL
void duk_regexp_compile(duk_hthread
*thr
);
78 DUK_INTERNAL_DECL
void duk_regexp_create_instance(duk_hthread
*thr
);
79 DUK_INTERNAL_DECL
void duk_regexp_match(duk_hthread
*thr
);
80 DUK_INTERNAL_DECL
void duk_regexp_match_force_global(duk_hthread
*thr
); /* hacky helper for String.prototype.split() */
82 #endif /* DUK_REGEXP_H_INCLUDED */