I'm trying to do some very basic C++ function declaration parsing. Here is my rule for parsing an input parameter:
arg : 'const'? 'unsigned'? t=STRING m=TYPEMOD? n=STRING
-> ^(ARG $n $t $m?) ;
STRING : ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'::')+ ;
TYPEMOD
: ('*' | '&')+ ;
The problem is I'm trying to pass it something like:
int *param
It matches the "int" with t, but then skips the TYPEMOD, throws an exception saying the * is unwanted when trying to match the n, and then matches "param" with n. Why would it skip the TYPEMOD token and not match it?
Thanks in advance!
EDIT:
Here are my whitespace rules (I included my comment rules as well), everything seems to work fine when parsing other stuff like class declarations, properties, structs, it's just these TYPEMOD things...
COMMENT_LINE
: '//' (~'\n')* '\n' { $channel = HIDDEN; } ;
COMMENT_BLOCK
: '/*' .* '*/' { $channel = HIDDEN; } ;
NL : ('\r' | '\n')+ { $channel = HIDDEN; } ;
WS : (' '|'\t')+ { $channel = HIDDEN; } ;