I am really hyped about JuliaSyntax.jl, however I could not figure out how to perform a round trip from the parsed String to a syntax tree and back to a String.
Is this something possible already?
My usecase would be to use
JuliaSyntax as a parser, work directly in the syntax tree form and then go back to a String representation.
Here you have an example (hope this fits your use case well enough):
text = """inc(x) = x + 1"""
there = parsestmt(JuliaSyntax.SyntaxNode, text)
# do some work on `there` object
#back to string "inc(x) = x + 1"
andbackagain = JuliaSyntax.sourcetext(there)
This works at statement/expression level - but the same will work if you are doing the parsing at file-level (just switch the
parsestmt with the appropriate
I actually went back to this. Thanks for your answer but it unfortunately does not work for me.
sourcetext only works for
SyntaxNode and not for
GreenNode, additionaly it just return the source that it was given at the beginning (not that it’s actually easily possible to change the values in the
I guess JuliaSyntax.jl is really more meant to be “read-only”