INNER CODE UNIT · Python

strip_comments

torognes/vsearch · completion/scripts/extract_cli_options.py:27

def strip_comments(text: str) -> str:
    """Remove C and C++ comments, so commented-out entries are not read."""
    text = re.sub(r'/\*.*?\*/', '', text, flags=re.S)
    return re.sub(r'//[^\n]*', '', text)


def table_body(text: str, anchor: str, path: str) -> str:
    """The text between anchor's opening '{{' and its closing '},};'."""
    start = text.find(anchor)
    if start < 0:
        sys.exit(f'{path}: no {anchor.rstrip(" =")} table found. The table was '
                 'renamed or removed; this script needs updating.')
    opening = text.find('{{', start)
    closing = text.find('},};', opening)
    if opening < 0 or closing < 0:
        sys.exit(f'{path}: could not delimit the {anchor.rstrip(" =")} table. '
                 'It no longer opens with "{{" and closes with "},};"; this '
                 'script needs updating.')

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…