Skip to main content

recursive

Function recursive 

Source
pub fn recursive<'a, I, O, E, F, P>(f: F) -> Recursive<'a, I, O, E>
where I: Input, F: FnOnce(Recursive<'a, I, O, E>) -> P, P: Parser<I, Output = O, Error = E> + 'a,
Expand description

再帰パーサーを構築する。

クロージャ f は再帰参照(Recursive)を受け取り、パーサーを組み立てて返す。 返されたパーサーは Box<dyn Parser> として内部に格納される。

let expr = recursive(|expr| {
    let atom = integer().or(between(tag("("), expr, tag(")")));
    let term = atom.chainl1(mul_op());
    term.chainl1(add_op())
});