2

I am using GumTree to parse a Java file into an ITree, which is GumTree's data structure that represents an AST. I then modify the ITree by performing Actions on it, which are GumTree's representation of Inserts, Updates (renames, etc.), Deletes, and Moves. I would like to then unparse the resulting modified ITree. In other words, I am trying to pretty print the AST.

I have looked in the ITree methods (core/src/gumtreediff/tree) and tried toPrettyString, but that just returned the string "15" which is the type of the top AST node of the tree (a compilation unit).

The GumTree wiki on GitHub has no mention of unparsing or pretty printing. A Google search doesn't help because I think GumTree is too obscure.

Wondering if I should "just" write my own unparser.

I am using release 2.0.0 of GumTree.

pillravi
  • 4,035
  • 5
  • 19
  • 33
  • 1
    Currently implementing an unparser. I hope to add this functionality to GumTree soon. – pillravi Apr 25 '16 at 01:11
  • Were you ever able to get this working? Does GumTree now support unparsing, or is there some alternative concrete syntax tree that preserves source code formatting? – breandan Oct 29 '21 at 03:41

1 Answers1

1

Not sure if this is what you're looking for, but there is a built-in method

toTreeString()

which will return a multi-level indented version of the tree.

nullromo
  • 2,165
  • 2
  • 18
  • 39
  • Thanks, but that's not what I'm looking for. I've looked through all of the provided API and what I want doesn't exist. I have been in contact with the main Gumtree developer, and I'm working on implementing the unparser functionality that I need. – pillravi Jun 02 '16 at 02:30
  • Oh I see. You're trying to turn an ITree back into something that looks like human-readable code. Can you not accomplish this with a simple post-order traversal? I guess it's not quite that simple. Well, good luck! – nullromo Jun 03 '16 at 20:49
  • Thanks; I am doing a traversal but yeah it's not that simple. I have to add all the terminal characters back in and I found a parse ambiguity. But so far my solution works for many cases. – pillravi Jun 03 '16 at 23:04