drmfinlay / pyjsgf

JSpeech Grammar Format (JSGF) compiler, matcher and parser package for Python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parser ignores AlternativSet

embie27 opened this issue · comments

When parsing a rule with a Literal followed by an AlternativeSet and again a Literal, the AlternativeSet is not parsed as such. If there is no Literal either on the rigtht or on the left side of the AlternativeSet everything works fine.
Example:
Rule: public <greet> = i (go | run) to school;
Parser Output: Rule(name='greet', visible=True, expansion=Sequence(Literal('i'), Literal('go'), Literal('run'), Literal('to school')))

I did some debugging and I think I found the mistake.
The function flatten_chain is called if there is a Sequence as a child of another Sequence. So if there is something like Sequence(Literal('i'), Sequence(AlternativeSet(Literal('go'), Literal('run')), Literal('to school'))) it will be called.
But the function does not only remove children that are sequences but also AlternativeSets. So the result is Sequence(Literal('i'), Literal('go'), Literal('run'), Literal('to school') instead of Sequence(Literal('i'), AlternativeSet(Literal('go'), Literal('run')), Literal('to school')).

Worked out a fix for this issue in pull request #10.

Nice catch! 👍
Thanks for the issue and fix. I'll merge your PR and add a test case into test_parser.py. I'm happy to release this along with the other changes I made a few days ago as version 1.4.1.