Unnamed repository; edit this file 'description' to name the repository.
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
; Everything in Scheme is `(list (symbol) ...)`, so scopes and definitions are
; gated by `#eq?`/`#any-of?` predicates on the leading symbol of a form.

; Scopes

(list
  .
  (symbol) @_f
  (#any-of? @_f
    "lambda" "λ" "case-lambda"
    "let" "let*" "letrec" "letrec*" "let-values" "let*-values"
    "let-syntax" "letrec-syntax"
    "do")) @local.scope

; A `(define (f args...) ...)` form is also a scope for its parameters.
(list
  .
  (symbol) @_f
  .
  (list)
  (#eq? @_f "define")) @local.scope

; Definitions

; (lambda (a b c) ...) and (define (f a b c) ...) parameters
(list
  .
  (symbol) @_f
  .
  (list
    (symbol) @local.definition.variable.parameter)
  (#any-of? @_f "lambda" "λ"))

(list
  .
  (symbol) @_f
  .
  (list
    .
    (symbol) ; function name, not a parameter
    (symbol) @local.definition.variable.parameter)
  (#eq? @_f "define"))

; (let ((x v) (y w)) ...) and friends: each binding's first symbol
(list
  .
  (symbol) @_f
  .
  (list
    (list
      .
      (symbol) @local.definition.variable))
  (#any-of? @_f
    "let" "let*" "letrec" "letrec*" "let-values" "let*-values"
    "let-syntax" "letrec-syntax" "do"))

; (define name value)
(list
  .
  (symbol) @_f
  .
  (symbol) @local.definition.variable
  (#eq? @_f "define"))

; References

(symbol) @local.reference

; The leading symbol of a form is a keyword/operator/call target, not a
; variable reference; cancel resolution there.
(list
  .
  (symbol) @_)