So I am having a problem with javacc and skipping comments. I have a multi line comment skip that can contain multiply comments within itself (A comment is anything that appears within /* and a */), I also use this code segement <"//" (~["\n"])* "\n"> to skip a single line comment. Both function independently of one another but when combined, the single line comment seems to break my multi line comment.
The parser no longer recognises the multi line comment and instead parses it as a combination of OTHER(/*), ID etc.
Below is my code for the multi line comment and single line comment skip:
SKIP:
{
"/*" {commentnesting++;} : IN_COMMENT
}
<IN_COMMENT> SKIP :
{
"/*" {commentnesting++;}
| "*/" {commentnesting--;
if(commentnesting == 0) {
SwitchTo(DEFAULT);
}
}
| <~[]>
}
SKIP :
{
<"//" (~["\n"])* "\n">
}
My Questions are:
- How can the single line comment cause the multi line comment to break, when they to my relatively new eyes appear to have completely different regexes?
- Is their a way to write the single line comment skip , so that it performs the same function as before but doesn’t break the multi line comment when the two are used together?
Looks like that should work, except you seem to be missing some angle brackets. Instead of:
…shouldn’t it be:
…and similarly with your second rule?