/
test.rego
201 lines (168 loc) · 3.15 KB
/
test.rego
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# The blank lines below me should be gone! (except one)
# Comment!
package a.b
# I also, am a comment.
import data.x.y.z
import data.a.b.c # Another comment!
# I belong with data.a, there should be a newline before me.
import data.a
import data.f.g
default foo = false
foo[x] {
not x = g
f(x) = 1
g(
x, "foo"
) = z
}
globals = {"foo": "bar",
"fizz": "buzz"}
partial_obj["x"] = 1
partial_obj.y = 2
partial_obj["z"] = 3 {
true
}
partial_set["x"]
partial_set.y
# Latent comment.
r = y {
y = x
split("foo.bar", ".", input.x) with input as {"x": x}
}
# Comment on else
else = y {
y = ["howdy"]
x = {"x": {
"y": "z",
}}
a = {"a": {
"b": "c",
}, "b": "c", "c": [1, 2,
3, 4]}
}
fn(x) = y {
y = x
}
fn_else(x) = 1 {
true
} # foo
else =
# bar
2
{
true
} else = 3
# baz
{
false
}
long(x) = true {
x = "foo %host"
}
short(x) {
x = "bar"
}
raw_string = `hi\there`
raw_multiline = `this
string
is on
multiple lines`
fn2([x, y,
z], {"foo": a}) = b {
split(x, y, c)
trim(a, z, d) # function comment 1
split(c[0], d, b)
x = sprintf("hello %v",
["world"])
#function comment 2
} # function comment 3
f[x] {
x = "hi"
} { # Comment on chain
x = "bye"
}
import data.foo.bar
import data.bar.foo # data.bar.foo should be first
p[x] = y { y = x
y = "foo"
z = { "a": "b", # Comment inside object 1
"b": "c" , "c": "d", # comment on object entry line
# Comment inside object 2
"d": "e",
# Comment before closing object brace.
} # Comment on closing object brace.
a = {"a": "b", "c": "d"}
b = [1, 2, 3, 4]
c = [1, 2,
# Comment inside array
3, 4,
5, 6, 7,
8,
# Comment before nested composite.
[
["foo"], # Comment inside nested composite.
["bar"], # Comment after last element in nested composite.
# Comment before nested composite closing bracket.
], # Comment on nested composite closing bracket.
# Comment before closing array bracket.
] # Comment on closing array bracket.
d = [1 | b[_]]
e = [1 | split("foo.bar", ".", x); x[_]]
f = [1 | split("foo.bar", ".", x)
x[_]]
g = [1 |
split("foo.bar", ".", x) # comment in array comprehension
x[_]
# inner comment
]
h = {1 | b[_]}
i = {1 | split("foo.bar", ".", x); x[_]}
j = {1 | split("foo.bar", ".", x)
x[_]}
k = {1 |
split("foo.bar", ".", x) # comment in set comprehension
x[_]
# inner comment
}
l = {"foo":1 | b[_]}
m = {y:
x | split("foo.bar", ".", x); y = x[_]}
n = {y: x | split("foo.bar", ".", x)
y = x[_]}
o = {y: x |
split("foo.bar", ".", x) # comment in object comprehension
y = x[_]
# inner comment
}
} # Comment on rule closing brace
nested_infix {
x + 1
x = y + 2
plus(x, 1, 2)
plus(x, 1)
y = f(x)
f(x, y)
y = x + 1 + 2
x = y + # comment
z
x = (a + b) / 2
f((a+b)/2)
y = q()
}
expanded_const = true
partial_obj["why"] = true { false }
empty_sets {
set()
set() # comment at end of set
}
vardecls {
some v1, v2,# c1
v3,v4, # c2
v5 # c3
}
declare1 := 1
declare2 := 2 { false }
# more comments!
# more comments!
# more comments!
# more comments!