-
Here is my current query rule:
we initially used "operator precedence" and this rule worked fine for us. However, now we want to get rid of operator precedence and force users to use only one type of logical operator (allow |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Something like this would probably work: public query = this.RULE("query", () => {
this.SUBRULE2(this.expression, { LABEL: "lhs" })
// save the first operator so we can check that later operators match it.
let operator = undefined
this.MANY1({
DEF: () => {
operator = this.OR([
{
GATE: () => operator === undefined || operator === AND,
ALT: () => this.CONSUME(TOKEN.AND)
},
{
GATE: () => operator === undefined || operator === OR,
ALT: () => this.CONSUME(TOKEN.OR)
}
])
this.SUBRULE3(this.expression, { LABEL: "rhs" })
},
}) You can also probably solve it without the OR having a branch for every operator, but this way you will probably get better error messages. |
Beta Was this translation helpful? Give feedback.
-
Hello @hasanayan You can also evaluate modeling this restriction in a post parsing phase. In other words you could think of this as a formatting / linting rule instead of |
Beta Was this translation helpful? Give feedback.
Something like this would probably work:
You can also probably solve it without the OR having a branch …