You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to fix this too (not sure if I'll be capable to do this earlier though - from what I can see so far, we'll definitely need to consider to switch asap from when (true) and (true) or (true) thing to more conventional (true and true or true), because the parsing of irregular and directly opposite parens patterns for logical-and-or-not and logical-anything-else expressions incredibly clutters the code (not counting not-so-friendly-and-easy to explain/understand guards usage in a long run)).
You mean not require parenthesis around true and false?
Yes, but not only. It's actually more about requiring outer parens after when and for anything else parens to be optional. But in either case this would mean a breaking change.
I.e.:
with "required outer parens", currently valid when (true) and (true) or (true) becomes illegal
with "optional outer parens", too ambiguous stuff like when true, true > false comes in (sincetrue > false is also a selector).
I recall that when is allowed only in rulesets with one selector, so that concrete example of optional outer parens should not be ambigous. It was discussed in some issue a while ago.
I recall that when is allowed only in rulesets with one selector,
And it's the parser that has to test for , ( pattern and throw a error if it's just , .... So we either have to throw away , as an or operator, or require parens after , (and thus after when in general) at least to distinguish between condition, selector and condition, condition.
A breaking change in any case.
@seven-phases-max Cant we just assume that what follows , is another condition, try to parse out that condition and fail only if it is not there? We do not have to use the , ( optimization.
Cant we just assume that what follows , is another condition, try to parse out that condition and fail only if it is not there?
We can. But then someone writes something like:
htmlwhentrue,
body {
font-size: 16px
}
and the compiler interprets it as
htmlwhentrue, false {
font-size: 16px;
}
thus silently throwing body away (as it's parsed as valid (keyword) condition evaluating to false).
We still can require () after the comma but it will get us back to:
when true or false {}
when true, (false) {}
// why they are different?
or
when (true or false) {}
when (true), (false) {}
// why they are different?
Interestingly, these works: .test when (8+4 < 13) {}
Yes, I suppose this is because when we have the first inner parens in when ((x) < 3) the parser enters condition() -> conditionAnd() and stops here thus still returning properly parsed (x) value ( stored as (x = true) condition), but next comes only < 3 which isn't already parseable (since neither of comparision operands can be a condition(), thus the parser can't even try the other way around). <- well, roughly...
And the reverted expression works simply because the parser instantly goes down to this.addition() and "incomplete and/or values" don't interfere there.
when true or false {} // should fail
when true, (false) {} // should fail
when (true or false) {} // should pass
when (true), (false) {} // should pass
being illegal outside of parentheses, which it doesn't have to be.
It depends on what we're about. If it's about the current behaviour then there's no , issue, nothing to discuss.
If we're about #2807, then there're two variants as in #2798 (comment). The first variant bans the comma at all, and the second variant is about to ban it too (otherwise the mentioned ambiguity jumps in).
@matthew-dean@SomMeri
I don't see any bug in the example of #2798 (comment).
It's actually just a more user-friendly error message for the ambiguous syntax - if you remove that special test for , (, the error becomes just unrecongnised input, expected condition (is that what would you expect?).
@seven-phases-max By a bug, I mean that it's weird (unexpected) that a mixin can have a comma-guard and a selector can't. That said, per: #2807 (comment), let's get rid of the comma soon.
it's weird (unexpected) that a mixin can have a comma-guard and a selector can't.
I guess you both are missing that x ruleset there is actually valid and compiles fine, it's only the invalid y that throws the error. So still no real bug there (the example is only used to illustrate the ambiguity if we would allow the "all-parens-optional" syntax and don't ban comma).
I guess you both are missing that x ruleset there is actually valid and compiles fine, it's only the invalid y that throws the error. So still no real bug there
The bug would be that y should not be invalid if y is a valid when condition.
If there's consensus, though, we could mark that bug as "wontfix" until the comma is deprecated / removed. The docs don't yet mention the "or" keyword though.
Activity
seven-phases-max commentedon Feb 2, 2016
It's most likely because of #2763 (it seems that this kind of expressions is not covered by tests unfortunately).
[-]Handing parentheses in expressions appears broken in 2.6.0[/-][+]Guard expressions regression in 2.6.0[/+]seven-phases-max commentedon Feb 2, 2016
A minimal examples to reproduce:
SomMeri commentedon Feb 7, 2016
I will have a look at this, next week at latest. Adding some new tests might be a good idea too.
seven-phases-max commentedon Feb 7, 2016
I'm trying to fix this too (not sure if I'll be capable to do this earlier though - from what I can see so far, we'll definitely need to consider to switch asap from
when (true) and (true) or (true)thing to more conventional(true and true or true), because the parsing of irregular and directly opposite parens patterns for logical-and-or-not and logical-anything-else expressions incredibly clutters the code (not counting not-so-friendly-and-easy to explain/understand guards usage in a long run)).SomMeri commentedon Feb 7, 2016
You mean not require parenthesis around
trueandfalse? It would make sense to me.seven-phases-max commentedon Feb 7, 2016
Yes, but not only. It's actually more about requiring outer parens after
whenand for anything else parens to be optional. But in either case this would mean a breaking change.I.e.:
when (true) and (true) or (true)becomes illegalwhen true, true > falsecomes in (sincetrue > falseis also a selector).SomMeri commentedon Feb 7, 2016
I recall that
whenis allowed only in rulesets with one selector, so that concrete example of optional outer parens should not be ambigous. It was discussed in some issue a while ago.seven-phases-max commentedon Feb 7, 2016
And it's the parser that has to test for
, (pattern and throw a error if it's just, .... So we either have to throw away,as anoroperator, or require parens after,(and thus afterwhenin general) at least to distinguish betweencondition, selectorandcondition, condition.A breaking change in any case.
SomMeri commentedon Feb 8, 2016
@seven-phases-max Cant we just assume that what follows
,is another condition, try to parse out that condition and fail only if it is not there? We do not have to use the, (optimization.SomMeri commentedon Feb 8, 2016
Interestingly, these works:
.test when (8+4 < 13) {}.test when (8+(5-1) < 13) {}.test when (8 < (13+1))It seems like it specifically does not allow parenthesis around left side.
seven-phases-max commentedon Feb 8, 2016
We can. But then someone writes something like:
and the compiler interprets it as
thus silently throwing
bodyaway (as it's parsed as valid(keyword)condition evaluating tofalse).We still can require
()after the comma but it will get us back to:or
seven-phases-max commentedon Feb 8, 2016
Yes, I suppose this is because when we have the first inner parens in
when ((x) < 3)the parser enterscondition() -> conditionAnd()and stops here thus still returning properly parsed(x)value ( stored as(x = true)condition), but next comes only< 3which isn't already parseable (since neither of comparision operands can be acondition(), thus the parser can't even try the other way around). <- well, roughly...And the reverted expression works simply because the parser instantly goes down to
this.addition()and "incompleteand/orvalues" don't interfere there.3 remaining items
matthew-dean commentedon Feb 11, 2016
That is:
seven-phases-max commentedon Feb 11, 2016
It depends on what we're about. If it's about the current behaviour then there's no
,issue, nothing to discuss.If we're about #2807, then there're two variants as in #2798 (comment). The first variant bans the comma at all, and the second variant is about to ban it too (otherwise the mentioned ambiguity jumps in).
matthew-dean commentedon Feb 11, 2016
I don't see how. o_O Any comma after a
whenand before{is part of thewhenstatement.seven-phases-max commentedon Feb 11, 2016
It's not even true for the current behaviour. And especially it doesn't have to be for the planned one.
matthew-dean commentedon Feb 11, 2016
@seven-phases-max
Then that's a bug.
whenstatements can have commas. They shouldn't be treated differently than mixin guards.SomMeri commentedon Feb 11, 2016
@matthew-dean @seven-phases-max I think that comma after when inside ruleset is a bug, but different one then this one. It might even be harder to fix.
seven-phases-max commentedon Feb 11, 2016
@matthew-dean @SomMeri
I don't see any bug in the example of #2798 (comment).
It's actually just a more user-friendly error message for the ambiguous syntax - if you remove that special test for
, (, the error becomes justunrecongnised input, expected condition(is that what would you expect?).matthew-dean commentedon Feb 11, 2016
@seven-phases-max By a bug, I mean that it's weird (unexpected) that a mixin can have a comma-guard and a selector can't. That said, per: #2807 (comment), let's get rid of the comma soon.
SomMeri commentedon Feb 11, 2016
I considered it a bug for the same reason as @matthew-dean - because it is different then in mixin. I agree with deprecating comma for 3.0.
seven-phases-max commentedon Feb 11, 2016
I guess you both are missing that
xruleset there is actually valid and compiles fine, it's only the invalidythat throws the error. So still no real bug there (the example is only used to illustrate the ambiguity if we would allow the "all-parens-optional" syntax and don't ban comma).matthew-dean commentedon Feb 11, 2016
The bug would be that
yshould not be invalid ifyis a validwhencondition.If there's consensus, though, we could mark that bug as "wontfix" until the comma is deprecated / removed. The docs don't yet mention the "or" keyword though.
SomMeri commentedon Feb 11, 2016
@matthew-dean I created new issue for that in docs #396.
Btw, it is great that less.js is getting more active lately 👍 .
This fixes less#2798 - left part of inequality could not be enclosed in
Merge pull request #2819 from SomMeri/issue-2798-guards-regression