MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxCompileRegExp

Function fxCompileRegExp

xs/sources/xsre.c:2476–2595  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2474}
2475
2476txBoolean fxCompileRegExp(void* the, txString pattern, txString modifier, txInteger** code, txInteger** data, txString messageBuffer, txInteger messageSize)
2477{
2478 txBoolean result = 1;
2479 txPatternParser _parser;
2480 txPatternParser* parser = &_parser;
2481 txTerm* term;
2482
2483 fxPatternParserInitialize(parser);
2484 if (c_setjmp(parser->jmp_buf) == 0) {
2485 char c;
2486 while ((c = c_read8(modifier++))) {
2487 if ((c == 'g') && !(parser->flags & XS_REGEXP_G))
2488 parser->flags |= XS_REGEXP_G;
2489 else if ((c == 'i') && !(parser->flags & XS_REGEXP_I))
2490 parser->flags |= XS_REGEXP_I;
2491 else if ((c == 'm') && !(parser->flags & XS_REGEXP_M))
2492 parser->flags |= XS_REGEXP_M;
2493 else if ((c == 's') && !(parser->flags & XS_REGEXP_S))
2494 parser->flags |= XS_REGEXP_S;
2495 else if ((c == 'u') && !(parser->flags & XS_REGEXP_U) && !(parser->flags & XS_REGEXP_V))
2496 parser->flags |= XS_REGEXP_U;
2497 else if ((c == 'y') && !(parser->flags & XS_REGEXP_Y))
2498 parser->flags |= XS_REGEXP_Y;
2499 else if ((c == 'd') && !(parser->flags & XS_REGEXP_D))
2500 parser->flags |= XS_REGEXP_D;
2501 else if ((c == 'v') && !(parser->flags & XS_REGEXP_U) && !(parser->flags & XS_REGEXP_V))
2502 parser->flags |= XS_REGEXP_V;
2503 else
2504 break;
2505 }
2506 if (c)
2507 fxPatternParserError(parser, gxErrors[mxInvalidFlags]);
2508 parser->pattern = pattern;
2509 parser->the = the;
2510 parser->stackLimit = fxCStackLimit();
2511 fxPatternParserNext(parser);
2512 term = fxDisjunctionParse(parser, C_EOF);
2513 if (parser->firstNamedCapture)
2514 parser->flags |= XS_REGEXP_N;
2515 if (!(parser->flags & XS_REGEXP_UV) && (parser->flags & XS_REGEXP_N)) {
2516 fxPatternParserTerminate(parser);
2517 parser->offset = 0;
2518 parser->surrogate = 0;
2519 parser->assertionIndex = 0;
2520 parser->captureIndex = 0;
2521 parser->nameIndex = 0;
2522 parser->quantifierIndex = 0;
2523 parser->firstCaptureName = NULL;
2524 parser->firstNamedCapture = NULL;
2525 parser->lastNamedCapture = NULL;
2526 fxPatternParserNext(parser);
2527 term = fxDisjunctionParse(parser, C_EOF);
2528 }
2529 parser->captureIndex++;
2530 if (!term)
2531 fxPatternParserError(parser, gxErrors[mxInvalidPattern]);
2532 parser->size = (5 + parser->nameIndex) * sizeof(txInteger);
2533 (*term->dispatch.measure)(parser, term, 1);

Callers 6

PiuCode_searchFunction · 0.85
PiuCode_findFunction · 0.85
mainFunction · 0.85
fxGetNextRegExpFunction · 0.85
fxInitializeRegExpFunction · 0.85

Calls 8

fxPatternParserErrorFunction · 0.85
fxCStackLimitFunction · 0.85
fxPatternParserNextFunction · 0.85
fxDisjunctionParseFunction · 0.85
fxPatternParserTerminateFunction · 0.85
fxNewChunkFunction · 0.85
fxAbortFunction · 0.70

Tested by

no test coverage detected