Make an easy $100! (No, this is not SPAM!)

Here is a little mini-project for people interested in dipping their toe into the water here. (Yeah, come on in. The water is fine!) And yes, I am willing to pay $100 (not Zimbabwe dollars, or even Canadian or Australian, U.S. dollars, coin of the imperial realm…) for this.

The project I propose is to write a Java source code to HTML utility using JavaCC and FreeMarker.

Here is an outline of what needs to be done to claim the grand prize. The utility needs to use the Java.javacc java grammar here: https://github.com/javacc21/javacc21/tree/master/src/grammars

Here is the magic incantation to build the parser and compile it from any command line (assuming you have git and the JDK installed.)

 git clone https://github.com/javacc21/javacc21.git
 cd javcc21/src/main/grammars
 java -jar ../../bin/javacc.jar Java.javacc
 javac javagrammar/*.java

The above should generate a Java parser and compile it. The generated JavaParser class has a main() method that you can invoke via:

java javagrammar.JavaParser

Now, there is one wrinkle to all of this. You actually need to use the FREEMARKER_NODES option when generating the parser for this mini-project. So, actually, the third line of the magic incantation should be:

../../bin/javacc -FREEMARKER_NODES Java.javacc

and the fourth line would be:

javac -classpath .:../../bootstrap/freemarker.jar javagrammar/*.java

(and the : in the above would be a semicolon ; if you are on a Windows machine)

You see, what the -FREEMARKER_NODES option did was it generated Node objects that implement the freemarker.template.TemplateNodeModel API which allows FreeMarker to recursively walk the tree. So, a Java to HTML beautifier would require a FreeMarker template that handles the various nodes in the Java AST using the recursive tree walking machinery in FreeMarker. What is documented here for processing the XML DOM tree: https://freemarker.apache.org/docs/xgui_declarative_basics.html

Though that refers specifically to transforming XML, this can also be used perfectly well for generating a beautified HTML version of Java source code, except that, instead of the nodes being the DOM nodes of an XML document, they are the nodes of the AST.

So, here is how you claim the $100 prize. You get the Java 2 HTML utility working as documented above with a reasonably good explanation of it that I can include in the examples directory of FreeCC. Your authorship will be credited there, and you can provide me an email address and I will send you the $100 by Paypal.