Stephen Herod wrote:
... I suppose you can "train" antlr to understand the syntax of Apex ....
What do you mean by "train 'antlr"? "Train" as in artificial intelligence (neural network training)? If so, then you are mistaken.
Stephen Herod wrote:
... get a structured version of the code in the data structure (AST?), which I could then execute to create correctly formatted code.
Is this the right concept? Is Antlr a tool for this?
Yes, more or less. You write a grammar that pinpoints the language you want to parse. Then you use ANTLR, which will generate a lexer (tokenizer) and a parser based on the grammar file. You can let the parser create an AST from your input source, and then go through the AST and emit (custom) output / code.
Stephen Herod wrote:
... I am looking to invest a few days in this task, not months, and I'm not sure that it is even dimly achievable.
Well, I don’t know you, of course, but I would say writing a grammar for a language like Java, and then emitting output while walking around the AST for several days is impossible, especially for someone new to ANTLR. I am quite familiar with ANTLR, but I could not do this in just a few days. Please note that I am only talking about the "parsing part", after you have done this, you will need to integrate this into some kind of text editor. All this looks more like a project of several months, even weeks, not to mention a few days.
So, in short, if all you want to do is write a special marker, ANTLR is not the best choice.
You can see the Xtext , which uses ANTLR under the hood. To quote their website:
With Xtext, you can easily create your own programming languages and domain languages (DSL). This platform supports the development of language infrastructures, including compilers and interpreters, as well as fully integrated Eclipse-based IDE integration ....
But I doubt that you will have the Eclipse plugin and run for several days.
Anyway, good luck!