Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display the bytecode when compiled a regular expression in debug mode #74485

Closed
serhiy-storchaka opened this issue May 7, 2017 · 5 comments
Closed
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir topic-regex type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 30299
Nosy @terryjreedy, @ezio-melotti, @serhiy-storchaka, @jcgoble3
PRs
  • bpo-30299: Display a bytecode when compile a regex in debug mode. #1491
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-05-14.06:54:04.286>
    created_at = <Date 2017-05-07.15:27:38.755>
    labels = ['expert-regex', 'type-feature', 'library', '3.7']
    title = 'Display the bytecode when compiled a regular expression in debug mode'
    updated_at = <Date 2017-05-14.06:54:04.285>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2017-05-14.06:54:04.285>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-05-14.06:54:04.286>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)', 'Regular Expressions']
    creation = <Date 2017-05-07.15:27:38.755>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30299
    keywords = []
    message_count = 5.0
    messages = ['293198', '293211', '293214', '293224', '293636']
    nosy_count = 5.0
    nosy_names = ['terry.reedy', 'ezio.melotti', 'mrabarnett', 'serhiy.storchaka', 'jcgoble3']
    pr_nums = ['1491']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue30299'
    versions = ['Python 3.7']

    @serhiy-storchaka
    Copy link
    Member Author

    Proposed patch makes compiling a regular expression in debug mode (with the re.DEBUG flag) displaying the bytecode in human readable form (in addition to the syntax tree). For example:

    >>> re.compile('test_[a-z_]+', re.DEBUG)
    LITERAL 116
    LITERAL 101
    LITERAL 115
    LITERAL 116
    LITERAL 95
    MAX_REPEAT 1 MAXREPEAT
      IN
        RANGE (97, 122)
        LITERAL 95
    1. INFO 16 0b1 6 MAXREPEAT (to 17)
      prefix_skip 5
      prefix [0x74, 0x65, 0x73, 0x74, 0x5f] ('test_')
      overlap [0, 0, 0, 1, 0]
      17: LITERAL 0x74 ('t')
    2. LITERAL 0x65 ('e')
    3. LITERAL 0x73 ('s')
    4. LITERAL 0x74 ('t')
    5. LITERAL 0x5f ('_')
    6. REPEAT_ONE 12 1 MAXREPEAT (to 40)
    7. IN 7 (to 39)
    8. RANGE 0x61 0x7a ('a'-'z')
      
    9. LITERAL 0x5f ('\_')
      
    10. FAILURE
      

    39: SUCCESS
    40: SUCCESS
    re.compile('test_[a-z_]+', re.DEBUG)

    This feature is needed mainly for our own needs. It can help optimizing regular expression compilation.

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life stdlib Python modules in the Lib dir topic-regex type-feature A feature request or enhancement labels May 7, 2017
    @terryjreedy
    Copy link
    Member

    The new output is the blank line and numbered lines, produced by the new dis function.

    The addition is specific to CPython's re module. Thus the doc for re.DEBUG remains "Display debug information about compiled expression." I think that the NEWS entry should also mention that this is a cpython-specific enhancement and not a language change. See review note.

    @serhiy-storchaka
    Copy link
    Member Author

    What the review note you mean Terry?

    @terryjreedy
    Copy link
    Member

    Whoops, the one I thought I added previously. I must not have clicked the [comment] button after writing it and before closing the tab.

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 4ab6abf by Serhiy Storchaka in branch 'master':
    bpo-30299: Display a bytecode when compile a regex in debug mode. (bpo-1491)
    4ab6abf

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir topic-regex type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants