Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

Returning original node from visitor #36

Open
JisuPark opened this issue Aug 5, 2018 · 4 comments
Open

Returning original node from visitor #36

JisuPark opened this issue Aug 5, 2018 · 4 comments

Comments

@JisuPark
Copy link

JisuPark commented Aug 5, 2018

First of all, thank you for the awesome project!

I suggest enhancing transformAST to return not only the parsed one but also the original one.

Similar to Javaparser project, if we want to support Transform and Generate the solidity code, returning original node is essential.

We could use the changed version to reconstruct specific granularity.

For example,

var source = "contract test { uint a; function c() public { uint f = 3; uint e = 1+4;}}"
var ast = parser.parse(source);
parser.visit(ast, {
  FunctionDefinition: (node) => {
    console.log(node.ctx.getText()); // "functionc()public{uintf=3;uinte=1+4;}"
  }
});

By the way, I'm still thinking about how to keep whitespace and newlines.
Could you give me some advice? (It may be related to #32)

@JisuPark JisuPark changed the title returning original node from visitor Returning original node from visitor Aug 5, 2018
@federicobond
Copy link
Owner

@JisuPark hey! sorry about the late response.

I'm not sure what you mean by the original code, but I am wary of exposing such implementation details to the public interface. I believe adding a Concrete Syntax Tree modeled after the JS one should be the way to go here, but any feedback is appreciated.

@JisuPark
Copy link
Author

@federicobond Thanks for the reply!

Now I see your point. I thought current node arguments are too solid to develop a variety of visitor.

When I wanted to extract only function declaration in the source, it was hard because I had to reassemble from the argument node of the visitor. (Let me know if there is an easier way.)

So I suggested such tweak since it might help developers to create such visitor easier.

I think Concrete Syntax Tree can solve it easily.
Let me know how I can help you to develop it.

Thanks

@federicobond
Copy link
Owner

@JisuPark can you provide a piece of code of what you would like to achieve with this library? Better if it is in the form of a pull request with a failing test case. Let’s forget about the implementation for now and understand the API.

@yxliang01
Copy link
Contributor

The getText method shown in the example looks pretty useful :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants