You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I am trying to create a nom 5 style combinator in order to parse an arbitrary number of brackets from a string (e.g. "(((abc)))" => "abc"). I have a working implementation like so...
...the compiler won't allow it because it cannot move out of 'f', a captured variable in an 'Fn' closure. Essentially, for this to work the Fns would have to be replaced with FnOnces (which is not what nom uses), see this question.
The first method works and is acceptable but this has got me thinking about whether it is possible to use existing combinators within new ones like this? I assume this would have worked quite differently with the nom 4 macro-based approach but nonetheless seems like an important feature.
Sorry if I am being stupid, any pointers in the right direction would be much appreciated!
The text was updated successfully, but these errors were encountered:
zakcutner
changed the title
Creating nom 5 brackets combinator
Recursively defining nom 5 combinators
Oct 11, 2019
So I figured out a possible solution to this issue; the bounds on F can be changed to make it implement the Copy trait like this...
F:Fn(I) -> IResult<I,O,E> + Copy
However, I am unsure whether this will result in inefficiencies (compared to my original solution) due to unnecessary copying at runtime. Perhaps someone would be able to help clarify this for me?
Hello! I am trying to create a nom 5 style combinator in order to parse an arbitrary number of brackets from a string (e.g.
"(((abc)))" => "abc"
). I have a working implementation like so......however when I attempt to use the
terminated()
combinator within my generated closure like so......the compiler won't allow it because it
cannot move out of 'f', a captured variable in an 'Fn' closure
. Essentially, for this to work theFn
s would have to be replaced withFnOnce
s (which is not what nom uses), see this question.The first method works and is acceptable but this has got me thinking about whether it is possible to use existing combinators within new ones like this? I assume this would have worked quite differently with the nom 4 macro-based approach but nonetheless seems like an important feature.
Sorry if I am being stupid, any pointers in the right direction would be much appreciated!
The text was updated successfully, but these errors were encountered: