Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
duk_regexp.h File Reference

Go to the source code of this file.

Data Structures

struct  duk_re_matcher_ctx
 
struct  duk_re_compiler_ctx
 

Macros

#define DUK_RE_MAX_ATOM_COPIES   1000
 
#define DUK_RE_COMPILE_TOKEN_LIMIT   100000000L /* 1e8 */
 
#define DUK_RE_EXECUTE_STEPS_LIMIT   1000000000L /* 1e9 */
 
#define DUK_REOP_MATCH   1
 
#define DUK_REOP_CHAR   2
 
#define DUK_REOP_PERIOD   3
 
#define DUK_REOP_RANGES   4
 
#define DUK_REOP_INVRANGES   5
 
#define DUK_REOP_JUMP   6
 
#define DUK_REOP_SPLIT1   7
 
#define DUK_REOP_SPLIT2   8
 
#define DUK_REOP_SQMINIMAL   9
 
#define DUK_REOP_SQGREEDY   10
 
#define DUK_REOP_SAVE   11
 
#define DUK_REOP_WIPERANGE   12
 
#define DUK_REOP_LOOKPOS   13
 
#define DUK_REOP_LOOKNEG   14
 
#define DUK_REOP_BACKREFERENCE   15
 
#define DUK_REOP_ASSERT_START   16
 
#define DUK_REOP_ASSERT_END   17
 
#define DUK_REOP_ASSERT_WORD_BOUNDARY   18
 
#define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY   19
 
#define DUK_RE_FLAG_GLOBAL   (1 << 0)
 
#define DUK_RE_FLAG_IGNORE_CASE   (1 << 1)
 
#define DUK_RE_FLAG_MULTILINE   (1 << 2)
 

Functions

DUK_INTERNAL_DECL void duk_regexp_compile (duk_hthread *thr)
 
DUK_INTERNAL_DECL void duk_regexp_create_instance (duk_hthread *thr)
 
DUK_INTERNAL_DECL void duk_regexp_match (duk_hthread *thr)
 
DUK_INTERNAL_DECL void duk_regexp_match_force_global (duk_hthread *thr)
 

Macro Definition Documentation

◆ DUK_RE_COMPILE_TOKEN_LIMIT

#define DUK_RE_COMPILE_TOKEN_LIMIT   100000000L /* 1e8 */

Definition at line 12 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_RE_EXECUTE_STEPS_LIMIT

#define DUK_RE_EXECUTE_STEPS_LIMIT   1000000000L /* 1e9 */

Definition at line 15 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_RE_FLAG_GLOBAL

#define DUK_RE_FLAG_GLOBAL   (1 << 0)

Definition at line 39 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_RE_FLAG_IGNORE_CASE

#define DUK_RE_FLAG_IGNORE_CASE   (1 << 1)

Definition at line 40 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_RE_FLAG_MULTILINE

#define DUK_RE_FLAG_MULTILINE   (1 << 2)

Definition at line 41 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_RE_MAX_ATOM_COPIES

#define DUK_RE_MAX_ATOM_COPIES   1000

Definition at line 9 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_ASSERT_END

#define DUK_REOP_ASSERT_END   17

Definition at line 34 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_ASSERT_NOT_WORD_BOUNDARY

#define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY   19

Definition at line 36 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_ASSERT_START

#define DUK_REOP_ASSERT_START   16

Definition at line 33 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_ASSERT_WORD_BOUNDARY

#define DUK_REOP_ASSERT_WORD_BOUNDARY   18

Definition at line 35 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_BACKREFERENCE

#define DUK_REOP_BACKREFERENCE   15

Definition at line 32 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_CHAR

#define DUK_REOP_CHAR   2

Definition at line 19 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_INVRANGES

#define DUK_REOP_INVRANGES   5

Definition at line 22 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_JUMP

#define DUK_REOP_JUMP   6

Definition at line 23 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_LOOKNEG

#define DUK_REOP_LOOKNEG   14

Definition at line 31 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_LOOKPOS

#define DUK_REOP_LOOKPOS   13

Definition at line 30 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_MATCH

#define DUK_REOP_MATCH   1

Definition at line 18 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_PERIOD

#define DUK_REOP_PERIOD   3

Definition at line 20 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_RANGES

#define DUK_REOP_RANGES   4

Definition at line 21 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_SAVE

#define DUK_REOP_SAVE   11

Definition at line 28 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_SPLIT1

#define DUK_REOP_SPLIT1   7

Definition at line 24 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_SPLIT2

#define DUK_REOP_SPLIT2   8

Definition at line 25 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_SQGREEDY

#define DUK_REOP_SQGREEDY   10

Definition at line 27 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_SQMINIMAL

#define DUK_REOP_SQMINIMAL   9

Definition at line 26 of file duktape-1.5.2/src-separate/duk_regexp.h.

◆ DUK_REOP_WIPERANGE

#define DUK_REOP_WIPERANGE   12

Definition at line 29 of file duktape-1.5.2/src-separate/duk_regexp.h.

Function Documentation

◆ duk_regexp_compile()

DUK_INTERNAL_DECL void duk_regexp_compile ( duk_hthread * thr)

Definition at line 78146 of file duktape-1.5.2/src-noline/duktape.c.

78163 {
78164 duk_context *ctx = (duk_context *) thr;
78165 duk_re_compiler_ctx re_ctx;
78166 duk_lexer_point lex_point;
78167 duk_hstring *h_pattern;
78168 duk_hstring *h_flags;
78169 duk__re_disjunction_info ign_disj;
78170
78171 DUK_ASSERT(thr != NULL);
78172 DUK_ASSERT(ctx != NULL);
78173
78174 /*
78175 * Args validation
78176 */
78177
78178 /* TypeError if fails */
78179 h_pattern = duk_require_hstring(ctx, -2);
78180 h_flags = duk_require_hstring(ctx, -1);
78181
78182 /*
78183 * Create normalized 'source' property (E5 Section 15.10.3).
78184 */
78185
78186 /* [ ... pattern flags ] */
78187
78189
78190 /* [ ... pattern flags escaped_source ] */
78191
78192 /*
78193 * Init compilation context
78194 */
78195
78196 /* [ ... pattern flags escaped_source buffer ] */
78197
78198 DUK_MEMZERO(&re_ctx, sizeof(re_ctx));
78199 DUK_LEXER_INITCTX(&re_ctx.lex); /* duplicate zeroing, expect for (possible) NULL inits */
78200 re_ctx.thr = thr;
78201 re_ctx.lex.thr = thr;
78202 re_ctx.lex.input = DUK_HSTRING_GET_DATA(h_pattern);
78203 re_ctx.lex.input_length = DUK_HSTRING_GET_BYTELEN(h_pattern);
78206 re_ctx.re_flags = duk__parse_regexp_flags(thr, h_flags);
78207
78209
78210 DUK_DD(DUK_DDPRINT("regexp compiler ctx initialized, flags=0x%08lx, recursion_limit=%ld",
78211 (unsigned long) re_ctx.re_flags, (long) re_ctx.recursion_limit));
78212
78213 /*
78214 * Init lexer
78215 */
78216
78217 lex_point.offset = 0; /* expensive init, just want to fill window */
78218 lex_point.line = 1;
78219 DUK_LEXER_SETPOINT(&re_ctx.lex, &lex_point);
78220
78221 /*
78222 * Compilation
78223 */
78224
78225 DUK_DD(DUK_DDPRINT("starting regexp compilation"));
78226
78228 duk__append_u32(&re_ctx, 0);
78229 duk__parse_disjunction(&re_ctx, 1 /*expect_eof*/, &ign_disj);
78231 duk__append_u32(&re_ctx, 1);
78233
78234 /*
78235 * Check for invalid backreferences; note that it is NOT an error
78236 * to back-reference a capture group which has not yet been introduced
78237 * in the pattern (as in /\1(foo)/); in fact, the backreference will
78238 * always match! It IS an error to back-reference a capture group
78239 * which will never be introduced in the pattern. Thus, we can check
78240 * for such references only after parsing is complete.
78241 */
78242
78243 if (re_ctx.highest_backref > re_ctx.captures) {
78245 }
78246
78247 /*
78248 * Emit compiled regexp header: flags, ncaptures
78249 * (insertion order inverted on purpose)
78250 */
78251
78252 duk__insert_u32(&re_ctx, 0, (re_ctx.captures + 1) * 2);
78253 duk__insert_u32(&re_ctx, 0, re_ctx.re_flags);
78254
#define DUK_USE_REGEXP_COMPILER_RECLIMIT
#define DUK_MEMZERO(p, n)
#define DUK_HSTRING_GET_DATA(x)
DUK_LOCAL duk_uint32_t duk__parse_regexp_flags(duk_hthread *thr, duk_hstring *h)
#define DUK_ERROR_SYNTAX(thr, msg)
#define DUK_LEXER_INITCTX(ctx)
#define DUK_RE_COMPILE_TOKEN_LIMIT
#define DUK_LEXER_SETPOINT(ctx, pt)
#define DUK_HSTRING_GET_BYTELEN(x)
#define DUK_BW_INIT_PUSHBUF(thr, bw_ctx, sz)
DUK_LOCAL void duk__parse_disjunction(duk_re_compiler_ctx *re_ctx, duk_bool_t expect_eof, duk__re_disjunction_info *out_atom_info)
DUK_LOCAL void duk__create_escaped_source(duk_hthread *thr, int idx_pattern)
DUK_INTERNAL_DECL duk_hstring * duk_require_hstring(duk_context *ctx, duk_idx_t index)
#define DUK__RE_INITIAL_BUFSIZE
DUK_LOCAL duk_uint32_t duk__append_u32(duk_re_compiler_ctx *re_ctx, duk_uint32_t x)
DUK_LOCAL duk_uint32_t duk__insert_u32(duk_re_compiler_ctx *re_ctx, duk_uint32_t offset, duk_uint32_t x)
#define DUK_STR_INVALID_BACKREFS
#define NULL
Definition gmacros.h:924

◆ duk_regexp_create_instance()

DUK_INTERNAL_DECL void duk_regexp_create_instance ( duk_hthread * thr)

Definition at line 78266 of file duktape-1.5.2/src-noline/duktape.c.

78269 : %!T, escaped source: %!T",
78270 (duk_tval *) duk_get_tval(ctx, -1), (duk_tval *) duk_get_tval(ctx, -2)));
78271}
78272
78273/*
78274 * Create a RegExp instance (E5 Section 15.10.7).
78275 *
78276 * Note: the output stack left by duk_regexp_compile() is directly compatible
78277 * with the input here.
78278 *
78279 * Input stack: [ escaped_source bytecode ] (both as strings)
78280 * Output stack: [ RegExp ]
78281 */
78282
78283DUK_INTERNAL void duk_regexp_create_instance(duk_hthread *thr) {
78284 duk_context *ctx = (duk_context *) thr;
78285 duk_hobject *h;
78286 duk_hstring *h_bc;
78287 duk_small_int_t re_flags;
78288
78289 /* [ ... escape_source bytecode ] */
78290
78291 h_bc = duk_get_hstring(ctx, -1);
78292 DUK_ASSERT(h_bc != NULL);
78293 DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h_bc) >= 1); /* always at least the header */
78294 DUK_ASSERT(DUK_HSTRING_GET_CHARLEN(h_bc) >= 1);
78295 DUK_ASSERT((duk_small_int_t) DUK_HSTRING_GET_DATA(h_bc)[0] < 0x80); /* flags always encodes to 1 byte */
78296 re_flags = (duk_small_int_t) DUK_HSTRING_GET_DATA(h_bc)[0];
78297
78298 /* [ ... escaped_source bytecode ] */
78299
78300 duk_push_object(ctx);
78301 h = duk_get_hobject(ctx, -1);
78302 DUK_ASSERT(h != NULL);
78303 duk_insert(ctx, -3);
78304
78305 /* [ ... regexp_object escaped_source bytecode ] */
78306
78307 DUK_HOBJECT_SET_CLASS_NUMBER(h, DUK_HOBJECT_CLASS_REGEXP);
78308 DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, thr->builtins[DUK_BIDX_REGEXP_PROTOTYPE]);
78309
78310 duk_xdef_prop_stridx(ctx, -3, DUK_STRIDX_INT_BYTECODE, DUK_PROPDESC_FLAGS_NONE);
78311
78312 /* [ ... regexp_object escaped_source ] */
78313
78314 duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_SOURCE, DUK_PROPDESC_FLAGS_NONE);

◆ duk_regexp_match()

DUK_INTERNAL_DECL void duk_regexp_match ( duk_hthread * thr)

Definition at line 79315 of file duktape-1.5.2/src-noline/duktape.c.

◆ duk_regexp_match_force_global()

DUK_INTERNAL_DECL void duk_regexp_match_force_global ( duk_hthread * thr)

Definition at line 79322 of file duktape-1.5.2/src-noline/duktape.c.