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

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top