MCPcopy Create free account
hub / github.com/boostorg/build / regpiece

Function regpiece

src/engine/regexp.cpp:417–470  ·  view source on GitHub ↗

- regpiece - something followed by possible [*+?] * * Note that the branching code sequences used for ? and the general cases * of * and + are somewhat optimized: they use the same NOTHING node as * both the endmarker for their branch list and the body of the last branch. * It might seem that this node could be dispensed with entirely, but the * endmarker role is not redundant. */

Source from the content-addressed store, hash-verified

415 * endmarker role is not redundant.
416 */
417static char *
418regpiece( int32_t *flagp )
419{
420 char *ret;
421 char op;
422 char *next;
423 int32_t flags;
424
425 ret = regatom(&flags);
426 if (ret == NULL)
427 return(NULL);
428
429 op = *regparse;
430 if (!ISMULT(op)) {
431 *flagp = flags;
432 return(ret);
433 }
434
435 if (!(flags&HASWIDTH) && op != '?')
436 FAIL("*+ operand could be empty");
437 *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH);
438
439 if (op == '*' && (flags&SIMPLE))
440 reginsert(STAR, ret);
441 else if (op == '*') {
442 /* Emit x* as (x&|), where & means "self". */
443 reginsert(BRANCH, ret); /* Either x */
444 regoptail(ret, regnode(BACK)); /* and loop */
445 regoptail(ret, ret); /* back */
446 regtail(ret, regnode(BRANCH)); /* or */
447 regtail(ret, regnode(NOTHING)); /* null. */
448 } else if (op == '+' && (flags&SIMPLE))
449 reginsert(PLUS, ret);
450 else if (op == '+') {
451 /* Emit x+ as x(&|), where & means "self". */
452 next = regnode(BRANCH); /* Either */
453 regtail(ret, next);
454 regtail(regnode(BACK), ret); /* loop back */
455 regtail(next, regnode(BRANCH)); /* or */
456 regtail(ret, regnode(NOTHING)); /* null. */
457 } else if (op == '?') {
458 /* Emit x? as (x|) */
459 reginsert(BRANCH, ret); /* Either x */
460 regtail(ret, regnode(BRANCH)); /* or */
461 next = regnode(NOTHING); /* null. */
462 regtail(ret, next);
463 regoptail(ret, next);
464 }
465 regparse++;
466 if (ISMULT(*regparse))
467 FAIL("nested *?+");
468
469 return(ret);
470}
471
472/*
473 - regatom - the lowest level

Callers 1

regbranchFunction · 0.85

Calls 5

regatomFunction · 0.85
reginsertFunction · 0.85
regoptailFunction · 0.85
regnodeFunction · 0.85
regtailFunction · 0.85

Tested by

no test coverage detected