MCPcopy Create free account
hub / github.com/RustPython/RustPython / _parse

Function _parse

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

Source from the content-addressed store, hash-verified

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

Callers 1

_parse_subFunction · 0.70

Calls 15

SubPatternClass · 0.85
_class_escapeFunction · 0.85
lenFunction · 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
opengroupMethod · 0.80
closegroupMethod · 0.80

Tested by

no test coverage detected