Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a code formatting tool for a programming language

I'm looking into the feasibility of writing a code formatting tool for the Apex language, a Salesforce.com variation on Java, and perhams VisualForce, its tag based markup language.

I have no idea on where to start this, apart from feeling/knowing that writing a language parser from scratch is probably not the best approach.

I have a fairly thin grasp of what Antlr is and what it does, but conceptually, I'm imagining one could 'train' antlr to understand the syntax of Apex. I could then get a structured version of the code in a data structure (AST?) which I could then walk to produce correctly formatted code.

Is this the right concept? Is Antlr a tool to do that? Any links to a brief synopsis on this? I'm looking for investing a few days in this task, not months, and I'm not sure if its even vaguely achievable.

like image 720
Steven Herod Avatar asked Jun 06 '11 21:06

Steven Herod


1 Answers

Since Apex syntax is similar to Java, I'd look at Eclipse's JDT. Edit down the Java grammar to match Apex. Do the same w/ formatting rules/options. This is more than a few days of work.

like image 193
Jeremy Ross Avatar answered Sep 19 '22 03:09

Jeremy Ross