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

173 lines
3.5 KiB
YAML

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cases:
- note: single-char
rego: package a
num_expressions: 1
num_statements: 0
num_queries: 0
package:
span: package a
refr:
var: a
eidx: 0
- note: simple
rego: package test
num_expressions: 1
num_statements: 0
num_queries: 0
package:
span: package test
refr:
var: test
eidx: 0
- note: dot
rego: package a.b
num_expressions: 2
num_statements: 0
num_queries: 0
package:
span: package a.b
refr:
refdot:
span: a.b
refr:
var: a
eidx: 0
field: b
eidx: 1
- note: multi-dot
rego: package a.b.c
num_expressions: 3
num_statements: 0
num_queries: 0
package:
span: package a.b.c
refr:
refdot:
span: a.b.c
refr:
refdot:
span: a.b
refr:
var: a
eidx: 0
field: b
eidx: 1
field: c
eidx: 2
- note: bracket
rego: package a["b"]
num_expressions: 3
num_statements: 0
num_queries: 0
package:
span: package a["b"]
refr:
refbrack:
span: a["b"]
refr:
var: a
eidx: 0
index:
string: b
eidx: 1
eidx: 2
- note: multi-bracket
rego: package a["b"]["c.d"]
num_expressions: 5
num_statements: 0
num_queries: 0
package:
span: package a["b"]["c.d"]
refr:
refbrack:
span: a["b"]["c.d"]
refr:
refbrack:
span: a["b"]
refr:
var: a
eidx: 0
index:
string: b
eidx: 1
eidx: 2
index:
string: c.d
eidx: 3
eidx: 4
- note: complex
rego: package a["b.c"].d["e.f"].g
num_expressions: 7
num_statements: 0
num_queries: 0
package:
span: package a["b.c"].d["e.f"].g
refr:
refdot:
span: a["b.c"].d["e.f"].g
refr:
refbrack:
span: a["b.c"].d["e.f"]
refr:
refdot:
span: a["b.c"].d
refr:
refbrack:
span: a["b.c"]
refr:
var: a
eidx: 0
index:
string: "b.c"
eidx: 1
eidx: 2
field: d
eidx: 3
index:
string: e.f
eidx: 4
eidx: 5
field: g
eidx: 6
- note: missing-package-keyword
rego: packge a
error: expecting `package`
- note: missing-var
rego: package 5
error: expecting identifier
- note: missing-var-1
rego: package (
error: expecting identifier
- note: missing-field
rego: package a.b.
error: expecting identifier
- note: space-after-dot
rego: package a. b
error: invalid whitespace between . and identifier
- note: space-before-dot
rego: package a .b
error: invalid whitespace before .
- note: space-after-lbracket
rego: package a ["b"]
error: invalid whitespace before [
- note: non-string-index
rego: package a[1]
error: expected string