سؤال

I'm trying this (it's just an example):

foo:
  bar?
  { if ($bar == null) { ... } }
  ;

ANTLR4 compiler says:

Message{errorType=ISOLATED_RULE_REF, args=[bar, $bar] ...

What is the workaround?

هل كانت مفيدة؟

المحلول

Ideally the action you have written above would be placed in the exitFoo method of a listener which you use after the parse is complete.

However, if you do leave the action in the grammar, to reference the context object itself, use the ctx property. For example, $bar.ctx is the expression you are trying to use here, and $ctx evaluates to the context object for the enclosing rule.

نصائح أخرى

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top