Support optional else-branch for if-then-elif-end (#2598)
This commit is contained in:
1 parent
4dc2a2fb9d
commit
12ce4e3b54
4 files changed
+388
-391
No files matched your search
@@ -2147,7 +2147,7 @@ sections:
|
|||||||
|
|
||||||
`if A then B end` is the same as `if A then B else . end`.
|
`if A then B end` is the same as `if A then B else . end`.
|
||||||
That is, the `else` branch is optional, and if absent is the
|
That is, the `else` branch is optional, and if absent is the
|
||||||
same as `.`.
|
same as `.`. This also applies to `elif` with absent ending `else` branch.
|
||||||
|
|
||||||
Checking for false or null is a simpler notion of
|
Checking for false or null is a simpler notion of
|
||||||
"truthiness" than is found in JavaScript or Python, but it
|
"truthiness" than is found in JavaScript or Python, but it
|
||||||
|
|||||||
+377
-387
File diff suppressed because it is too large.
Load diff
+3
-3
@@ -367,9 +367,6 @@ Term "as" Patterns '|' Exp {
|
|||||||
"if" Exp "then" Exp ElseBody {
|
"if" Exp "then" Exp ElseBody {
|
||||||
$$ = gen_cond($2, $4, $5);
|
$$ = gen_cond($2, $4, $5);
|
||||||
} |
|
} |
|
||||||
"if" Exp "then" Exp "end" {
|
|
||||||
$$ = gen_cond($2, $4, gen_noop());
|
|
||||||
} |
|
|
||||||
"if" Exp "then" error {
|
"if" Exp "then" error {
|
||||||
FAIL(@$, "Possibly unterminated 'if' statement");
|
FAIL(@$, "Possibly unterminated 'if' statement");
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
@@ -625,6 +622,9 @@ ElseBody:
|
|||||||
} |
|
} |
|
||||||
"else" Exp "end" {
|
"else" Exp "end" {
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
|
} |
|
||||||
|
"end" {
|
||||||
|
$$ = gen_noop();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpD:
|
ExpD:
|
||||||
|
|||||||
@@ -1116,6 +1116,13 @@ null
|
|||||||
7
|
7
|
||||||
[7]
|
[7]
|
||||||
|
|
||||||
|
[if false then 3 elif false then 4 end]
|
||||||
|
7
|
||||||
|
[7]
|
||||||
|
|
||||||
|
[if false then 3 elif false then 4 else . end]
|
||||||
|
7
|
||||||
|
[7]
|
||||||
|
|
||||||
[.[] | [.foo[] // .bar]]
|
[.[] | [.foo[] // .bar]]
|
||||||
[{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]
|
[{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]
|
||||||
|
|||||||
Reference in new issue
Block a user