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

In the re's token example OP and SKIP regexes can be improved #66176

Closed
py-user mannequin opened this issue Jul 14, 2014 · 3 comments
Closed

In the re's token example OP and SKIP regexes can be improved #66176

py-user mannequin opened this issue Jul 14, 2014 · 3 comments
Assignees
Labels
docs Documentation in the Doc dir performance Performance or resource usage topic-regex

Comments

@py-user
Copy link
Mannequin

py-user mannequin commented Jul 14, 2014

BPO 21977
Nosy @rhettinger, @ezio-melotti, @py-user
Files
  • re_ex_tok.diff: clear OP and fast SKIP
  • 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 = 'https://github.com/rhettinger'
    closed_at = <Date 2014-07-14.08:53:36.476>
    created_at = <Date 2014-07-14.07:23:21.527>
    labels = ['expert-regex', 'docs', 'performance']
    title = "In the re's token example OP and SKIP regexes can be improved"
    updated_at = <Date 2014-07-14.15:23:42.385>
    user = 'https://github.com/py-user'

    bugs.python.org fields:

    activity = <Date 2014-07-14.15:23:42.385>
    actor = 'berker.peksag'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2014-07-14.08:53:36.476>
    closer = 'rhettinger'
    components = ['Documentation', 'Regular Expressions']
    creation = <Date 2014-07-14.07:23:21.527>
    creator = 'py.user'
    dependencies = []
    files = ['35951']
    hgrepos = []
    issue_num = 21977
    keywords = ['patch']
    message_count = 3.0
    messages = ['223000', '223003', '223004']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'ezio.melotti', 'mrabarnett', 'docs@python', 'py.user', 'python-dev']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue21977'
    versions = ['Python 3.4', 'Python 3.5']

    @py-user
    Copy link
    Mannequin Author

    py-user mannequin commented Jul 14, 2014

    https://docs.python.org/3/library/re.html#writing-a-tokenizer

    There are redundant escapes in the regex:

    ('OP', r'[+*\/\-]'), # Arithmetic operators

    Sequence -+*/ is sufficient.

    It makes the loop to do all steps on every 4 spaces:

    ('SKIP', r'[ \t]'), # Skip over spaces and tabs

    Sequence [ \t]+ is faster.

    Applied patch.

    @py-user py-user mannequin assigned docspython Jul 14, 2014
    @py-user py-user mannequin added type-feature A feature request or enhancement docs Documentation in the Doc dir topic-regex labels Jul 14, 2014
    @rhettinger rhettinger assigned rhettinger and unassigned docspython Jul 14, 2014
    @rhettinger
    Copy link
    Contributor

    I will keep the \- because the - at the front of the character range is a non-obvious special case. The other changes look reasonable.

    @rhettinger rhettinger added performance Performance or resource usage and removed type-feature A feature request or enhancement labels Jul 14, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 14, 2014

    New changeset bb28542af060 by Raymond Hettinger in branch '3.4':
    bpo-21977: Minor improvements to the regexes in the tokenizer example.
    http://hg.python.org/cpython/rev/bb28542af060

    @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
    docs Documentation in the Doc dir performance Performance or resource usage topic-regex
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant