Skip to content

How to handle cyclic recursion, i.e. two parsers that depend on each other? #263

Answered by CraftSpider
Asha20 asked this question in Q&A
Discussion options

You must be logged in to vote

There's a method on Recursive, Recursive::declare. It can be used to define as many parsers as you need in advance, then define them all later with Recursive::define

Example

let first = Recursive::declare();
let second = Recursive::declare();

first.define(
    just('A').then(second.clone().or_not())
);

second.define(
   just('B').then(first.clone().or_not())
};

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Asha20
Comment options

Answer selected by Asha20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants