Skip to content

Optional closing tag causes runtime error: Earley generates multiple start symbol items #1587

@caph1993

Description

@caph1993

Describe the bug

I defined the following grammar with ambiguity enabled. The parser raised and error and automatically suggested me to report the bug.

Note. The example below is a minimal example of my real use case.

To Reproduce

# Bug report
from lark import Lark, UnexpectedCharacters

grammar = """
    start: "<p>" text ("<b>" bold "</b>")* CLOSE?
    text:  /.+/
    bold: /.+/
    CLOSE: "</p>"
    %ignore CLOSE
    
    %import common.WS
"""

# Use ambiguity='explicit' to see all possible trees
parser = Lark(grammar, start='start', ambiguity='explicit', lexer='dynamic_complete')

text = "<p>Press the <b>button</b>.</p>"
print(text)
try:
    print(parser.parse(text).pretty())
except UnexpectedCharacters:
    print("No matches")

Output:

RuntimeError: Earley should not generate multiple start symbol items! Please report this bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions