ANTLR 4.5 is giving me a "mismatched input 'String[]' expecting 'String'" but I don't understand why the '[]' are being included in the token.
I have stripped the grammar down to the bare minimum to show the problem:
grammar Test;
@header
{
package parser;
}
mainClass : 'class' ID '{' 'void' 'main' '(' 'String' '[' ']' ID ')' '}' ;
ID : [a-zA-Z] [a-zA-z0-9]* ;
WS : [ \t\f\r\n]+ -> channel(HIDDEN);
The input is:
class A
{
void main(String[] args)
}
If I use 'String []' then the input is successfully parsed.
If I print out the tokens from the parse tree then they all look like what I expect, except for 'String[]' being shown as one ID token and not 3 separate tokens.
I have tried explicitly defining the 'String', '[' and ']' tokens but the result is the same.
I just can't work out what is wrong.