(source, state, verbose, nested, first=False)
| 510 | return subpattern |
| 511 | |
| 512 | def _parse(source, state, verbose, nested, first=False): |
| 513 | # parse a simple pattern |
| 514 | subpattern = SubPattern(state) |
| 515 | |
| 516 | # precompute constants into local variables |
| 517 | subpatternappend = subpattern.append |
| 518 | sourceget = source.get |
| 519 | sourcematch = source.match |
| 520 | _len = len |
| 521 | _ord = ord |
| 522 | |
| 523 | while True: |
| 524 | |
| 525 | this = source.next |
| 526 | if this is None: |
| 527 | break # end of pattern |
| 528 | if this in "|)": |
| 529 | break # end of subpattern |
| 530 | sourceget() |
| 531 | |
| 532 | if verbose: |
| 533 | # skip whitespace and comments |
| 534 | if this in WHITESPACE: |
| 535 | continue |
| 536 | if this == "#": |
| 537 | while True: |
| 538 | this = sourceget() |
| 539 | if this is None or this == "\n": |
| 540 | break |
| 541 | continue |
| 542 | |
| 543 | if this[0] == "\\": |
| 544 | code = _escape(source, this, state) |
| 545 | subpatternappend(code) |
| 546 | |
| 547 | elif this not in SPECIAL_CHARS: |
| 548 | subpatternappend((LITERAL, _ord(this))) |
| 549 | |
| 550 | elif this == "[": |
| 551 | here = source.tell() - 1 |
| 552 | # character set |
| 553 | set = [] |
| 554 | setappend = set.append |
| 555 | ## if sourcematch(":"): |
| 556 | ## pass # handle character classes |
| 557 | if source.next == '[': |
| 558 | import warnings |
| 559 | warnings.warn( |
| 560 | 'Possible nested set at position %d' % source.tell(), |
| 561 | FutureWarning, stacklevel=nested + 6 |
| 562 | ) |
| 563 | negate = sourcematch("^") |
| 564 | # check remaining characters |
| 565 | while True: |
| 566 | this = sourceget() |
| 567 | if this is None: |
| 568 | raise source.error("unterminated character set", |
| 569 | source.tell() - here) |
no test coverage detected