MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _compile_info

Function _compile_info

tools/python-3.11.9-amd64/Lib/re/_compiler.py:511–568  ·  view source on GitHub ↗
(code, pattern, flags)

Source from the content-addressed store, hash-verified

509 return None
510
511def _compile_info(code, pattern, flags):
512 # internal: compile an info block. in the current version,
513 # this contains min/max pattern width, and an optional literal
514 # prefix or a character map
515 lo, hi = pattern.getwidth()
516 if hi > MAXCODE:
517 hi = MAXCODE
518 if lo == 0:
519 code.extend([INFO, 4, 0, lo, hi])
520 return
521 # look for a literal prefix
522 prefix = []
523 prefix_skip = 0
524 charset = [] # not used
525 if not (flags & SRE_FLAG_IGNORECASE and flags & SRE_FLAG_LOCALE):
526 # look for literal prefix
527 prefix, prefix_skip, got_all = _get_literal_prefix(pattern, flags)
528 # if no prefix, look for charset prefix
529 if not prefix:
530 charset = _get_charset_prefix(pattern, flags)
531## if prefix:
532## print("*** PREFIX", prefix, prefix_skip)
533## if charset:
534## print("*** CHARSET", charset)
535 # add an info block
536 emit = code.append
537 emit(INFO)
538 skip = len(code); emit(0)
539 # literal flag
540 mask = 0
541 if prefix:
542 mask = SRE_INFO_PREFIX
543 if prefix_skip is None and got_all:
544 mask = mask | SRE_INFO_LITERAL
545 elif charset:
546 mask = mask | SRE_INFO_CHARSET
547 emit(mask)
548 # pattern length
549 if lo < MAXCODE:
550 emit(lo)
551 else:
552 emit(MAXCODE)
553 prefix = prefix[:MAXCODE]
554 emit(hi)
555 # add literal prefix
556 if prefix:
557 emit(len(prefix)) # length
558 if prefix_skip is None:
559 prefix_skip = len(prefix)
560 emit(prefix_skip) # skip
561 code.extend(prefix)
562 # generate overlap table
563 code.extend(_generate_overlap_table(prefix))
564 elif charset:
565 charset, hascased = _optimize_charset(charset)
566 assert not hascased
567 _compile_charset(charset, flags, code)
568 code[skip] = len(code) - skip

Callers 1

_codeFunction · 0.85

Calls 7

_get_literal_prefixFunction · 0.85
_get_charset_prefixFunction · 0.85
_generate_overlap_tableFunction · 0.85
_optimize_charsetFunction · 0.85
_compile_charsetFunction · 0.85
getwidthMethod · 0.80
extendMethod · 0.45

Tested by

no test coverage detected