I'm trying to parse regular expressions using JavaCC but I encountered a problem with integers. The problem is that sometimes, in some productions, I want to interpret a set of numbers as a character each, however, on something like (ab){1,20} I want to interpret the numbers inside the braces as integers. The problem is that JavaCC is choosing the first token that matches in the list, regardless of if that token is expected in the production or not.
I have a token DIGIT and a token INTEGER defined as one or more DIGITs. If I prioritize DIGIT, it will never choose INTEGER, if I prioritize INTEGER, in the productions where I want to interpret digits one by one it will choose INTEGER.
I also tried to define something like (< DIGIT >)+ in the production expecting an integer, but then I don't know how to assign that to a Token. Is there a way to assign the whole sequence to a single token, or at least append each digit to the image of one token or store an array of tokens?