projectfluent / fluent-rs

Rust implementation of Project Fluent
https://projectfluent.org
Apache License 2.0
1.05k stars 95 forks source link

Allow AST traversal via the Visitor trait #188

Closed Michael-F-Bryan closed 3 years ago

Michael-F-Bryan commented 4 years ago

See https://github.com/projectfluent/fluent-rs/pull/183#issuecomment-651517745

Michael-F-Bryan commented 3 years ago

As mentioned in https://github.com/projectfluent/fluent-rs/pull/183#issuecomment-659661542:

It's possible to build a new tree by using a pushdown automaton which will build up a new AST on each transition, but you'll likely run into issues with the borrow checker.... When you recurse and add a new state to the stack, you'd be forced to "find" where you want to insert new nodes instead of just holding a reference to the parent in the automaton (multiple nested states means multiple mutable pointers into the same tree, which is no bueno).

I'm sure you could work around this with enough dynamic dispatch and indirection, but to be honest I'd just write the traversal/modification by hand at that point. That way you're free to do whatever you want and don't need to conform to a particular interface.

This experiment was useful, but I don't think we'll want to go down this path so I'm going to close the PR.