- regatom - the lowest level * * Optimization: gobbles an entire sequence of ordinary characters so that * it can turn them into a single node, which is smaller to store and * faster to run. Backslashed characters are exceptions, each becoming a * separate node; the code is simpler that way and it's not worth fixing. */
| 478 | * separate node; the code is simpler that way and it's not worth fixing. |
| 479 | */ |
| 480 | static char * |
| 481 | regatom( int32_t *flagp ) |
| 482 | { |
| 483 | char *ret; |
| 484 | int32_t flags; |
| 485 | |
| 486 | *flagp = WORST; /* Tentatively. */ |
| 487 | |
| 488 | switch (*regparse++) { |
| 489 | /* FIXME: these chars only have meaning at beg/end of pat? */ |
| 490 | case '^': |
| 491 | ret = regnode(BOL); |
| 492 | break; |
| 493 | case '$': |
| 494 | ret = regnode(EOL); |
| 495 | break; |
| 496 | case '.': |
| 497 | ret = regnode(ANY); |
| 498 | *flagp |= HASWIDTH|SIMPLE; |
| 499 | break; |
| 500 | case '[': { |
| 501 | int32_t classr; |
| 502 | int32_t classend; |
| 503 | |
| 504 | if (*regparse == '^') { /* Complement of range. */ |
| 505 | ret = regnode(ANYBUT); |
| 506 | regparse++; |
| 507 | } else |
| 508 | ret = regnode(ANYOF); |
| 509 | if (*regparse == ']' || *regparse == '-') |
| 510 | regc(*regparse++); |
| 511 | while (*regparse != '\0' && *regparse != ']') { |
| 512 | if (*regparse == '-') { |
| 513 | regparse++; |
| 514 | if (*regparse == ']' || *regparse == '\0') |
| 515 | regc('-'); |
| 516 | else { |
| 517 | classr = UCHARAT(regparse-2)+1; |
| 518 | classend = UCHARAT(regparse); |
| 519 | if (classr > classend+1) |
| 520 | FAIL("invalid [] range"); |
| 521 | for (; classr <= classend; classr++) |
| 522 | regc(classr); |
| 523 | regparse++; |
| 524 | } |
| 525 | } else |
| 526 | regc(*regparse++); |
| 527 | } |
| 528 | regc('\0'); |
| 529 | if (*regparse != ']') |
| 530 | FAIL("unmatched []"); |
| 531 | regparse++; |
| 532 | *flagp |= HASWIDTH|SIMPLE; |
| 533 | } |
| 534 | break; |
| 535 | case '(': |
| 536 | ret = reg(1, &flags); |
| 537 | if (ret == NULL) |