Thank you paul

I am trying to extract comments from my groovy script for use in a visualizer 
that graphs the execution of the script. I wanted to show the actual code in a 
description section, and the comments along each graph node

I tried the GroovyDoc route, but it worked only on function signatures and not 
on comments inside the function block. Shil, Alessio and your suggestions to 
read the source file makes sense, I will give that a shot

regards
Saravanan

On 2021/09/29 06:52:43, Paul King <[email protected]> wrote: 
> Hi Saravanan,
> 
> Currently that isn't possible. That information is skipped over during
> early parsing and is gone by the time AST processing starts. That was one
> of the reasons Groovydoc embedding was added in Groovy 3 to at least allow
> the Groovydoc part of such information to be available during AST
> processing.
> 
> If you explain a little more about what you are trying to do, perhaps
> someone can give further advice. You could for example use the line and
> column number information in the AST to "scrape" the information from the
> source file yourself. Regex might help here depending on what you are
> trying to do.
> 
> Cheers, Paul.
> 
> On Wed, Sep 29, 2021 at 4:26 PM Saravanan Palanichamy <[email protected]>
> wrote:
> 
> > Hello all,
> >
> > I am trying to do two things
> >
> > 1) Extract comments from inside a function code (not the function's groovy
> > doc, but comments embedded inside the function code itself)
> > 2) Extract the source code of the function itself
> >
> > For example
> >
> > /* Comments about myFunction *./
> > void myFunction() {
> >     // My first line in the function
> >     myFirstLine()
> >
> >     // My second line
> >     secondLine()
> > }
> >
> > I want to extract the two // comments inside the function. I also want to
> > be able to get the entire source code of the function (so essentially the
> > entire code snippet above) as part of my AST transformations. Is that
> > possible? Thank you for your time
> >
> > regards
> > Saravanan
> >
> 

Reply via email to