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

Function parse

Lib/re/_parser.py:962–987  ·  view source on GitHub ↗
(str, flags=0, state=None)

Source from the content-addressed store, hash-verified

960 return flags
961
962def parse(str, flags=0, state=None):
963 # parse 're' pattern into list of (opcode, argument) tuples
964
965 source = Tokenizer(str)
966
967 if state is None:
968 state = State()
969 state.flags = flags
970 state.str = str
971
972 p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
973 p.state.flags = fix_flags(str, p.state.flags)
974
975 if source.next is not None:
976 assert source.next == ")"
977 raise source.error("unbalanced parenthesis")
978
979 for g in p.state.grouprefpos:
980 if g >= p.state.groups:
981 msg = "invalid group reference %d" % g
982 raise error(msg, str, p.state.grouprefpos[g])
983
984 if flags & SRE_FLAG_DEBUG:
985 p.dump()
986
987 return p
988
989def parse_template(source, pattern):
990 # parse 're' replacement string into list of literals and

Callers 10

test_formatter_parserMethod · 0.50
test_parse_memlimitMethod · 0.50
test_basicMethod · 0.50
test_positional_onlyMethod · 0.50
test_nested_sequenceMethod · 0.50

Calls 7

errorMethod · 0.95
_parse_subFunction · 0.85
fix_flagsFunction · 0.85
TokenizerClass · 0.70
StateClass · 0.70
errorClass · 0.50
dumpMethod · 0.45

Tested by 10

test_formatter_parserMethod · 0.40
test_parse_memlimitMethod · 0.40
test_basicMethod · 0.40
test_positional_onlyMethod · 0.40
test_nested_sequenceMethod · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…