Skip to content

Grammar for slash_no_default and slash_with_default can be simplified. #125198

@Ketchp

Description

@Ketchp

Feature or enhancement

Proposal:

The current grammar for slash_no_default has two alternatives:

slash_no_default[asdl_arg_seq*]:
    | a[asdl_arg_seq*]=param_no_default+ '/' ',' { a }
    | a[asdl_arg_seq*]=param_no_default+ '/' &')' { a }

I am proposing changing the grammar to:

slash_no_default[asdl_arg_seq*]:
    | a[asdl_arg_seq*]=param_no_default+ '/' (',' | &')' { (void *)1 }) { a }

The same change can be made to the slash_with_default rule.
1 is meant as true and cast to void * is needed because peg-generator
always creates an artificial rule for a group with a return type void *.

This change would mean less backtracking will be made since param_no_default+ would be parsed only once.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions