I don't know about Groovy specifically, but most parsers discard comments
(and whitespace, line endings, etc.) before building an AST. However, you
can reconstruct the missing text if you have the position information of
each AST node and the original source code available.

On Wed, 29 Sept 2021 at 08:26, 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