Skip to content

Bug with zero or more rule #81

@heckad

Description

@heckad

Gram file

start: stmts

stmts: stmt*

stmt: block

block: "{" stmts "}"

Input

{ {} }

Result

  File "<unknown>", line 1
    { {} }
       ^
SyntaxError: input.txt

The problem in the generated parse rule for the block stmt
Code

    @memoize
    def block(self) -> Optional[Any]:
        # block: "{" stmts "}"
        mark = self._mark()
        if (
            (literal := self.expect("{"))
            and
            (stmts := self.stmts())
            and
            (literal_1 := self.expect("}"))
        ):
            return [literal, stmts, literal_1];
        self._reset(mark)
        return None;

(stmts := self.stmts()) shoud be (stmts := self.stmts()) is not None because an empty array is interpreted as false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions