I've been trying to use Irony to parse some XML code. I defined the grammar as follows:
this.Root = tagList;
tagList.Rule = this.MakeStarRule(tagList, tag);
tag.Rule = conditionBlock;
ifTagOpen.Rule = < + "a" + "condition" + equals + "'i'" + >;
ifTagClose.Rule = < + slash + "a" + >;
elseIfTag.Rule = < + "b" + "a" + equals + "'i'" + >;
elseTagClose.Rule = < + slash + "a" + >;
conditionBlock.Rule = ifTagOpen + ifTagCloseElseIf | ifTagOpen + tag + ifTagCloseElseIf;
elseIfTagBlock.Rule = elseIfTag + elseTagClose;
ifTagCloseElseIf.Rule = ifTagClose | ifTagClose + elseIfTagBlock | Empty;
Now, when I try to parse something like this:
<a condition ='i'><a condition ='i'></a><b a='i'></b></a>
it works fine (as expected).
But, when I try something like this:
<a condition ='i'><a condition ='i'></a></a>
it does not work and it tells me that it expects <b a='i'>
after the first </a>
.
Correct me if I'm wrong, but shouldn't this be parsable too? The first production of the last rule clearly says that there doesn't have to be <b a='i'>
after </a>
. I suspect that after the parser encounters another "<" after the first </a>
it tries to apply the second production of the last rule ifTagClose + elseIfTagBlock and thus expects <b a='i'>
. I'm pretty sure that the problem is with the starting "<", because when I remove it from the starts of all terminals, it works as expected.
Is there any workaround to this except for custom parsing actions? Or any other parsing engines for c# that would know how to cope with this?