Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement syntax to specify a variable size children list of same type #46

Open
pollyvolk opened this issue May 11, 2022 · 1 comment
Open
Assignees

Comments

@pollyvolk
Copy link
Member

There are cases when third-party parsers produce a structure of AST, where some parent node contains a list of children of the same type among other children of different types. This list varies in size. Therefore, while creating transformation rules it is impossible to specify such structure of the initial subtree in a single rule.
An example is given below.
The source code in Java:

class P {
	public Object myMethod(int i, String s, java.lang.Object o) {
		int val = getVal(i, s);
		return o.addValue(val);
	}
}

The AST produced by JavaParser creates the following subtree from the method declaration:

  graph TD;
      MethodDeclaration -- 0 --> Modifier;
      MethodDeclaration -- 1 --> SimpleName;
      MethodDeclaration -- 2 --> ClassOrInterfaceType;
      MethodDeclaration -- 3 --> 1[Parameter];
      MethodDeclaration -- 4 --> 2[Parameter];
      MethodDeclaration -- 5 --> 3[Parameter];
      MethodDeclaration -- 6 --> BlockStmt;
Loading

Where children 3 - 5 are arguments from the method's argument block.
In similar cases the amount of arguments, therefore children, may differ.

It is proposed to develop and implement a special syntax to make it possible to explicitly indicate with the DSL that it is requested to take all children (for example, all children with type Parameter) of a same type and put them in a separate block in the target AST.
For example to create such a subtree:

  graph TD;
      MethodDeclaration -- 0 --> Modifier;
      MethodDeclaration -- 1 --> SimpleName;
      MethodDeclaration -- 2 --> ClassOrInterfaceType;
      MethodDeclaration -- 3 --> ParameterBlock;
      MethodDeclaration -- 4 --> BlockStmt;
      ParameterBlock -- 0 --> 1[Parameter];
      ParameterBlock -- 1 --> 2[Parameter];
      ParameterBlock -- 2 --> 3[Parameter];
Loading
@kniazkov kniazkov self-assigned this May 11, 2022
@pollyvolk
Copy link
Member Author

functionDecl java

kniazkov added a commit that referenced this issue Sep 20, 2022
#46 - Implement syntax to specify a variable size children list of same type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants