`rego.v1` enforces `if` before chained rule bodies, not allowed by parser
johanfylling opened this issue · 4 comments
johanfylling commented
The policy:
package play
import rego.v1
p if {
input.x == 1
} {
input.x == 2
}
will produce error:
1 error occurred: policy.rego:7: rego_parse_error: `if` keyword is required before rule body
However, updating the policy by adding an if
to the second body:
package play
import rego.v1
p if {
input.x == 1
} if {
input.x == 2
}
will produce error:
1 error occurred: policy.rego:7: rego_parse_error: unexpected if keyword
} if {
^
johanfylling commented
Three possible solutions:
- Don't require
if
on chained bodies despiterego.v1
import - Update parser to allow
if
on chained bodies - Don't allow chained bodies in
1.0
2
has added benefit of clarity (depending on view, of course):
p if {
input.x == 1
} if {
input.x == 2
}
as the added if
makes the separation of the bodies somewhat more obvious.
3
might be too obtrusive if this is a commonly used pattern.
ashutosh-narkar commented
If we believe it's a commonly used pattern, would option 1
be better? You can make the argument that the first if
applies to the chain maybe.
anderseknert commented
Agreed — since the purpose of chained bodies is likely compactness, I feel like it's fine to only require if
in the visible rule head. So I vote for 1
too.
johanfylling commented
Alright, so far it looks like no 1 has it 👍.