ErrorRule how to configure it properly?

Sep 29, 2011 at 8:28 AM
Edited Sep 29, 2011 at 8:30 AM


I have following language (dsl) example:

entity A


   column Id int;

   column Name   //here we have a syntax error

   column Description string;


For the column declaration: "column" + Id + Id + semi;

If i configure ErrorRule as in CSharpGrammar example: column.ErrorRule = SyntaxError + semi; I have following problem:

for the example above, the parser will ignore "column Name" but also next declaration "column Description string ;" and this is not what i need.

I would need somehow to instruct the parser to go back one token if the syntax error is on a keyword, so that in my case,

it would permit matching "column Description string" 

Is this possible?


Sep 29, 2011 at 4:14 PM

ErrorRule allows you to "recover" from error and continue parsing - not to parse successfully at the end, but to discover more errors further in the source, if there's more than one. If ErrorRule is activated, it means that we are in error state, and will NOT end up with a successfully parsed script (!). So there's not much value in your effort to recover the last column declaration and make it parse successfully - it will be thrown away anyway. The parser will correctly point to location around Name as a place of error - that's all what is needed - to point user to error location. Parser will then proceed to the next column declaration (or next Entity) to possibly discover more errors.

Hope that clears the confusion


Sep 29, 2011 at 9:50 PM

Thanks, I understand this now.

I find error rule very problematic to configure.

lets take  this declarations from my dsl:   entity A { column A1 int ; column A2 int; } entity B { column B1 }

If there is a syntax error in column definition for A1  and i have an errorrule = SyntaxError + semi; then it will ignore everything till the end of A2 int.

But if i have an error in A2 definition, let's say missing semicolon. than it will ignore everything till member B1 of next entity.

If i reconfigure errorRule = SyntaxError + ("}" | semi)  this will solve problem 2 but will match till end of entity if any column but the last has an error.

If i switch errorRule = SyntaxError + ( semi | "}") will have both problems.

ACTUALLY WHAT IS NEEDED IS AN ERROR RULE THAT MATCHES  ANY "}" or semi whichever comes first, but match both even if first succeds!!! 

Can something like this be done in Irony?





Sep 29, 2011 at 9:55 PM

Look in sample c# grammar, all instances of ErrorRule; you need smth similar to member declaration:


      columndef.ErrorRule = SyntaxError + ";" | SyntaxError + "}" ;

that should do the trick for you