As I stated separately in an announcement, the re-activated FreeCC project is very much in need of collaborators. Granted, people should be interested enough on their own steam, but I have decided to sweeten things a bit. I am defining a mini-project that I will pay $100 for. Well, the first person who completes it, anyway. Depending on how this turns out, I may define some other mini-projects with moderate payouts, depending on their complexity. I don't think that this one should be more than a day's work. Well, probably considerably less than that. (NB. That is $100, the real ones, not Zimbabwe dollars, or even Canadian or Australian. Coin of the imperial realm...)

Okay, the project I propose is to write a Java source code to HTML utility using FreeCC and FreeMarker. Here is an outline of what needs to be done to claim the grand prize. As I stated in the announcement, FreeCC contains a Java grammar that is quite usable on its own. The one here: https://github.com/revusky/freecc/tree/master/src/grammars

I think that things that are easy should be easy. So I provide the steps to get going. Here is the magic incantation to build the parser and compile it from any command line (assuming you have git and the JDK installed. /Who doesn't?/)

|git clone https://github.com/revusky/freecc.git cd freecc/src/grammars ../../bin/freecc Java.freecc 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 |You can use that, by the way to run over any Java 
source file and dump the AST.

Okay, now, there is a wrinkle to this. To work on this mini-project actually requires a modification of the above hocus pocus. You see, you need to use the FREEMARKER_NODES option when generating the parser. That means that the third line of the magic incantation above should be:

|../../bin/freecc -FREEMARKER_NODES Java.freecc |

and the fourth line is also a bit more complicated because you need to have freemarker.jar on the classpath. (Do use the one that is included with FreeCC, by the way.) So the compile step becomes:

|javac -classpath .:../../bin/freemarker.jar javagrammar/*.java |

(/and the : in the above would be a semicolon ; if you are on a Windows machine. (I know I'm spoonfeeding here, but I prefer to err on the side of over-specification.../))

You see, what the -FREEMARKER_NODES option did was it told FreeCC to generate Node objects that implement the freemarker.template.TemplateNodeModel API which allows FreeMarker to recursively walk the tree. So, this mini-project, 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 generated by parsing a Java source file. (Pretty cool, eh?) So, what you need is to parse the java source file, expose the root node of the AST to your java template and marry the two with template.process(...) or something like that.

Okay, 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.

This is not the preferred venue for discussing FreeCC development, so anybody who wants to follow through on the above mini-project and get their $100 and their name in the FreeCC distribution as a contributor, please use the discussion forum that was recently set up for this purpose. Specifically here: https://discuss.parsers.org/t/make-an-easy-100-no-this-is-not-spam/15

Happy New Year,

Jon Revusky

P.S. If you decide to give it a try, you can ask for hints and so on as well. I think the trickiest thing might be handling indentation level. Well, also, one could get more or less ambitious with the thing. Like, somebody who is really a whiz with HTML/javascript could probably produce a really nice navigable version of the source code and such. But I think I'll accept anything that is colorized and properly indented.

Reply via email to