1

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?

  • Have you posted this question on the Irony discussion board? Roman is usually quite prompt in answering these types of questions, and most assuredly is THE expert on Irony. – Pieter Geerkens Mar 14 '13 at 14:26
  • I have, but Roman told me that it's and else-dangling problem which it very likely is not (there are not if/else statements in the code). – Karel Varel Mar 14 '13 at 14:39
  • I believe you mis-understood Roman. He was referring to a type of problem that is best-known for that particular occurrence, not to a specific instance of that occurrence. The grammar debugging/tracing tools in Irony are excellent; how far have you gotten in running a small test case through those? – Pieter Geerkens Mar 14 '13 at 14:43
  • I got as far as I described in my question. I'm pretty sure that the problem is in the second production of the last rule (ifTagClose + elseIfTagBlock). Also there are no conflicts, so else-dangling problem is less likely. – Karel Varel Mar 14 '13 at 14:48

0 Answers0