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