0

I have the a rule with an action defined as follows:

metric_expr
  : metric=NAME ('AS' label=NAME)? {System.out.println(String.format("%s: %s", metric, label));}
  ;

I got the error says:

error(146): com\foo\bar\PRL.g:65:54: invalid StringTemplate % shorthand syntax: '%s'

Anyone know how to workaround this?

Gelin Luo
  • 14,035
  • 27
  • 86
  • 139

1 Answers1

3

Escape the % signs with a single backslash.

And if you want to display the text of a token, use the token's .text attribute:

metric_expr
  : metric=NAME ('AS' label=NAME)? 
    {System.out.printf("\%s: \%s", $metric.text, $label.text);}
  ;
Nathan Schwermann
  • 31,285
  • 16
  • 80
  • 91
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288