Path: blob/main/pkg/river/parser/testdata/valid/expressions.river
5302 views
// Literals
lit_number = 10
lit_float = 15.0
lit_string = "Hello, world!"
lit_ident = other_ident
lit_null = null
lit_true = true
lit_false = false
// Arrays
array_expr_empty = []
array_expr_one_element = [0]
array_expr = [0, 1, 2, 3]
array_expr_trailing = [0, 1, 2, 3,]
array_expr_multiline = [
0,
1,
2,
3,
]
array_expr_nested = [[1]]
// Objects
object_expr_empty = {}
object_expr_one_field = { field_a = 1 }
object_expr = { field_a = 1, field_b = 2 }
object_expr_trailing = { field_a = 1, field_b = 2, }
object_expr_multiline = {
field_a = 1,
field_b = 2,
}
object_expr_nested = { field_a = { nested_field_a = 1 } }
// Unary ops
not_something = !true
neg_number = -5
// Math binops
binop_sum = 1 + 2
binop_sub = 1 - 2
binop_mul = 1 * 2
binop_div = 1 / 2
binop_mod = 1 % 2
binop_pow = 1 ^ 2 ^ 3
// Compare binops
binop_eq = 1 == 2
binop_neq = 1 != 2
binop_lt = 1 < 2
binop_lte = 1 <= 2
binop_gt = 1 > 2
binop_gte = 1 >= 2
// Logical binops
binop_or = true || false
binop_and = true && false
// Mixed math operations
math = 1 + 2 - 3 * 4 / 5 % 6
compare_ops = 1 == 2 != 3 < 4 > 5 <= 6 >= 7
logical_ops = true || false && true
mixed_assoc = 1 * 3 + 5 ^ 3 - 2 % 1 // Test with both left- and right- associative operators
expr_parens = (5 * 2) + 5
// Accessors
field_access = a.b.c.d
element_access = a[0][1][2]
// Function calls
call_no_args = a()
call_one_arg = a(1)
call_multiple_args = a(1,2,3)
call_trailing_comma = a(1,2,3,)
call_multiline = a(
1,
2,
3,
)
mixed_expr = (a.b.c)(1, 3 * some_list[magic_index * 2]).resulting_field