tree-sitter-bp/test/corpus/expressions.txt

400 lines
9.3 KiB
Plaintext

================================================================================
Boolean
================================================================================
foo = false
foo = true
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(boolean_literal))
(assignment
(identifier)
(operator)
(boolean_literal)))
================================================================================
Boolean (identifier/literal)
================================================================================
true = false
false = true
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(boolean_literal))
(assignment
(identifier)
(operator)
(boolean_literal)))
================================================================================
Integer
================================================================================
foo = 0
foo = 42
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(integer_literal))
(assignment
(identifier)
(operator)
(integer_literal)))
================================================================================
Integer (negative)
================================================================================
foo = -0
foo = -42
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(integer_literal))
(assignment
(identifier)
(operator)
(integer_literal)))
================================================================================
String
================================================================================
foo = "Hello World!"
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(interpreted_string_literal)))
================================================================================
String (escape)
================================================================================
foo = "Hello\nWorld!"
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(interpreted_string_literal
(escape_sequence))))
================================================================================
String (raw)
================================================================================
foo = `Hello\nWorld!`
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(raw_string_literal)))
================================================================================
List (empty)
================================================================================
foo = []
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(list_expression)))
================================================================================
List (singleton)
================================================================================
foo = [42]
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(list_expression
(integer_literal))))
================================================================================
List (singleton multiline)
================================================================================
foo = [
42
]
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(list_expression
(integer_literal))))
================================================================================
List (singleton trailing comma)
================================================================================
foo = [
42,
]
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(list_expression
(integer_literal))))
================================================================================
List (mixed values)
================================================================================
foo = [
42,
"foobar",
]
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(list_expression
(integer_literal)
(interpreted_string_literal))))
================================================================================
List (list of list)
================================================================================
foo = [
[42],
["foobar"],
[],
]
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(list_expression
(list_expression
(integer_literal))
(list_expression
(interpreted_string_literal))
(list_expression))))
================================================================================
List (rogue comma)
================================================================================
foo = [
,
]
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(list_expression
(ERROR))))
================================================================================
Map (empty)
================================================================================
foo = {}
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(map_expression)))
================================================================================
Map (singleton)
================================================================================
foo = {foo:42}
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(map_expression
(property
(identifier)
(integer_literal)))))
================================================================================
Map (singleton multiline)
================================================================================
foo = {
foo: 42
}
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(map_expression
(property
(identifier)
(integer_literal)))))
================================================================================
Map (singleton trailing comma)
================================================================================
foo = {
foo: 42,
}
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(map_expression
(property
(identifier)
(integer_literal)))))
================================================================================
Map (mixed values)
================================================================================
foo = {
answer: 42,
value: "foobar",
}
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(map_expression
(property
(identifier)
(integer_literal))
(property
(identifier)
(interpreted_string_literal)))))
================================================================================
Map (map of map)
================================================================================
foo = {
the: {answer: 42},
}
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(map_expression
(property
(identifier)
(map_expression
(property
(identifier)
(integer_literal)))))))
================================================================================
Map (rogue comma)
================================================================================
foo = {
,
}
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(map_expression
(ERROR))))
================================================================================
Binary operators
================================================================================
foo = [
-12 + -27 + 42,
"a" + "b",
]
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(list_expression
(binary_expression
(binary_expression
(integer_literal)
(operator)
(integer_literal))
(operator)
(integer_literal))
(binary_expression
(interpreted_string_literal)
(operator)
(interpreted_string_literal)))))