how properly use recursive
When i run my parser(application). There is this error
thread 'main' panicked at /home/sineptic/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stacker-0.1.15/src/lib.rs:197:21:
setting stack permissions failed with: Cannot allocate memory (os error 12)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
and it freezes.
When I try to RUST_BACKTRACE=1 it run smth but, and print only memory allocation of {different count} bytes failed and then run, but don't print.
I can build without problem.
This may mean that your parser is trying to infinitely recurse (stacker allocates more memory for the stack for deep recursion), can you provide the code for it?
Yes, I agree. This looks like left recursion.
I implement #653 and write this:
// ...
recursive(|x| {
x.then_with(move |ctx: Context| {
take_until(just::<_, _, Simple<char>>('`').repeated().at_least(1)).map(
move |(chars, ticks)| match ticks.len() {
n if n == backticks => Context::Ok(
[ctx.clone().into_intermediate_state().unwrap(), chars]
.concat(),
ticks,
),
_ => Context::IntermediateState(
[
ctx.clone().into_intermediate_state().unwrap(),
chars,
ticks,
]
.concat(),
),
},
)
})
})
.map(|x| match x {
Context::Ok(a, b) => (a, b),
Context::IntermediateState(_) => unreachable!(),
})
// ...
And have Infinite recursion. How can I avoid this?
I presume that you're using 0.9.
I don't see anything here that would result in infinite recursion (to be clear, do you mean infinite recursion or infinite iteration?) by itself, the problem must be elsewhere.
@sineptic Have you been able to fix this, or are you able to share more of the code that is producing the error? Otherwise this issue can't move forward.
Ohhh, I don't remember what I do to make it works, but this issue is irrelevant.