There's another thing I'd like to ask for a help with.

Some of my groovy sources are actually pre-processed (in a way remotely similar 
to the well-known CPP, i.e., before groovyc is called, a temporary groovy 
source is generated from one or more original sources; it's the generated temp 
file which then gets compiled by groovyc and is turned to an appropriate 
.class).

Currently, I am fixing the file names and source line numbers externally, i.e., 
I am
(a) catching the issues the compiler reports, and re-write the file name and 
line number as needed before sending it up to Xcode to show them in its issue 
list;
(b) before displaying a stack trace in my code, I am fixing the file names and 
line numbers similarly, based on the information from the preprocessor, which I 
store as a resource in my application JAR.

That does work, but is a bit at the complex, error-prone and ugly side.

I wonder: couldn't I write an ASTT which would fix the file names and line 
numbers directly in the compiled .class, so that all the reported issues from 
the compiler, just as all the runtime thrown exceptions etc., would not need to 
be fixed anymore, for that would all properly address the original sources and 
their line numbers?

I have actually tried to do that at the CompilePhase.INITIALIZATION time, with 
no real success. It does not seem I am able to change the source files 
node-based, only a SourceUnit seems to allow that — whilst a pre-processed file 
actually contains result of more different original source files, oops. What's 
even worse, whilst I can override configureAST in my own ParserPlugin subclass 
to fix the line numbers there (haven't found any other place to do that), it 
fails in a number of ways even in the simplest case of a pre-processed file 
containing result of only one original source (e.g., at the moment when an 
issue is reported there seems to be no way to know whether the appropriate node 
has already been processed and its line numbers fixed or not).

Is there now with antlr4-based Parrot a decent and reliable solution of this 
problem ASTT-level, or should I rather stick with my external solutions with 
Groovy 3+?

Thanks again,
OC

Reply via email to