in Parser grammar I would like to define several variables in locals .
A simplified example is as follows:
body locals [ Map<String, String> bodyContent = new HashMap<String, String>(); long counter = 0; ] : BODY_CAPTION NEWLINE line ; line : key='MyKey' TAB value='MyValue' NEWLINE { $body::bodyContent.put($key.text, $value.text); $body::counter++; } ;
This gives an error:
unknown attribute 'counter' for rule 'body' in '$body::counter'
If I change the lines in the locals clause as follows
locals [ long counter = 0; Map<String, String> bodyContent = new HashMap<String, String>(); ]
he gives an error:
unknown attribute 'bodyContent' for rule 'body' in '$body::bodyContent'
It appears that ANTLR only recognizes the first definition of a local variable in the locals clause.
Is there a way to define multiple local variables in locals ?
source share