nvim-treesitter/runtime/queries/c/indents.scm

100 lines
1.9 KiB
Scheme
Raw Permalink Normal View History

2021-01-05 19:26:08 +07:00
[
2024-01-06 15:05:50 +09:00
(compound_statement)
2021-01-05 19:26:08 +07:00
(field_declaration_list)
(case_statement)
(enumerator_list)
2021-07-31 12:59:19 -04:00
(compound_literal_expression)
2022-01-18 21:17:26 +06:00
(initializer_list)
2023-01-10 14:04:27 +09:00
(init_declarator)
] @indent.begin
; With current indent logic, if we capture expression_statement with @indent.begin
; It will be affected by _parent_ node with error subnodes deep down the tree
2024-01-06 15:05:50 +09:00
; So narrow indent capture to check for error inside expression statement only,
(expression_statement
(_) @indent.begin
";" @indent.end)
(ERROR
2024-01-06 15:05:50 +09:00
"for"
"(" @indent.begin
";"
";"
")" @indent.end)
2023-01-10 14:04:27 +09:00
((for_statement
2024-01-06 15:05:50 +09:00
body: (_) @_body) @indent.begin
(#not-kind-eq? @_body "compound_statement"))
(while_statement
condition: (_) @indent.begin)
((while_statement
2024-01-06 15:05:50 +09:00
body: (_) @_body) @indent.begin
(#not-kind-eq? @_body "compound_statement"))
2023-01-10 14:04:27 +09:00
2024-01-06 15:05:50 +09:00
((if_statement)
.
2024-01-06 15:05:50 +09:00
(ERROR
"else" @indent.begin))
(if_statement
condition: (_) @indent.begin)
2024-01-06 15:05:50 +09:00
; Supports if without braces (but not both if-else without braces)
2024-01-21 22:05:44 +09:00
(if_statement
consequence: (_
";" @indent.end) @_consequence
(#not-kind-eq? @_consequence "compound_statement")
alternative: (else_clause
"else" @indent.branch
[
(if_statement
(compound_statement) @indent.dedent)? @indent.dedent
(compound_statement)? @indent.dedent
(_)? @indent.dedent
])?) @indent.begin
2023-01-10 14:04:27 +09:00
2024-01-06 15:05:50 +09:00
(else_clause
(_
.
"{" @indent.branch))
2023-01-10 14:04:27 +09:00
2024-01-06 15:05:50 +09:00
(compound_statement
"}" @indent.end)
2022-01-22 18:24:38 +01:00
[
")"
"}"
(statement_identifier)
] @indent.branch
2022-01-22 18:24:38 +01:00
2021-01-05 19:26:08 +07:00
[
"#define"
"#ifdef"
"#ifndef"
"#elif"
2022-01-18 21:17:26 +06:00
"#if"
"#else"
2021-01-05 19:26:08 +07:00
"#endif"
] @indent.zero
[
2022-01-18 21:17:26 +06:00
(preproc_arg)
(string_literal)
] @indent.ignore
2022-01-18 21:17:26 +06:00
2024-01-06 15:05:50 +09:00
((ERROR
(parameter_declaration)) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
2024-01-06 15:05:50 +09:00
([
(argument_list)
(parameter_list)
] @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
2024-01-06 15:05:50 +09:00
(comment) @indent.auto