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

Action called twice with Memo.no, once with Memo.yes #108

Open
callumenator opened this issue Feb 18, 2013 · 5 comments
Open

Action called twice with Memo.no, once with Memo.yes #108

callumenator opened this issue Feb 18, 2013 · 5 comments

Comments

@callumenator
Copy link
Collaborator

enum g = `
Test:
    Rule <- (!A .)* A
    A <- 'A'{action}
`;

mixin(grammar!(Memoization.no)(g));

T action(T)(T t)
{
    if (t.successful)
        writeln("ACTION!");
    return t;
}

void main()
{
    Test("xxxA");
}

I think in this test action should only be called once, and with memoization on that is what happens. With memoization off, action is called twice. I'm not having much luck debugging it.

@callumenator
Copy link
Collaborator Author

Actually I think I get what is going on now, maybe I have it wrong way round. The memo'd version after trying the neg look-ahead at the end, already has a match that succeeded, so instead of running the A rule again it grabs it from the memo, so the action doesn't get run again.

So now i think both versions should call the action twice because of where it is placed. The memo would need to know about actions then. I'll wait to see what you think.

@PhilippeSigaud
Copy link
Collaborator

Ideally, ! (and maybe &) operators should 'gag' actions, disabling them. I think I see how to do that, with an internal NoAction!() operator that propagates towards the children until it finds an Action!() member.

Or else, I can just put in the docs that expressions used inside lookahead should not have side effects?

@callumenator
Copy link
Collaborator Author

Ideally, ! (and maybe &) operators should 'gag' actions, disabling them. I think I see how to do that, with an >internal NoAction!() operator that propagates towards the children until it finds an Action!() member.

Yeh I probably agree.

Or else, I can just put in the docs that expressions used inside lookahead should not have side effects?

If you have a rule on an action, you would then also need a no-action version of it. I think gagging the look-ahead's is better.

@PhilippeSigaud
Copy link
Collaborator

Or else, I can just put in the docs that expressions used inside lookahead
should not have side effects?

If you have a rule on an action, you would then also need a no-action
version of it. I think gagging the look-ahead's is better.

And I guess gagging could be made into a generic mechanism, useful for
something else.

@callumenator
Copy link
Collaborator Author

And I guess gagging could be made into a generic mechanism, useful for
something else.

Definitely, I have needed it before, and worked around it with two versions of the same rule.

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