MCPcopy Index your code
hub / github.com/python/cpython / _parse

Function _parse

Lib/re/_parser.py:511–884  ·  view source on GitHub ↗
(source, state, verbose, nested, first=False)

Source from the content-addressed store, hash-verified

509 return subpattern
510
511def _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)

Callers 1

_parse_subFunction · 0.70

Calls 15

SubPatternClass · 0.85
_class_escapeFunction · 0.85
_uniqFunction · 0.85
_parse_subFunction · 0.85
_parse_flagsFunction · 0.85
getuntilMethod · 0.80
checkgroupnameMethod · 0.80
checkgroupMethod · 0.80
checklookbehindgroupMethod · 0.80
isdecimalMethod · 0.80
isasciiMethod · 0.80
opengroupMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…