Replies: 1 comment
-
@segeljakt any thoughts? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The API with the
PrattParser
I think has some egonomic issues that can make life difficult with the borrow checker when one's parser has to hold some state.Consider the following from my real world parser:
This happens because the parser itself has to hold state (in this case variable bindings), and that mutable state needs to be borrowed by the relevant closures. But the compiler really isn't going to like receiving multiple callbacks which borrow against the same state (in this case
self
but could be anything).I have as a workaround the use of an
Rc<RefCell
around the mutable variable state (variable binding context) but this feels like a really bad cop-out.I think the answer here is that
PrattParser
itself should be able to take as an construction argument some kind of arbitrary mutable context state parameter. And then this would get passed into each of the closures used as arguments to themap_<xxx>
functions.Otherwise, I can't really think of a way to make this API work without resorting to
RefCell
etc. The compiler is always going to think there's multiple borrows happening, even though in reality the PrattParser will only be using one at a time. I think that's a bit of a design problem with the API as it stands.Beta Was this translation helpful? Give feedback.
All reactions