Native OCaml Rego/OPA policy engine
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Resolve all shift/reduce conflicts in Rego parser

4 conflicts, all inherent to Rego's grammar where postfix operators
(call, bracket-ref) are ambiguous with rule/statement boundaries:

- LPAREN/LBRACK after term_expr in rule heads: resolved by giving
the infix_expr->term_expr reduction %prec below_LPAREN
- SEMICOLON after literal_stmt in queries: resolved by giving
the single-statement reduction %prec below_SEMI
- LBRACK after contains_key: resolved by giving the bare
CONTAINS rule %prec below_LPAREN

+8 -3
+8 -3
lib/parser.mly
··· 43 43 %nonassoc EQEQ BANGEQ LT GT LE GE 44 44 %left PLUS MINUS 45 45 %left STAR SLASH PERCENT 46 + (* Dummy token for reducing term_expr → infix_expr at lower precedence 47 + than LPAREN/LBRACK postfix operators, resolving the shift/reduce 48 + conflicts in rule heads and contains_key. *) 49 + %nonassoc below_LPAREN below_SEMI 50 + %nonassoc LPAREN LBRACK SEMICOLON 46 51 47 52 %start <Ast.rego_module> rego_module 48 53 %start <Ast.expr> expr_only ··· 97 102 { RuleDefault (sp, r, [], op, v) } 98 103 | r=ref_expr CONTAINS k=contains_key IF b=rule_body 99 104 { RuleSpec (sp, RuleHeadSet (sp, r, Some k), [b]) } 100 - | r=ref_expr CONTAINS k=contains_key 105 + | r=ref_expr CONTAINS k=contains_key %prec below_LPAREN 101 106 { RuleSpec (sp, RuleHeadSet (sp, r, Some k), []) } 102 107 | r=ref_expr LPAREN a=separated_list(COMMA, expr) RPAREN 103 108 op=assign_op v=expr IF b=rule_body es=else_chain ··· 139 144 (* ── Query ─────────────────────────────────────────────────────────────── *) 140 145 141 146 query_stmts: 142 - | s=literal_stmt { [s] } 147 + | s=literal_stmt { [s] } %prec below_SEMI 143 148 | s=literal_stmt SEMICOLON { [s] } 144 149 | s=literal_stmt SEMICOLON rest=query_stmts { s :: rest } 145 150 ; ··· 185 190 ; 186 191 187 192 infix_expr: 188 - | t=term_expr { t } 193 + | t=term_expr { t } %prec below_LPAREN 189 194 | l=infix_expr PLUS r=infix_expr { ArithExpr (sp, Add, l, r) } 190 195 | l=infix_expr MINUS r=infix_expr { ArithExpr (sp, Sub, l, r) } 191 196 | l=infix_expr STAR r=infix_expr { ArithExpr (sp, Mul, l, r) }