summaryrefslogtreecommitdiff
path: root/queries/elixir/99-function.scm
blob: a20455d7c3f03d96b12495416f1b1f2abb5a0ca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
; named functions
; 1. arguments and inline do block
(call
  target: (identifier) @_func_type
  (arguments
    (call
      target: (identifier)
      (do_block) @context.body))
  (#any-of? @_func_type "def" "defp" "defmacro" "defmacrop")) @context.function

; 2. arguments and separate do block
(call
  target: (identifier) @_func_type
  (arguments
    (call
      target: (identifier)
      (arguments)))
  (do_block) @context.body
  (#any-of? @_func_type "def" "defp" "defmacro" "defmacrop")) @context.function

; 3. without arguments just identifier
(call
  target: (identifier) @_func_type
  (arguments
    (identifier))
  (do_block) @context.body
  (#any-of? @_func_type "def" "defp" "defmacro" "defmacrop")) @context.function

; anonymous functions
; 1. module attributes (@name fn -> end) with body
(unary_operator
  (call
    (arguments
      (anonymous_function
        (stab_clause
          right: (body) @context.body))))) @context.function

; 2. without body (empty @name fn x -> end)
(unary_operator
  (call
    (arguments
      (anonymous_function
        (stab_clause
          (arguments)))))) @context.function