Вопрос

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

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top