-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feature request: elsif #72
Comments
I'm not sure how this would be implemented. The Thoughts? |
Seeing as there are no suggestions for how to implement this, I'm closing it. If anyone has ideas or a PR for this, we'll gladly reconsider. |
Reopening as I think the recent inverse and program changes from @mmun might allow for something like multiple chained inverses if we can get the Jison productions to agree. Some concerns to think about:
|
In terms of the actual execution, inverse would effectively become a chain, so there would be no helper changes needed and they would not need to be aware of anything more than "there is something after me in the negative case" which they would continue to define as they please. |
@kpdecker This is nice! I'm surprised by this, but in a good way. I'd love to look at an implementation when we have one 😄 |
I am intrigued as well and curious how it could be generalized for other use cases besides |
a suggestion: you can do elseif parsing in compiler and group them, then test them and run the specified branch in if block. here is an implementation of xtemplate: example:
compiled to var id2 = scope.resolve(["x"]);
var exp4 = id2;
var id3 = scope.resolve(["y"]);
exp4 = (id2) > (id3);
params1.push(exp4);
option0.params = params1;
option0.fn = function (scope, buffer) {
buffer.append('\n1\n');
return buffer;
};
var elseIfs5 = []
var elseIf6 = {}
elseIf6.test = function (scope) {
var id7 = scope.resolve(["x"]);
var exp9 = id7;
var id8 = scope.resolve(["z"]);
exp9 = (id7) > (id8);
return (exp9);
};
elseIf6.fn = function (scope, buffer) {
buffer.append('\n2\n');
return buffer;
};
elseIfs5.push(elseIf6);
option0.elseIfs = elseIfs5;
pos.line = 1;
pos.col = 6;
buffer = ifCommand.call(tpl, scope, option0, buffer);
return buffer; |
The basic approach here creates ambiguous parse trees.
and
Can't be expressed in a context free manner as long as the same syntax construct is used to both start an inversed block and the chained inverse operation. In order to support this feature, we will need to define a syntax that is only used for the chained operations. One thought is using |
Allows users to chain multiple helpers together using their inverse callbacks. I.e. ``` {{#if foo}} {{else if bar}} {{else}} {{/if}} ``` The control flow here effectively causes the helpers to be nested. The above is actually syntactic sugar for this: ``` {{#if foo}} {{else}} {{#if bar}} {{else}} {{/if}} {{/if}} ``` Any helper may be used in this manner, the only requirement is they support normal calls and inverse calls. Introduces a breaking change in that `{{else foo}}` may no longer be used as a root level operator. Instead `{{^foo}}` must be used. Fixes #72.
Closing in favor of #892 |
of course it can be done with the existing helpers (if, else, unless), but often elsif is just the natural choice people are used too.
The text was updated successfully, but these errors were encountered: