1
0
dust/tree-sitter-dust/corpus/functions.txt

251 lines
6.1 KiB
Plaintext

================================================================================
Anonymous Function
================================================================================
(fn) <str> { "Hiya" }
--------------------------------------------------------------------------------
(root
(statement
(expression
(value
(function
(type_definition
(type))
(block
(statement
(expression
(value
(string))))))))))
================================================================================
Function Declaration
================================================================================
foobar = (fn x <int>, y <int>) <int> {
x + y
}
--------------------------------------------------------------------------------
(root
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(value
(function
(identifier)
(type_definition
(type))
(identifier)
(type_definition
(type))
(type_definition
(type))
(block
(statement
(expression
(math
(expression
(identifier))
(math_operator)
(expression
(identifier)))))))))))))
================================================================================
Function Call
================================================================================
(foobar "Hiya")
--------------------------------------------------------------------------------
(root
(statement
(expression
(function_call
(function_expression
(identifier))
(expression
(value
(string)))))))
================================================================================
Function Expressions
================================================================================
(foobar "Hiya")
(foo:bar "Hiya")
((foobar) "Hiya")
((fn msg <str>) <str> { msg } "Hiya")
--------------------------------------------------------------------------------
(root
(statement
(expression
(function_call
(function_expression
(identifier))
(expression
(value
(string))))))
(statement
(expression
(function_call
(function_expression
(index
(expression
(identifier))
(expression
(identifier))))
(expression
(value
(string))))))
(statement
(expression
(function_call
(function_expression
(function_call
(function_expression
(identifier))))
(expression
(value
(string))))))
(statement
(expression
(function_call
(function_expression
(value
(function
(identifier)
(type_definition
(type))
(type_definition
(type))
(block
(statement
(expression
(identifier)))))))
(expression
(value
(string)))))))
================================================================================
Complex Function Call
================================================================================
(foobar
"hi"
42
{
x = 1
y = 2
}
)
--------------------------------------------------------------------------------
(root
(statement
(expression
(function_call
(function_expression
(identifier))
(expression
(value
(string)))
(expression
(value
(integer)))
(expression
(value
(map
(identifier)
(statement
(expression
(value
(integer))))
(identifier)
(statement
(expression
(value
(integer)))))))))))
================================================================================
Callback Function Call
================================================================================
x = (fn cb <() -> bool>) <bool> {
(cb)
}
(x (fn) <bool> { true })
--------------------------------------------------------------------------------
(root
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(value
(function
(identifier)
(type_definition
(type
(type)))
(type_definition
(type))
(block
(statement
(expression
(function_call
(function_expression
(identifier))))))))))))
(statement
(expression
(function_call
(function_expression
(identifier))
(expression
(value
(function
(type_definition
(type))
(block
(statement
(expression
(value
(boolean))))))))))))
================================================================================
Nested Function Call
================================================================================
(from_json (read 'file.json'))
--------------------------------------------------------------------------------
(root
(statement
(expression
(function_call
(function_expression
(identifier
(built_in_function)))
(expression
(function_call
(function_expression
(identifier
(built_in_function)))
(expression
(value
(string)))))))))