mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-21 12:50:09 -04:00
added b lang
This commit is contained in:
parent
27b0bd487c
commit
39dc0f6d01
7 changed files with 567 additions and 0 deletions
|
|
@ -75,6 +75,13 @@ return {
|
||||||
},
|
},
|
||||||
tier = 2,
|
tier = 2,
|
||||||
},
|
},
|
||||||
|
b = {
|
||||||
|
install_info = {
|
||||||
|
revision = '353237b4e3325f73c4eb1f745048c6bcac763953',
|
||||||
|
url = 'https://github.com/VoxelPrismatic/tree-sitter-b',
|
||||||
|
},
|
||||||
|
tier = 2,
|
||||||
|
},
|
||||||
bash = {
|
bash = {
|
||||||
install_info = {
|
install_info = {
|
||||||
revision = '0c46d792d54c536be5ff7eb18eb95c70fccdb232',
|
revision = '0c46d792d54c536be5ff7eb18eb95c70fccdb232',
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ local filetypes = {
|
||||||
vhs = { 'tape' },
|
vhs = { 'tape' },
|
||||||
xml = { 'xsd', 'xslt', 'svg' },
|
xml = { 'xsd', 'xslt', 'svg' },
|
||||||
xresources = { 'xdefaults' },
|
xresources = { 'xdefaults' },
|
||||||
|
b = { 'b' },
|
||||||
}
|
}
|
||||||
|
|
||||||
for lang, ft in pairs(filetypes) do
|
for lang, ft in pairs(filetypes) do
|
||||||
|
|
|
||||||
23
runtime/queries/b/folds.scm
Normal file
23
runtime/queries/b/folds.scm
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
[
|
||||||
|
(for_statement)
|
||||||
|
(if_statement)
|
||||||
|
(while_statement)
|
||||||
|
(do_statement)
|
||||||
|
(switch_statement)
|
||||||
|
(case_statement)
|
||||||
|
(function_definition)
|
||||||
|
(struct_specifier)
|
||||||
|
(enum_specifier)
|
||||||
|
(comment)
|
||||||
|
(preproc_if)
|
||||||
|
(preproc_elif)
|
||||||
|
(preproc_else)
|
||||||
|
(preproc_ifdef)
|
||||||
|
(preproc_function_def)
|
||||||
|
(initializer_list)
|
||||||
|
(gnu_asm_expression)
|
||||||
|
(preproc_include)+
|
||||||
|
] @fold
|
||||||
|
|
||||||
|
(compound_statement
|
||||||
|
(compound_statement) @fold)
|
||||||
242
runtime/queries/b/highlights.scm
Normal file
242
runtime/queries/b/highlights.scm
Normal file
|
|
@ -0,0 +1,242 @@
|
||||||
|
; Lower priority to prefer @variable.parameter when identifier appears in parameter_declaration.
|
||||||
|
((identifier) @variable
|
||||||
|
(#set! priority 95))
|
||||||
|
|
||||||
|
[
|
||||||
|
"default"
|
||||||
|
"goto"
|
||||||
|
"asm"
|
||||||
|
"__asm__"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
"auto" @keyword.type
|
||||||
|
|
||||||
|
"extrn" @keyword.type
|
||||||
|
|
||||||
|
(alignof_expression
|
||||||
|
.
|
||||||
|
_ @keyword.operator)
|
||||||
|
|
||||||
|
"return" @keyword.return
|
||||||
|
|
||||||
|
"while" @keyword.repeat
|
||||||
|
|
||||||
|
[
|
||||||
|
"if"
|
||||||
|
"else"
|
||||||
|
"case"
|
||||||
|
"switch"
|
||||||
|
] @keyword.conditional
|
||||||
|
|
||||||
|
"extrn" @keyword.import
|
||||||
|
|
||||||
|
[
|
||||||
|
";"
|
||||||
|
":"
|
||||||
|
","
|
||||||
|
"."
|
||||||
|
"::"
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
[
|
||||||
|
"="
|
||||||
|
"-"
|
||||||
|
"*"
|
||||||
|
"/"
|
||||||
|
"+"
|
||||||
|
"%"
|
||||||
|
"~"
|
||||||
|
"|"
|
||||||
|
"&"
|
||||||
|
"^"
|
||||||
|
"<<"
|
||||||
|
">>"
|
||||||
|
"->"
|
||||||
|
"<"
|
||||||
|
"<="
|
||||||
|
">="
|
||||||
|
">"
|
||||||
|
"=="
|
||||||
|
"!="
|
||||||
|
"!"
|
||||||
|
"&&"
|
||||||
|
"||"
|
||||||
|
"--"
|
||||||
|
"++"
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
[
|
||||||
|
"=-"
|
||||||
|
"=+"
|
||||||
|
"=*"
|
||||||
|
"=/"
|
||||||
|
"=%"
|
||||||
|
"=|"
|
||||||
|
"=&"
|
||||||
|
"=^"
|
||||||
|
"=>>"
|
||||||
|
"=<<"
|
||||||
|
"=>="
|
||||||
|
"=<="
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
; Make sure the comma operator is given a highlight group after the comma
|
||||||
|
; punctuator so the operator is highlighted properly.
|
||||||
|
(comma_expression
|
||||||
|
"," @operator)
|
||||||
|
|
||||||
|
[
|
||||||
|
(true)
|
||||||
|
(false)
|
||||||
|
] @boolean
|
||||||
|
|
||||||
|
(conditional_expression
|
||||||
|
[
|
||||||
|
"?"
|
||||||
|
":"
|
||||||
|
] @keyword.conditional.ternary)
|
||||||
|
|
||||||
|
(string_literal) @string
|
||||||
|
|
||||||
|
(system_lib_string) @string
|
||||||
|
|
||||||
|
(escape_sequence) @string.escape
|
||||||
|
|
||||||
|
(null) @constant.builtin
|
||||||
|
|
||||||
|
(number_literal) @number
|
||||||
|
|
||||||
|
(char_literal) @character
|
||||||
|
|
||||||
|
((field_expression
|
||||||
|
(field_identifier) @property) @_parent
|
||||||
|
(#not-has-parent? @_parent template_method function_declarator call_expression))
|
||||||
|
|
||||||
|
(field_designator) @property
|
||||||
|
|
||||||
|
((field_identifier) @property
|
||||||
|
(#has-ancestor? @property field_declaration)
|
||||||
|
(#not-has-ancestor? @property function_declarator))
|
||||||
|
|
||||||
|
(statement_identifier) @label
|
||||||
|
|
||||||
|
(declaration
|
||||||
|
type: (type_identifier) @_type
|
||||||
|
declarator: (identifier) @label
|
||||||
|
(#eq? @_type "__label__"))
|
||||||
|
|
||||||
|
[
|
||||||
|
(type_identifier)
|
||||||
|
(type_descriptor)
|
||||||
|
] @type
|
||||||
|
|
||||||
|
(storage_class_specifier) @keyword.modifier
|
||||||
|
|
||||||
|
[
|
||||||
|
(type_qualifier)
|
||||||
|
(gnu_asm_qualifier)
|
||||||
|
"__extension__"
|
||||||
|
] @keyword.modifier
|
||||||
|
|
||||||
|
(type_definition
|
||||||
|
declarator: (type_identifier) @type.definition)
|
||||||
|
|
||||||
|
(primitive_type) @type.builtin
|
||||||
|
|
||||||
|
(sized_type_specifier
|
||||||
|
_ @type.builtin
|
||||||
|
type: _?)
|
||||||
|
|
||||||
|
((identifier) @constant
|
||||||
|
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
|
||||||
|
|
||||||
|
(enumerator
|
||||||
|
name: (identifier) @constant)
|
||||||
|
|
||||||
|
(case_statement
|
||||||
|
value: (identifier) @constant)
|
||||||
|
|
||||||
|
((identifier) @constant.builtin
|
||||||
|
; format-ignore
|
||||||
|
(#any-of? @constant.builtin
|
||||||
|
"args"
|
||||||
|
))
|
||||||
|
|
||||||
|
(attribute_specifier
|
||||||
|
(argument_list
|
||||||
|
(identifier) @variable.builtin))
|
||||||
|
|
||||||
|
(attribute_specifier
|
||||||
|
(argument_list
|
||||||
|
(call_expression
|
||||||
|
function: (identifier) @variable.builtin)))
|
||||||
|
|
||||||
|
((call_expression
|
||||||
|
function: (identifier) @function.builtin)
|
||||||
|
(#lua-match? @function.builtin "^__builtin_"))
|
||||||
|
|
||||||
|
((call_expression
|
||||||
|
function: (identifier) @function.builtin)
|
||||||
|
(#has-ancestor? @function.builtin attribute_specifier))
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (identifier) @function.call)
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (field_expression
|
||||||
|
field: (field_identifier) @function.call))
|
||||||
|
|
||||||
|
(function_declarator
|
||||||
|
declarator: (identifier) @function)
|
||||||
|
|
||||||
|
(function_declarator
|
||||||
|
declarator: (parenthesized_declarator
|
||||||
|
(pointer_declarator
|
||||||
|
declarator: (field_identifier) @function)))
|
||||||
|
|
||||||
|
(comment) @comment @spell
|
||||||
|
|
||||||
|
((comment) @comment.documentation
|
||||||
|
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
|
||||||
|
|
||||||
|
; Parameters
|
||||||
|
(parameter_declaration
|
||||||
|
declarator: (identifier) @variable.parameter)
|
||||||
|
|
||||||
|
(parameter_declaration
|
||||||
|
declarator: (array_declarator) @variable.parameter)
|
||||||
|
|
||||||
|
(parameter_declaration
|
||||||
|
declarator: (pointer_declarator) @variable.parameter)
|
||||||
|
|
||||||
|
; K&R functions
|
||||||
|
; To enable support for K&R functions,
|
||||||
|
; add the following lines to your own query config and uncomment them.
|
||||||
|
; They are commented out as they'll conflict with C++
|
||||||
|
; Note that you'll need to have `; extends` at the top of your query file.
|
||||||
|
;
|
||||||
|
; (parameter_list (identifier) @variable.parameter)
|
||||||
|
;
|
||||||
|
; (function_definition
|
||||||
|
; declarator: _
|
||||||
|
; (declaration
|
||||||
|
; declarator: (identifier) @variable.parameter))
|
||||||
|
;
|
||||||
|
; (function_definition
|
||||||
|
; declarator: _
|
||||||
|
; (declaration
|
||||||
|
; declarator: (array_declarator) @variable.parameter))
|
||||||
|
;
|
||||||
|
; (function_definition
|
||||||
|
; declarator: _
|
||||||
|
; (declaration
|
||||||
|
; declarator: (pointer_declarator) @variable.parameter))
|
||||||
99
runtime/queries/b/indents.scm
Normal file
99
runtime/queries/b/indents.scm
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
[
|
||||||
|
(compound_statement)
|
||||||
|
(field_declaration_list)
|
||||||
|
(case_statement)
|
||||||
|
(enumerator_list)
|
||||||
|
(compound_literal_expression)
|
||||||
|
(initializer_list)
|
||||||
|
(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
|
||||||
|
; So narrow indent capture to check for error inside expression statement only,
|
||||||
|
(expression_statement
|
||||||
|
(_) @indent.begin
|
||||||
|
";" @indent.end)
|
||||||
|
|
||||||
|
(ERROR
|
||||||
|
"for"
|
||||||
|
"(" @indent.begin
|
||||||
|
";"
|
||||||
|
";"
|
||||||
|
")" @indent.end)
|
||||||
|
|
||||||
|
((for_statement
|
||||||
|
body: (_) @_body) @indent.begin
|
||||||
|
(#not-kind-eq? @_body "compound_statement"))
|
||||||
|
|
||||||
|
(while_statement
|
||||||
|
condition: (_) @indent.begin)
|
||||||
|
|
||||||
|
((while_statement
|
||||||
|
body: (_) @_body) @indent.begin
|
||||||
|
(#not-kind-eq? @_body "compound_statement"))
|
||||||
|
|
||||||
|
((if_statement)
|
||||||
|
.
|
||||||
|
(ERROR
|
||||||
|
"else" @indent.begin))
|
||||||
|
|
||||||
|
(if_statement
|
||||||
|
condition: (_) @indent.begin)
|
||||||
|
|
||||||
|
; Supports if without braces (but not both if-else without braces)
|
||||||
|
(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
|
||||||
|
|
||||||
|
(else_clause
|
||||||
|
(_
|
||||||
|
.
|
||||||
|
"{" @indent.branch))
|
||||||
|
|
||||||
|
(compound_statement
|
||||||
|
"}" @indent.end)
|
||||||
|
|
||||||
|
[
|
||||||
|
")"
|
||||||
|
"}"
|
||||||
|
(statement_identifier)
|
||||||
|
] @indent.branch
|
||||||
|
|
||||||
|
[
|
||||||
|
"#define"
|
||||||
|
"#ifdef"
|
||||||
|
"#ifndef"
|
||||||
|
"#elif"
|
||||||
|
"#if"
|
||||||
|
"#else"
|
||||||
|
"#endif"
|
||||||
|
] @indent.zero
|
||||||
|
|
||||||
|
[
|
||||||
|
(preproc_arg)
|
||||||
|
(string_literal)
|
||||||
|
] @indent.ignore
|
||||||
|
|
||||||
|
((ERROR
|
||||||
|
(parameter_declaration)) @indent.align
|
||||||
|
(#set! indent.open_delimiter "(")
|
||||||
|
(#set! indent.close_delimiter ")"))
|
||||||
|
|
||||||
|
([
|
||||||
|
(argument_list)
|
||||||
|
(parameter_list)
|
||||||
|
] @indent.align
|
||||||
|
(#set! indent.open_delimiter "(")
|
||||||
|
(#set! indent.close_delimiter ")"))
|
||||||
|
|
||||||
|
(comment) @indent.auto
|
||||||
128
runtime/queries/b/injections.scm
Normal file
128
runtime/queries/b/injections.scm
Normal file
|
|
@ -0,0 +1,128 @@
|
||||||
|
((preproc_arg) @injection.content
|
||||||
|
(#set! injection.self))
|
||||||
|
|
||||||
|
((comment) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
||||||
|
|
||||||
|
((comment) @injection.content
|
||||||
|
(#match? @injection.content "/\\*!([a-zA-Z]+:)?re2c")
|
||||||
|
(#set! injection.language "re2c"))
|
||||||
|
|
||||||
|
((comment) @injection.content
|
||||||
|
(#lua-match? @injection.content "/[*/][!*/]<?[^a-zA-Z]")
|
||||||
|
(#set! injection.language "doxygen"))
|
||||||
|
|
||||||
|
((call_expression
|
||||||
|
function: (identifier) @_function
|
||||||
|
arguments: (argument_list
|
||||||
|
.
|
||||||
|
[
|
||||||
|
(string_literal
|
||||||
|
(string_content) @injection.content)
|
||||||
|
(concatenated_string
|
||||||
|
(string_literal
|
||||||
|
(string_content) @injection.content))
|
||||||
|
]))
|
||||||
|
; format-ignore
|
||||||
|
(#any-of? @_function
|
||||||
|
"printf" "printf_s"
|
||||||
|
"vprintf" "vprintf_s"
|
||||||
|
"scanf" "scanf_s"
|
||||||
|
"vscanf" "vscanf_s"
|
||||||
|
"wprintf" "wprintf_s"
|
||||||
|
"vwprintf" "vwprintf_s"
|
||||||
|
"wscanf" "wscanf_s"
|
||||||
|
"vwscanf" "vwscanf_s"
|
||||||
|
"cscanf" "_cscanf"
|
||||||
|
"printw"
|
||||||
|
"scanw")
|
||||||
|
(#set! injection.language "printf"))
|
||||||
|
|
||||||
|
((call_expression
|
||||||
|
function: (identifier) @_function
|
||||||
|
arguments: (argument_list
|
||||||
|
(_)
|
||||||
|
.
|
||||||
|
[
|
||||||
|
(string_literal
|
||||||
|
(string_content) @injection.content)
|
||||||
|
(concatenated_string
|
||||||
|
(string_literal
|
||||||
|
(string_content) @injection.content))
|
||||||
|
]))
|
||||||
|
; format-ignore
|
||||||
|
(#any-of? @_function
|
||||||
|
"fprintf" "fprintf_s"
|
||||||
|
"sprintf"
|
||||||
|
"dprintf"
|
||||||
|
"fscanf" "fscanf_s"
|
||||||
|
"sscanf" "sscanf_s"
|
||||||
|
"vsscanf" "vsscanf_s"
|
||||||
|
"vfprintf" "vfprintf_s"
|
||||||
|
"vsprintf"
|
||||||
|
"vdprintf"
|
||||||
|
"fwprintf" "fwprintf_s"
|
||||||
|
"vfwprintf" "vfwprintf_s"
|
||||||
|
"fwscanf" "fwscanf_s"
|
||||||
|
"swscanf" "swscanf_s"
|
||||||
|
"vswscanf" "vswscanf_s"
|
||||||
|
"vfscanf" "vfscanf_s"
|
||||||
|
"vfwscanf" "vfwscanf_s"
|
||||||
|
"wprintw"
|
||||||
|
"vw_printw" "vwprintw"
|
||||||
|
"wscanw"
|
||||||
|
"vw_scanw" "vwscanw")
|
||||||
|
(#set! injection.language "printf"))
|
||||||
|
|
||||||
|
((call_expression
|
||||||
|
function: (identifier) @_function
|
||||||
|
arguments: (argument_list
|
||||||
|
(_)
|
||||||
|
.
|
||||||
|
(_)
|
||||||
|
.
|
||||||
|
[
|
||||||
|
(string_literal
|
||||||
|
(string_content) @injection.content)
|
||||||
|
(concatenated_string
|
||||||
|
(string_literal
|
||||||
|
(string_content) @injection.content))
|
||||||
|
]))
|
||||||
|
; format-ignore
|
||||||
|
(#any-of? @_function
|
||||||
|
"sprintf_s"
|
||||||
|
"snprintf" "snprintf_s"
|
||||||
|
"vsprintf_s"
|
||||||
|
"vsnprintf" "vsnprintf_s"
|
||||||
|
"swprintf" "swprintf_s"
|
||||||
|
"snwprintf_s"
|
||||||
|
"vswprintf" "vswprintf_s"
|
||||||
|
"vsnwprintf_s"
|
||||||
|
"mvprintw"
|
||||||
|
"mvscanw")
|
||||||
|
(#set! injection.language "printf"))
|
||||||
|
|
||||||
|
((call_expression
|
||||||
|
function: (identifier) @_function
|
||||||
|
arguments: (argument_list
|
||||||
|
(_)
|
||||||
|
.
|
||||||
|
(_)
|
||||||
|
.
|
||||||
|
(_)
|
||||||
|
.
|
||||||
|
[
|
||||||
|
(string_literal
|
||||||
|
(string_content) @injection.content)
|
||||||
|
(concatenated_string
|
||||||
|
(string_literal
|
||||||
|
(string_content) @injection.content))
|
||||||
|
]))
|
||||||
|
(#any-of? @_function "mvwprintw" "mvwscanw")
|
||||||
|
(#set! injection.language "printf"))
|
||||||
|
|
||||||
|
; TODO: add when asm is added
|
||||||
|
; (gnu_asm_expression assembly_code: (string_literal) @injection.content
|
||||||
|
; (#set! injection.language "asm"))
|
||||||
|
; (gnu_asm_expression assembly_code: (concatenated_string (string_literal) @injection.content)
|
||||||
|
; (#set! injection.language "asm"))
|
||||||
67
runtime/queries/b/locals.scm
Normal file
67
runtime/queries/b/locals.scm
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
; Functions definitions
|
||||||
|
(function_declarator
|
||||||
|
declarator: (identifier) @local.definition.function)
|
||||||
|
|
||||||
|
(preproc_function_def
|
||||||
|
name: (identifier) @local.definition.macro) @local.scope
|
||||||
|
|
||||||
|
(preproc_def
|
||||||
|
name: (identifier) @local.definition.macro)
|
||||||
|
|
||||||
|
(pointer_declarator
|
||||||
|
declarator: (identifier) @local.definition.var)
|
||||||
|
|
||||||
|
(parameter_declaration
|
||||||
|
declarator: (identifier) @local.definition.parameter)
|
||||||
|
|
||||||
|
(init_declarator
|
||||||
|
declarator: (identifier) @local.definition.var)
|
||||||
|
|
||||||
|
(array_declarator
|
||||||
|
declarator: (identifier) @local.definition.var)
|
||||||
|
|
||||||
|
(declaration
|
||||||
|
declarator: (identifier) @local.definition.var)
|
||||||
|
|
||||||
|
(enum_specifier
|
||||||
|
name: (_) @local.definition.type
|
||||||
|
(enumerator_list
|
||||||
|
(enumerator
|
||||||
|
name: (identifier) @local.definition.var)))
|
||||||
|
|
||||||
|
; Type / Struct / Enum
|
||||||
|
(field_declaration
|
||||||
|
declarator: (field_identifier) @local.definition.field)
|
||||||
|
|
||||||
|
(type_definition
|
||||||
|
declarator: (type_identifier) @local.definition.type)
|
||||||
|
|
||||||
|
(struct_specifier
|
||||||
|
name: (type_identifier) @local.definition.type)
|
||||||
|
|
||||||
|
; goto
|
||||||
|
(labeled_statement
|
||||||
|
(statement_identifier) @local.definition)
|
||||||
|
|
||||||
|
; References
|
||||||
|
(identifier) @local.reference
|
||||||
|
|
||||||
|
((field_identifier) @local.reference
|
||||||
|
(#set! reference.kind "field"))
|
||||||
|
|
||||||
|
((type_identifier) @local.reference
|
||||||
|
(#set! reference.kind "type"))
|
||||||
|
|
||||||
|
(goto_statement
|
||||||
|
(statement_identifier) @local.reference)
|
||||||
|
|
||||||
|
; Scope
|
||||||
|
[
|
||||||
|
(for_statement)
|
||||||
|
(if_statement)
|
||||||
|
(while_statement)
|
||||||
|
(translation_unit)
|
||||||
|
(function_definition)
|
||||||
|
(compound_statement) ; a block in curly braces
|
||||||
|
(struct_specifier)
|
||||||
|
] @local.scope
|
||||||
Loading…
Add table
Add a link
Reference in a new issue