aboutsummaryrefslogtreecommitdiffstats
path: root/runtime/queries/ocaml/indents.scm
blob: d7f05367d222c6d0984a39d8e063aa130eb7bd1d (plain) (blame)
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
74
75
76
77
; format-ignore
[ 
  (let_binding)                 ; let = ...
  (type_binding)

  (external)
  (record_declaration)          ; { foo: bar ... }
  (structure)                   ; struct ... end
  (signature)                   ; sig ... end
  (value_specification)         ; val x: bar

  (do_clause)                   ; do ... done
  (match_case)

  (field_expression)
  (application_expression)
  (parenthesized_expression)    ; ( ... )
  (record_expression)           ; { foo = bar ... }
  (list_expression)             ; [...;...]
  (try_expression)              ; try ... with
] @indent.begin

; handle if-else if-else case
(if_expression
  condition: (_) @indent.begin)

(then_clause) @indent.begin

((else_clause
  (_) @_not_if) @indent.begin
  (#not-kind-eq? @_not_if "if_expression"))

((parameter) @indent.begin
  (#set! indent.start_at_same_line))

(_
  (ERROR) @indent.begin
  (#set! indent.start_at_same_line))

(ERROR
  "|" @indent.begin
  (#set! indent.start_at_same_line))

(try_expression
  "with" @indent.branch
  [
    (match_case) @indent.dedent
    (match_case
      [
        (parenthesized_expression)
        (list_expression)
      ] @indent.dedent)
  ])

"}" @indent.branch @indent.end

(list_expression
  "]" @indent.branch)

(parenthesized_expression
  ")" @indent.branch)

";;" @indent.end

(do_clause
  "done" @indent.end @indent.branch)

(structure
  "end" @indent.end @indent.branch)

(signature
  "end" @indent.end @indent.branch)

[
  (string)
  (comment)
] @indent.auto