Files
regorus/tests/parser/cases/some/some.vars.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

81 lines
1.6 KiB
YAML

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cases:
- note: single-multi-vars
rego: |
package test
x = y {
# Single var
some a
# Multiple var. With and without spaces.
some
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:
some-vars:
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: |
package test
x = y {
some a some b
}
error: expecting `}` while parsing query
- note: keyword
rego: |
package test
x = y {
some as
}
error: unexpected keyword `as`
- note: top-level
rego: |
package test
x = some y
error: unexpected keyword `some`
- note: top-level1
rego: |
package test
some y
error: unexpected keyword `some`
- note: some-in-set
rego: |
package test
x = { some y }
error: unexpected keyword `some`
- note: non-var
rego: |
package test
x = y {
some a, 5
}
error: encountered `5` while expecting identifier