Files
regorus/tests/parser/cases/expressions/object.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

220 lines
6.2 KiB
YAML

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cases:
- note: all
rego: |
package test
import future.keywords.in
# Empty object
x = {}
# Single field
y = {
"a" : 5
}
# Multiple fields
z = {
"a" : 5,
"b" : [ 1, 2, 3 ],
"c" : { 4, 5, 6 },
"d" : {
"a" : 5,
"b" : set()
}
# array as key
, [1,
2,
3] : 4,
# set as key
{ 1 } : 2,
# Object as key
{
"a" : 1,
"b" : 2, # Trailing comma
} : `hello,
world`
# Null, boolean
, null: false,
true : true,
# Only single var in is supported as value
"p" : "q", "r" in "d" : "e"
}
num_expressions: 54
num_statements: 0
num_queries: 0
policy:
- spec:
span: x = {}
head:
compr:
span: x = {}
refr:
var: x
eidx: 4
assign:
span: = {}
op: =
value:
object:
fields: []
eidx: 5
bodies: []
- spec:
head:
compr:
refr:
var: y
eidx: 6
assign:
op: =
value:
object:
fields:
- key:
string: a
eidx: 7
value:
number: 5
eidx: 8
eidx: 9
bodies: []
- spec:
head:
compr:
refr:
var: z
eidx: 10
assign:
op: =
value:
object:
fields:
- key:
string: a
eidx: 11
value:
number: 5
eidx: 12
- key:
string: b
eidx: 13
value:
array:
- number: 1
eidx: 14
- number: 2
eidx: 15
- number: 3
eidx: 16
eidx: 17
- key:
string: c
eidx: 18
value:
set:
- number: 4
eidx: 19
- number: 5
eidx: 20
- number : 6
eidx: 21
eidx: 22
- key:
string: d
eidx: 23
value:
object:
fields:
- key:
string: a
eidx: 24
value:
number: 5
eidx: 25
- key:
string: b
eidx: 26
value:
set: []
eidx: 27
eidx: 28
- key:
array:
- number: 1
eidx: 29
- number: 2
eidx: 30
- number: 3
eidx: 31
eidx: 32
value:
number: 4
eidx: 33
- key:
set:
- number: 1
eidx: 34
eidx: 35
value:
number: 2
eidx: 36
- key:
object:
fields:
- key:
string: a
eidx: 37
value:
number: 1
eidx: 38
- key:
string: b
eidx: 39
value:
number: 2
eidx: 40
eidx: 41
value:
rawstring: "hello,\n world"
eidx: 42
- key:
"null": null
eidx: 43
value:
bool: false
eidx: 44
- key:
bool: true
eidx: 45
value:
bool: true
eidx: 46
- key:
string: p
eidx: 47
value:
string: q
eidx: 48
- key:
inexpr:
value:
string: r
eidx: 49
collection:
string: d
eidx: 50
eidx: 51
value:
string: e
eidx: 52
eidx: 53
bodies: []