Skip to content

parsing error for rules with [x] followed by x #41

@kercos

Description

@kercos

Try the following script:

from jsgf import parser, Grammar
rule1 = parser.parse_rule_string('public <test1> = [la] lady;')
rule2 = parser.parse_rule_string('public <test2> = [la] bady;')
grammar = Grammar()
grammar.add_rule(rule1)
grammar.add_rule(rule2)
print(grammar.compile())
matching1 = grammar.find_matching_rules('lady')
matching2 = grammar.find_matching_rules('bady')
print('Matching "lady":', matching1)
print('Matching "bady":', matching2)

The output will show the following:

#JSGF V1.0;
grammar default;
public <test1> = [la] lady;
public <test2> = [la] bady;

Matching "lady": []
Matching "bady": [Rule(name='test2', visible=True, expansion=Sequence(OptionalGrouping(Literal('la')), Literal('bady')))]

Notice that the string "lady" is not matched by the grammar, even though rule test1 expands to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions