tulipcc/ParserGeneratorCC

Java compilation warnings in TokenManager

itineric opened this issue · 14 comments

Hi,

There are several unused methods in generated TokenManager.
Imported packages / classes that are defined inside PARSER_BEGIN and PARSER_END are also defined in TokenManager generated class.
This means several compilation warnings.
Could add @SuppressWarnings("unused") on class declaration (maybe here: src/main/resources/templates/TokenManager.template). Dont know why this was removed, that SuppressWarning there in version 5 and version 6 of Javacc.

phax commented

Currently the template based approach is very generic and handles a wide range of possibilities. I plan to limit this a bit (e.g. don't create code for versions below 5) and I also think about dropping the "static" option. With these possibilities it will get simpler, and of course I will also look at the TokenManager.

But still... there are compatilation warnings... even if an enhancement does the trick later, couldnt you just add a SuppressWarning for now ?
Thats not the best solution but having compilation warnings on generated code is not clean stuff either.

phax commented

Okay will check tomorrow...

Thanks !

phax commented

I added a @return statement to the JavaDoc - is that what you were aiming for?

Thats not it.

Imagine the folowing parser declaration:

PARSER_BEGIN(MyParser)

import my.pack.MyClass;

PARSER_END(MyParser)

The generated MyParserTokenManager will have

import my.pack.MyClass;

But this import is never used. So you will have compilation warnings for unused imports.
To fix it temporarly, MyParserTokenManager should be annotated with @SuppressWarnings("unused")

phax commented

Ah okay - so it has nothing to do with the TokenManager.template file.
Everything you write between PARSER_BEGIN and PARSER_END is up to you. It is part of your source grammar (.jj file) and it's your responsibility!
I cannot do anything about it!

phax commented

Sorry - closed accidentally only

I aggree that everything between PARSER_BEGIN and PARSER_END is up to me regarding the parser.
Here I am talking about the TokenManager. The imports declared for the Parser are also available in the TokenManager but not needed at all there. So there are compilation warnings on the generated code of the TokenManager (not the parser).
Will try to produce some simple .jj to show you.

phax commented

Ah I see what you mean - didn't think about this one :)

phax commented

Try adding the following to your grammar:

TOKEN_MGR_DECLS :
{}

-> that does the trick for me

See e.g. https://github.com/phax/ph-css/blob/master/ph-css/src/main/jjtree/ParserCSS30.jjt#L57 on how to use it

TOKEN_MGR_DECLS :
{}

defines additional elements inside the TokenManager class. The imports are "outside". Meaning before the class declaration.

phax commented

Got it - thanks. Sorry it took so long :)

phax commented

Fixed in PGCC 1.1.0