drmfinlay / pyjsgf

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parser keeps adding RequiredGroupings on parsing grammar

Axelfowlie opened this issue · comments

I stumbled across this issue on editing an existing grammar.
Everytime I parse a grammar from a file, a RequiredGrouping is added if there was one before.

RequiredGrouping(Literal("something")) will become RequiredGrouping(RequiredGrouping(Literal("something"))).

This does not happen if there it's only a Literal

The grammar was written to a file using Grammar.compile_to_file(path).
It looked something like this:

<unk_process> = UNK;
public <answers> = (<X>|  Do <Y>);
public <generic> = (<answers>|<unk_process>);

After reopening it with Parser.parse_grammar_file(path)

A pair of parantheses is added turning the grammar into this

<unk_process> = UNK;
public <answers> = ((<X>|  Do <Y>));
public <generic> = ((<answers>|<unk_process>));

I'm not sure why it happens but it doesn't seem to be an intended behaviour to me.

This working example shows the issue

grammar = Grammar("Test")

x = HiddenRule("X","X")
y = HiddenRule("Y","Y")
grammar.add_rule(x)
grammar.add_rule(y)
grammar.add_rule(PublicRule("Z",AlternativeSet(RuleRef(x),RuleRef(y))))

print(grammar.compile())

grammar.compile_to_file("test.jgram")
grammar = parser.parse_grammar_file("test.jgram")
print(grammar.compile())

Hello @Axelfowlie,

Sorry I have taken so long to get back to you on this! I would say this isn't intended behaviour (i.e. a bug). Thank you for providing examples. I will try to fix it soon.