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

Add tree transformation capabilities to Node and Tree #9

Closed
danieldietrich opened this issue Aug 20, 2014 · 4 comments
Closed

Add tree transformation capabilities to Node and Tree #9

danieldietrich opened this issue Aug 20, 2014 · 4 comments
Assignees
Labels

Comments

@danieldietrich
Copy link
Member

Wire together tree traversal (with walkers: preorder, inorder, postorder, level-order) and tree transformation.

Suggestion: Take the rewrite-rule approach using the Match API (enhanced by #8).

@danieldietrich
Copy link
Member Author

@danieldietrich danieldietrich changed the title Add tree transformation capabilities to Node and Tree [tree] Add tree transformation capabilities to Node and Tree Aug 22, 2014
@danieldietrich danieldietrich changed the title [tree] Add tree transformation capabilities to Node and Tree [collection] Add tree transformation capabilities to Node and Tree Aug 22, 2014
@danieldietrich danieldietrich added this to the 1.1.0 M1 milestone Sep 23, 2014
@danieldietrich danieldietrich removed their assignment Sep 25, 2014
@danieldietrich danieldietrich changed the title [collection] Add tree transformation capabilities to Node and Tree Add tree transformation capabilities to Node and Tree Oct 3, 2014
@danieldietrich danieldietrich modified the milestones: Parser, Collections Jan 3, 2015
@danieldietrich danieldietrich modified the milestones: 1.1.3 Tree Enhancements, 1.1.0 Collections Jan 10, 2015
@danieldietrich
Copy link
Member Author

I want Tree transformation look like this (stolen from databricks):

tree.transform {
  case Add(Literal(c1), Literal(c2)) => Literal(c1+c2)
  case Add(left, Literal(0)) => left
  case Add(Literal(0), right) => right
}

@danieldietrich
Copy link
Member Author

We need a function

Tree.transform(Function<? super Tree<? super T>, ? extends Tree<? extends T> f)

or

Tree.transform(UnaryOperator<Tree<T>> f)

Currently a Node has children of type List<Node>. We need to allow the empty tree and change the type of Node's children to List<Tree>.

@danieldietrich
Copy link
Member Author

Note: Removed the transform method because tree.transform(f) is the same as f.apply(tree).

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

No branches or pull requests

1 participant