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>
This commit is contained in:
Anand Krishnamoorthi
2025-06-20 15:09:07 -05:00
committed by GitHub
parent 620f8a4547
commit 444b2970a1
35 changed files with 2015 additions and 586 deletions
+7 -1
View File
@@ -13,11 +13,15 @@ cases:
d,e,
f
}
num_expressions: 3
num_statements: 2
num_queries: 1
policy:
- spec:
head: --skip--
bodies:
- query:
qidx: 0
stmts:
- span: some a
literal:
@@ -25,11 +29,13 @@ cases:
span: some a
vars:
- a
sidx: 0
- span: "some\n d,e,\n f"
literal:
some-vars:
span: "some\n d,e,\n f"
vars: [d, e, f]
sidx: 1
- note: same-line-error
rego: |
@@ -58,7 +64,7 @@ cases:
package test
some y
error: unexpected keyword `some`
- note: some-in-set
rego: |
package test