Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive rules passing different Var instances should be possible #27

Open
akirschbaum opened this issue Apr 28, 2015 · 1 comment
Open

Comments

@akirschbaum
Copy link

When using rules that have parameters, @cached can be used to allow recursive calls. The generated caching code then checks all parameters for equality when reusing rules.

This mechanism works fine for rules like

@Cached
public Rule rule(boolean flag) {
    return flag ? rule(false) : sequence("a", "b");
}

(Please ignore that this rule does not make much sense; I just needed a simple example for a rule definition with a structure that depends on the method's parameter.)

Quite often I need code like

@Cached
public Rule rule(Var<Integer> count) {
    Var<Integer> tmp = new Var<>();
    return firstOf(
        sequence("c", count.set(0)), 
        sequence("b", rule(tmp), count.set(tmp.getNonnull()+1), "b")
    );
}

That is: a recursion where the rule definition structure does NOT depend on the method's parameter but in which a different parameter is passed in each recursion level.

Such rules are currently not possible because the generated caching code never finds a match and therefore causes an infinite recursion during parser generation.

@fge
Copy link
Owner

fge commented May 9, 2015

Such rules are currently not possible because the generated caching code never finds a match and therefore causes an infinite recursion during parser generation.

Yes, that's what happens.

Unfortunately this is not curable with the current system; the day when indy is used I can probably fix this... But I'm far from being done with indy at all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants