Question

I have a rule to match 'FOR "hi" FOR'

rule : id1=ELEMENT STRING id1
{
   // action
} 
 -> ^(Tree rule)

but it fails saying reference to undefined rule: id1 How can I reuse a label to ensure the start and end of the rule are the same identifier

Était-ce utile?

La solution

The recommended way to handle this is assume the values match while parsing, and then examine the AST after parsing is complete, issuing error messages at that time for any mismatched elements.

This approach results in a more robust parser and much much understandable error messages in the case of an wrote.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top