Skip to content

python -m pegen python is broken #96424

@sobolevn

Description

@sobolevn

If I run PYTHONPATH=Tools/peg_generator ./python.exe -m pegen python Grammar/python.gram on main branch, the result file is broken.

There are lots of invalid syntax construct that come from C directly.

Some examples:

    @memoize
    def interactive(self) -> Optional[mod_ty]:
        # interactive: statement_newline
        mark = self._mark()
        if (
            (a := self.statement_newline())
        ):
            return _PyAST_Interactive ( a , p -> arena )
        self._reset(mark)
        return None

It also has this at the bottom:

        return children

    KEYWORDS = ('return', 'import', 'from', 'raise', 'pass', 'del', 'yield', 'assert', 'break', 'continue', 'global', 'nonlocal', 'def', 'if', 'class', 'with', 'for', 'try', 'while', 'as', 'elif', 'else', 'in', 'except', 'finally', 'None', 'True', 'False', 'or', 'and', 'not', 'is', 'lambda')
    SOFT_KEYWORDS = ('match', 'case', '_')


void *
_PyPegen_parse(Parser *p)
{
    // Initialize keywords
    p->keywords = reserved_keywords;
    p->n_keyword_lists = n_keyword_lists;
    p->soft_keywords = soft_keywords;

    // Run parser
    void *result = NULL;
    if (p->start_rule == Py_file_input) {
        result = file_rule(p);
    } else if (p->start_rule == Py_single_input) {
        result = interactive_rule(p);
    } else if (p->start_rule == Py_eval_input) {
        result = eval_rule(p);
    } else if (p->start_rule == Py_func_type_input) {
        result = func_type_rule(p);
    } else if (p->start_rule == Py_fstring_input) {
        result = fstring_rule(p);
    }

    return result;
}

I am attaching full file to this issue: https://gist.github.com/sobolevn/37cfd12ad9d2c157e72e7589747f4ed2

Pinging @isidentical and @pablogsal

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions