# The blank lines below me should be gone! (except one)

# Comment!
package a.b

# I also, am a comment.
import data.a.b.c # Another comment!
import data.x.y.z

# I belong with data.a, there should be a newline before me.
import data.a
import data.f.g

default foo := false

foo contains x if {
	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

partial_set contains "x"

# Latent comment.

r := y if {
	y = x
	split("foo.bar", ".", input.x) with input as {"x": x}
}

# Comment on else
else := y if {
	y = ["howdy"]
	x = {"x": {"y": "z"}}
	a = {
		"a": {"b": "c"},
		"b": "c", "c": [
			1, 2,
			3, 4,
		],
	}
}

fn(x) := y if {
	y = x
}

fn_else(x) := 1 if {
	true
} # foo

else := 2 if {
	# bar

	true
} else := 3 if {
	# baz

	false
}

long(x) if {
	x = "foo %host"
}

short(x) if {
	x = "bar"
}

raw_string := `hi\there`

raw_multiline := `this
string
  is on
multiple lines`

fn2(
	[
		x, y,
		z,
	],
	{"foo": a},
) := b if {
	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 contains x if {
	x = "hi"
}

f contains x if { # Comment on chain
	x = "bye"
}

import data.bar.foo # data.bar.foo should be first
import data.foo.bar

p[x] := y if {
	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 if {
	x + 1
	x = y + 2
	2 = x + 1
	x + 1
	y = f(x)
	f(x, y)
	y = (x + 1) + 2
	x = y + z # comment
	x = (a + b) / 2
	f((a + b) / 2)
	y = q()
}

expanded_const := true

partial_obj["why"] if false

empty_sets if {
	set()
	set() # comment at end of set
}

vardecls if {
	some v1, v2, # c1
		v3, v4, # c2
		v5 # c3
}

declare1 := 1

declare2 := 2 if false

declare3 := {1, 2, 3}

declare4 := {4, 5, 6}

union_object := {"response": (declare3 | declare4)}

union_set := {(declare3 | declare4)}

union_list := [(declare3 | declare4)]

union_set_2 := {(declare3 | declare4)}

union_object_multi_line := {"response": (declare3 | declare4)}

union_object_key := {(declare3 | declare4): "foo"}

union_object_key_multi_line := {(declare3 | declare4): "foo"}

# more comments!
# more comments!
# more comments!
# more comments!
