1

I have a grammar file called turtle.g4 which defines the behavior of Turtle files. It contains a rule regarding IRIs. iri: IRIREF | PrefixedName;

I have a separate java static method (say ClassStatic.methodx)I need to call every time this rule is invoked. Is is possible to write it inside the grammar file along with the rule, using the -> operator?

dia
  • 33
  • 4

1 Answers1

3

What you look for is called an action. You can add actions anywhere in your grammar rules, e.g.

iri: IRIREF { myPlatformCodeCall(); } | PrefixedName;

ANTLR embeds the code within curly braces directly in the generated parser. Read more in the ANTLR4 action doc;

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181