From 30259100b11d26b39bc0fcdb8f0174afa396996f Mon Sep 17 00:00:00 2001 From: VoxelPrismatic Date: Tue, 3 Jun 2025 16:58:04 -0500 Subject: [PATCH] v2 --- SUPPORTED_LANGUAGES.md | 2 +- lua/nvim-treesitter/parsers.lua | 4 +- runtime/queries/b/folds.scm | 23 --- runtime/queries/b/highlights.scm | 340 +++++++++++++------------------ runtime/queries/b/indents.scm | 99 --------- runtime/queries/b/injections.scm | 128 ------------ runtime/queries/b/locals.scm | 67 ------ 7 files changed, 150 insertions(+), 513 deletions(-) delete mode 100644 runtime/queries/b/folds.scm delete mode 100644 runtime/queries/b/indents.scm delete mode 100644 runtime/queries/b/injections.scm delete mode 100644 runtime/queries/b/locals.scm diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md index 01e9882fa..014c080f0 100644 --- a/SUPPORTED_LANGUAGES.md +++ b/SUPPORTED_LANGUAGES.md @@ -21,7 +21,7 @@ Language | Tier | Queries | Node | Maintainer [astro](https://github.com/virchau13/tree-sitter-astro) | unstable | `HFIJL` | | @virchau13 [authzed](https://github.com/mleonidas/tree-sitter-authzed) | unstable | `H  J ` | | @mattpolzin [awk](https://github.com/Beaglefoot/tree-sitter-awk) | unstable | `H  J ` | | -[b](https://github.com/VoxelPrismatic/tree-sitter-b) | unstable | `HFIJL` | | +[b](https://github.com/VoxelPrismatic/tree-sitter-b) | unstable | `H    ` | | @voxelprismatic [bash](https://github.com/tree-sitter/tree-sitter-bash) | unstable | `HF JL` | | @TravonteD [bass](https://github.com/vito/tree-sitter-bass) | unstable | `HFIJL` | | @amaanq [beancount](https://github.com/polarmutex/tree-sitter-beancount) | unstable | `HF J ` | | @polarmutex diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 804941ab0..f31eeed72 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -77,9 +77,11 @@ return { }, b = { install_info = { - revision = '3ca711959415190d02e056ba0d754716984e0c91', + revision = '23f515392632d6f010926a3257fa095c041eea6e', url = 'https://github.com/VoxelPrismatic/tree-sitter-b', + branch = 'v2', }, + maintainers = { '@VoxelPrismatic' }, tier = 2, }, bash = { diff --git a/runtime/queries/b/folds.scm b/runtime/queries/b/folds.scm deleted file mode 100644 index bb26a62eb..000000000 --- a/runtime/queries/b/folds.scm +++ /dev/null @@ -1,23 +0,0 @@ -[ - (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) diff --git a/runtime/queries/b/highlights.scm b/runtime/queries/b/highlights.scm index e109f9d89..6cd18b538 100644 --- a/runtime/queries/b/highlights.scm +++ b/runtime/queries/b/highlights.scm @@ -1,26 +1,40 @@ -; Lower priority to prefer @variable.parameter when identifier appears in parameter_declaration. +(_ + lhs: (linker) @comment + target: (linker) @markup.strong @diff.plus + rhs: (linker) @comment) + +(linker + target: (link_name) @markup.strong @diff.minus) @comment + ((identifier) @variable (#set! priority 95)) +((identifier) @constant + (#set! priority 103) + (#match? @constant "^[A-Z0-9_\\-]+$")) + +((identifier) @constant + (#set! priority 103) + (#match? @constant "args")) + +(comment) @comment + [ - "default" - "goto" - "asm" - "__asm__" -] @keyword - -(type_identifier) @keyword.type - -"auto" @keyword.type - -(alignof_expression - . - _ @keyword.operator) + "auto" + "extrn" +] @keyword.type "return" @keyword.return "while" @keyword.repeat +(goto_statement + token: "goto" @keyword + name: (rvalue) @label) + +(label_statement + name: (_) @label) + [ "if" "else" @@ -29,207 +43,145 @@ ] @keyword.conditional [ - ";" - ":" - "," - "." - "::" -] @punctuation.delimiter + (op_binary) + (op_unary) + (op_assign) + (op_incdec) +] @keyword.operator -[ - "(" - ")" - "[" - "]" - "{" - "}" -] @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) +(rune_literal) @character (string_literal) @string -(system_lib_string) @string - -(escape_sequence) @string.escape - -(null) @constant.builtin - (number_literal) @number -(char_literal) @character +(define_function + name: (identifier) @function.method) -((field_expression - (field_identifier) @property) @_parent - (#not-has-parent? @_parent template_method function_declarator call_expression)) +(call + name: (identifier) @function.method @function.method.call) -(field_designator) @property +; Standard libraries +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin + "char" "chdir" "chmod" "chown" "close" "creat" "ctime" "execl" "execv" "exit" "fork" "fstat" + "getchar" "getuid" "gtty" "lchar" "link" "mkdir" "open" "printf" "printn" "putchar" "read" + "setuid" "stat" "stty" "unlink" "wait" "write" "main")) -((field_identifier) @property - (#has-ancestor? @property field_declaration) - (#not-has-ancestor? @property function_declarator)) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin "assert") + (#has-ancestor? @function.builtin program_c_assert_h)) -(statement_identifier) @label +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin + "isalnum" "isalpha" "isascii4" "isblank" "iscntrl" "isdigit" "isgraph" "islower" "isprint" + "ispunct" "isspace" "isupper" "toascii" "tolower" "toupper") + (#has-ancestor? @function.builtin program_c_ctype_h)) -(declaration - type: (type_identifier) @_type - declarator: (identifier) @label - (#eq? @_type "__label__")) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin "nl_langinfo4") + (#has-ancestor? @function.builtin program_c_langinfo_h)) -(storage_class_specifier) @keyword.modifier +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin + "acos" "asin" "atan" "atan2" "ceil" "cos" "cosh" "erf" "erfc" "exp" "fabs" "floor" "fmod" + "frexp" "gamma" "hypot" "j0" "j1" "jn" "ldexp" "log" "log10" "modf" "nextafter" "nextafterl" + "nexttoward" "nexttowardl" "pow" "quantexpd32" "quantexpd64" "quantexpd128" "quantized32" + "quantized64" "quantized128" "samequantumd32" "samequantumd64" "samequantumd128" "sin" "sinh" + "sqrt" "tan" "tanh" "y0" "y1" "yn") + (#has-ancestor? @function.builtin program_c_math_h)) -[ - (type_qualifier) - (gnu_asm_qualifier) - "__extension__" -] @keyword.modifier +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin "catclose6" "catgets6" "catopen6") + (#has-ancestor? @function.builtin program_c_nl_types_h)) -(type_definition - declarator: (type_identifier) @type.definition) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin "regcomp" "regerror" "regexec" "regfree") + (#has-ancestor? @function.builtin program_c_regex_h)) -(primitive_type) @type.builtin +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin "longjmp" "setjmp") + (#has-ancestor? @function.builtin program_c_setjmp_h)) -(sized_type_specifier - _ @type.builtin - type: _?) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin "raise" "signal") + (#has-ancestor? @function.builtin program_c_signal_h)) -((identifier) @constant - (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin + "va_arg" "va_copy" "va_end" "va_start" "vfprintf" "vfscanf" "vfwprintf6" "vfwscanf" "vprintf" + "vscanf" "vsprintf" "vsscanf" "vswprintf" "vwprintf6" "wctob") + (#has-ancestor? @function.builtin program_c_stdarg_h)) -(enumerator - name: (identifier) @constant) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin + "btowc" "clearerr" "fclose" "fdopen5" "feof" "ferror" "fflush1" "fgetc1" "fgetpos1" "fgets1" + "fgetwc6" "fgetws6" "fileno5" "fopen" "fprintf" "fputc1" "fputs1" "fputwc6" "fputws6" "fread" + "freopen" "fscanf" "fseek1" "fsetpos1" "ftell1" "fwide6" "fwprintf6" "fwrite" "fwscanf6" "getc1" + "getchar1" "gets" "getwc6" "perror" "printf" "putc1" "putchar1" "puts" "putwc6" "remove" + "rename" "rewind1" "scanf" "setbuf" "setvbuf" "snprintf" "sprintf" "sscanf" "tmpfile" "tmpnam" + "ungetc1" "ungetwc6" "vfprintf" "vfscanf" "vfwprintf6" "vfwscanf" "vprintf" "vscanf" "vsprintf" + "vsnprintf" "vsscanf" "vswscanf" "vwscanf") + (#has-ancestor? @function.builtin program_c_stdio_h)) -(case_statement - value: (identifier) @constant) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin + "abort" "abs" "atexit" "atof" "atoi" "atol" "bsearch" "calloc" "div" "exit" "free" "getenv" + "labs" "ldiv" "malloc" "mblen" "mbstowcs" "mbtowc" "putenv" "qsort" "rand" "rand_r" "realloc" + "srand" "strtod" "strtod32" "strtod64" "strtod128" "strtof" "strtol" "strtold" "strtoul" + "system" "wcstombs" "wctomb") + (#has-ancestor? @function.builtin program_c_stdlib_h)) -((identifier) @constant.builtin - ; format-ignore - (#any-of? @constant.builtin - "args" - )) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin + "memchr" "memcmp" "memcpy" "memmove" "memset" "strcat" "strchr" "strcmp" "strcoll" "strcpy" + "strcspn" "strerror" "strlen" "strncat" "strncmp" "strncpy" "strpbrk" "strrchr" "strspn" + "strstr" "strtok" "strtok_r" "strxfrm") + (#has-ancestor? @function.builtin program_c_string_h)) -(attribute_specifier - (argument_list - (identifier) @variable.builtin)) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin "strcasecmp" "strncasecmp") + (#has-ancestor? @function.builtin program_c_strings_h)) -(attribute_specifier - (argument_list - (call_expression - function: (identifier) @variable.builtin))) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin + "asctime" "asctime_r" "clock" "ctime" "ctime64" "ctime_r" "ctime64_r" "difftime" "difftime64" + "gmtime" "gmtime64" "gmtime_r" "gmtime64_r" "localtime" "localtime64" "localtime_r" + "localtime64_r" "mktime" "mktime64" "strftime" "strptime4" "time" "time64") + (#has-ancestor? @function.builtin program_c_time_h)) -((call_expression - function: (identifier) @function.builtin) - (#lua-match? @function.builtin "^__builtin_")) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin + "btowc" "fgetwc6" "fgetws6" "fputwc6" "fputws6" "fwide6" "fwprintf6" "fwscanf6" "getwc6" + "getwchar6" "mbrlen4" "mbrtowc4" "mbsinit4" "mbsrtowcs4" "putwc6" "putwchar6" "strfmon4" + "swprintf" "swscanf" "ungetwc6" "vfwprintf6" "vswprintf" "vswscanf" "vwprintf6" "vwscanf" + "wcrtomb4" "wcscat" "wcschr" "wcscmp" "wcscoll4" "wcscpy" "wcscspn" "wcsftime" "wcslen" + "wcsncat" "wcsncmp" "wcsncpy" "wcspbrk" "wcsptime" "wcsrchr" "wcsrtombs4" "wcsspn" "wcsstr" + "wcstod" "wcstod32" "wcstod64" "wcstod128" "wcstof" "wcstok" "wcstol" "wcstold" "wcstoul" + "wcsxfrm4" "wctob" "wctype4" "wcwidth" "wmemchr" "wmemcmp" "wmemcpy" "wmemmove" "wmemset" + "wprintf6" "wscanf6") + (#has-ancestor? @function.builtin program_c_wchar_h)) -((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)) +((identifier) @function.builtin + (#set! priority 105) + (#any-of? @function.builtin + "iswalnum4" "iswalpha4" "iswblank4" "iswcntrl4" "iswctype4" "iswdigit4" "iswgraph4" "iswlower4" + "iswprint4" "iswpunct4" "iswspace4" "iswupper4" "iswxdigit4" "isxdigit4" "towctrans" "towlower4" + "towupper4" "wctrans") + (#has-ancestor? @function.builtin program_c_wctype_h)) diff --git a/runtime/queries/b/indents.scm b/runtime/queries/b/indents.scm deleted file mode 100644 index 1932ce8d6..000000000 --- a/runtime/queries/b/indents.scm +++ /dev/null @@ -1,99 +0,0 @@ -[ - (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 diff --git a/runtime/queries/b/injections.scm b/runtime/queries/b/injections.scm deleted file mode 100644 index ebedc1ec3..000000000 --- a/runtime/queries/b/injections.scm +++ /dev/null @@ -1,128 +0,0 @@ -((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 "/[*/][!*/]