grammar: Update to support and and or keywords - #212
Merged
Conversation
Adds the `and` and `or` logical keywords from open-policy-agent/opa#8999 to the lexer and grammar, following the precedence defined in open-policy-agent/opa#8677: `not` > `and` > `or` > `with`. Operands can be a single expression (`a or b`), an explicit body (`{a} or {b; c}`) or a parenthesized group (`(a or b) and c`). A `{...}` operand is only read as a body when an `and`/`or` follows it, so sets, objects and rule bodies keep parsing as before. A trailing `with` applies to the whole expression. Both keywords are also accepted as identifiers, as they remain identifiers in policies that do not import them, and `not` is accepted after a dot in a ref so that `import future.keywords.not` parses. Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
charlieegan3
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the new
and/orlogical keywords to the lexer and grammar with the precedence from open-policy-agent/opa#8677 (not>and>or>with), supporting single-expression, explicit-body and parenthesized operands; this is the IDEA item of open-policy-agent/opa#8999.Both keywords are also accepted as identifiers, since they stay identifiers in policies that do not import them, and
notis now accepted after a dot in a ref so thatimport future.keywords.notparses.