tree-sitter-elixir/test/corpus/expression/anonymous_function.txt

312 lines
5.0 KiB
Plaintext

=====================================
no arguments
=====================================
fn() -> 1 end
fn () -> 1 end
---
(source
(anonymous_function
(stab_clause
(arguments)
(body
(integer))))
(anonymous_function
(stab_clause
(arguments)
(body
(integer)))))
=====================================
no arguments without parentheses
=====================================
fn -> 1 end
---
(source
(anonymous_function
(stab_clause
(body
(integer)))))
=====================================
one argument
=====================================
fn(x) -> x end
---
(source
(anonymous_function
(stab_clause
(arguments
(identifier))
(body
(identifier)))))
=====================================
one argument without parentheses
=====================================
fn x -> x end
---
(source
(anonymous_function
(stab_clause
(arguments
(identifier))
(body
(identifier)))))
=====================================
many arguments
=====================================
fn(x, y, z) -> x + y end
---
(source
(anonymous_function
(stab_clause
(arguments
(identifier)
(identifier)
(identifier))
(body
(binary_operator
(identifier)
(identifier))))))
=====================================
many arguments without parentheses
=====================================
fn x, y -> x + y end
---
(source
(anonymous_function
(stab_clause
(arguments
(identifier)
(identifier))
(body
(binary_operator
(identifier)
(identifier))))))
=====================================
multiline body
=====================================
fn x, y ->
y
x
end
---
(source
(anonymous_function
(stab_clause
(arguments
(identifier)
(identifier))
(body
(identifier)
(identifier)))))
=====================================
many clauses
=====================================
fn
1 -> :yes
2 -> :no
other -> :maybe
end
---
(source
(anonymous_function
(stab_clause
(arguments
(integer))
(body
(atom)))
(stab_clause
(arguments
(integer))
(body
(atom)))
(stab_clause
(arguments
(identifier))
(body
(atom)))))
=====================================
with guard / no arguments
=====================================
fn
() when node() == :nonode@nohost -> true
end
---
(source
(anonymous_function
(stab_clause
(binary_operator
(arguments)
(binary_operator
(call
(identifier)
(arguments))
(atom)))
(body
(boolean)))))
=====================================
with guard / one argument
=====================================
fn
x when x == [] -> x
end
---
(source
(anonymous_function
(stab_clause
(binary_operator
(arguments
(identifier))
(binary_operator
(identifier)
(list)))
(body
(identifier)))))
=====================================
with guard / multiple arguments
=====================================
fn
x, y when x == [] -> x
end
---
(source
(anonymous_function
(stab_clause
(binary_operator
(arguments
(identifier)
(identifier))
(binary_operator
(identifier)
(list)))
(body
(identifier)))))
=====================================
with guard / arguments in parentheses
=====================================
fn
(x, y) when y == [] -> y
end
---
(source
(anonymous_function
(stab_clause
(binary_operator
(arguments
(identifier)
(identifier))
(binary_operator
(identifier)
(list)))
(body
(identifier)))))
=====================================
with guard / multiple guards
=====================================
fn
x when x > 10 when x < 5 -> x
end
---
(source
(anonymous_function
(stab_clause
(binary_operator
(arguments
(identifier))
(binary_operator
(binary_operator
(identifier)
(integer))
(binary_operator
(identifier)
(integer))))
(body
(identifier)))))
=====================================
pattern matching
=====================================
fn
[h | tail] -> {h, tail}
%{x: x} when x == 1 -> 1
end
---
(source
(anonymous_function
(stab_clause
(arguments
(list
(binary_operator
(identifier)
(identifier))))
(body
(tuple
(identifier)
(identifier))))
(stab_clause
(binary_operator
(arguments
(map
(map_content
(keywords
(pair
(keyword)
(identifier))))))
(binary_operator
(identifier)
(integer)))
(body
(integer)))))