Files
regorus/tests/parser/cases/every/every.yaml
Anand Krishnamoorthi 444b2970a1 feat!: Indexes for nodes in the AST (#414)
Indexes allow associating extra data with nodes in the AST
using an array and then quickly looking up the array to fetch
the extra data.

- Index eidx for expressions
- Index sidx for statements
- Index qidx for queries.

AST nodes are not cloneable. Therefore once a module is created,
it is not possible to accidentally create two nodes with the same
index inadvertently via clone.

Also added IndexChecker in debug builds. When a module is parsed,
it will assert that indexes have been constructed correctly.

AST Cleanup
- Make literal expressions (null, val, number, string etc) also structs
  to match all other expressions
- Merge True and False nodes into a single Bool node.

Also update dependencies.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2025-06-20 15:09:07 -05:00

82 lines
2.6 KiB
YAML

# Copyright (c) Microsoft Corporation. Licensed under the MIT
# License.
cases:
- note: basic
rego: |
package test
import future.keywords
y = 8 {
every x in [2] {
x > 0
every a, b in vals { check(a) }
}
}
num_expressions: 14
num_queries: 3
num_statements: 4
policy:
- spec:
head:
compr:
refr:
var: y
eidx: 3
assign:
op: "="
value:
number: 8
eidx: 4
bodies:
- query:
qidx: 2
stmts:
- sidx: 3
literal:
every:
value: x
domain:
array:
- number: 2
eidx: 5
eidx: 6
query:
qidx: 1
stmts:
- sidx: 0
literal:
expr:
boolexpr:
op: ">"
lhs:
var: x
eidx: 7
rhs:
number: 0
eidx: 8
eidx: 9
- sidx: 2
literal:
every:
key: a
value: b
domain:
var: vals
eidx: 10
query:
qidx: 0
stmts:
- sidx: 1
literal:
expr:
call:
fcn:
var: check
eidx: 11
params:
- var: a
eidx: 12
eidx: 13