diff options
| author | Minijackson <minijackson@riseup.net> | 2025-09-11 15:27:19 +0200 |
|---|---|---|
| committer | Christian Clason <ch.clason+github@icloud.com> | 2025-09-22 15:41:39 +0200 |
| commit | 53819acac287632ee2b62e0f7b63057904984906 (patch) | |
| tree | ee48d51e73c675c5cd6f73cbaaa1a157427023d8 /runtime/queries | |
| parent | fix: align line continuation highlights (#8146) (diff) | |
| download | nvim-treesitter-53819acac287632ee2b62e0f7b63057904984906.tar nvim-treesitter-53819acac287632ee2b62e0f7b63057904984906.tar.gz nvim-treesitter-53819acac287632ee2b62e0f7b63057904984906.tar.bz2 nvim-treesitter-53819acac287632ee2b62e0f7b63057904984906.tar.lz nvim-treesitter-53819acac287632ee2b62e0f7b63057904984906.tar.xz nvim-treesitter-53819acac287632ee2b62e0f7b63057904984906.tar.zst nvim-treesitter-53819acac287632ee2b62e0f7b63057904984906.zip | |
feat(snl): add parser and queries
Diffstat (limited to 'runtime/queries')
| -rw-r--r-- | runtime/queries/snl/folds.scm | 21 | ||||
| -rw-r--r-- | runtime/queries/snl/highlights.scm | 245 | ||||
| -rw-r--r-- | runtime/queries/snl/indents.scm | 61 | ||||
| -rw-r--r-- | runtime/queries/snl/injections.scm | 117 | ||||
| -rw-r--r-- | runtime/queries/snl/locals.scm | 65 |
5 files changed, 509 insertions, 0 deletions
diff --git a/runtime/queries/snl/folds.scm b/runtime/queries/snl/folds.scm new file mode 100644 index 000000000..65e50c62f --- /dev/null +++ b/runtime/queries/snl/folds.scm @@ -0,0 +1,21 @@ +[ + (for_statement) + (if_statement) + (while_statement) + (funcdef) + (structdef) + (comment) + (preproc_if) + (preproc_elif) + (preproc_else) + (preproc_ifdef) + (preproc_function_def) + (init_expr) + (entry) + (state_set) + (state) + (exit) +] @fold + +(initial_defn + (preproc_include))+ @fold diff --git a/runtime/queries/snl/highlights.scm b/runtime/queries/snl/highlights.scm new file mode 100644 index 000000000..423a7deb7 --- /dev/null +++ b/runtime/queries/snl/highlights.scm @@ -0,0 +1,245 @@ +(identifier) @variable + +[ + "enum" + "struct" + "union" +] @keyword.type + +[ + "assign" + "const" + "entry" + "exit" + "foreign" + "monitor" + "option" + "program" + "ss" + "state" + "sync" + "syncq" + "to" + "typename" +] @keyword + +"sizeof" @keyword.operator + +"return" @keyword.return + +[ + "while" + "for" + "continue" + "break" +] @keyword.repeat + +[ + "if" + "else" + "when" +] @keyword.conditional + +[ + "#elif" + "#else" + "#endif" + "#if" + "#ifdef" + "#ifndef" + (preproc_directive) + (line_marker) +] @keyword.directive + +"#define" @keyword.directive.define + +"#include" @keyword.import + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "." + "," + ";" +] @punctuation.delimiter + +[ + "%%" + "%{" + "}%" + "..." +] @punctuation.special + +[ + "+" + "-" + "*" + "&" + "!" + "~" + "++" + "--" + "=" + ">>" + "<<" + "/" + ">" + ">=" + "<" + "<=" + "==" + "!=" + "^" + "|" + "||" + "&&" + "%" + "*=" + "/=" + "%=" + "+=" + "-=" + "<<=" + ">>=" + "&=" + "^=" + "|=" +] @operator + +(comma_expr + "," @operator) + +[ + (true) + (false) +] @boolean + +(conditional_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +[ + (string_literal) + (system_lib_string) +] @string + +(parameter_expansion + [ + "{" + "}" + ] @string.special) + +(parameter_expansion + (identifier) @constant) + +(escape_sequence) @string.escape + +(null) @constant.builtin + +[ + (number_literal) + (char_literal) +] @number + +((preproc_arg) @function.macro + (#set! "priority" 90)) + +(preproc_defined) @function.macro + +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (field_expression + field: (identifier) @function.call)) + +(function_declarator + declarator: (identifier) @function) + +(preproc_function_def + name: (identifier) @function.macro) + +(field_expression + field: (identifier) @property) + +(type_qualifier) @keyword.modifier + +(structdef + name: (identifier) @type.definition) + +[ + (basetype) + (type_expr) +] @type + +(prim_type) @type.builtin + +(program + name: (identifier) @constant) + +(state_set + name: (identifier) @function) + +(state + name: (identifier) @function) + +(transition + name: (identifier) @function) + +(option + name: (identifier) @constant) + +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z%d_]*$")) + +(preproc_def + name: (_) @constant.macro) + +(preproc_call + directive: (preproc_directive) @_u + argument: (_) @constant.macro + (#eq? @_u "#undef")) + +(comment) @comment @spell + +(param_decl + (declarator + (identifier) @variable.parameter)) + +((identifier) @variable.parameter + (#has-ancestor? @variable.parameter param_decl)) + +(param_decl + (declarator + (pointer_declarator) @variable.parameter)) + +(preproc_params + (identifier) @variable.parameter) + +((call_expression + function: (_) @function.builtin) + (#any-of? @function.builtin + "delay" "pvPut" "pvPutComplete" "pvArrayPutComplete" "pvPutCancel" "pvArrayPutCancel" "pvGet" + "pvGetComplete" "pvArrayGetComplete" "pvGetCancel" "pvArrayGetCancel" "pvGetQ" "pvFreeQ" + "pvFlushQ" "pvAssign" "pvAssignSubst" "pvMonitor" "pvArrayMonitor" "pvStopMonitor" + "pvArrayStopMonitor" "pvSync" "pvArraySync" "pvCount" "pvStatus" "pvSeverity" "pvMessage" + "pvTimeStamp" "pvAssigned" "pvConnected" "pvArrayConnected" "pvIndex" "pvFlush" "pvChannelCount" + "pvAssignCount" "pvConnectCount" "efSet" "efClear" "efTest" "efTestAndClear" "macValueGet" + "optGet")) + +((identifier) @constant.builtin + (#any-of? @constant.builtin + "pvStatOK" "pvStatERROR" "pvStatDISCONN" "pvStatREAD" "pvStatWRITE" "pvStatHIHI" "pvStatHIGH" + "pvStatLOLO" "pvStatLOW" "pvStatSTATE" "pvStatCOS" "pvStatCOMM" "pvStatTIMEOUT" "pvStatHW_LIMIT" + "pvStatCALC" "pvStatSCAN" "pvStatLINK" "pvStatSOFT" "pvStatBAD_SUB" "pvStatUDF" "pvStatDISABLE" + "pvStatSIMM" "pvStatREAD_ACCESS" "pvStatWRITE_ACCESS" "pvSevrOK" "pvSevrERROR" "pvSevrNONE" + "pvSevrMINOR" "pvSevrMAJOR" "pvSevrINVALID" "DEFAULT" "ASYNC" "SYNC" "NOEVFLAG")) diff --git a/runtime/queries/snl/indents.scm b/runtime/queries/snl/indents.scm new file mode 100644 index 000000000..0d6523615 --- /dev/null +++ b/runtime/queries/snl/indents.scm @@ -0,0 +1,61 @@ +[ + (field_declaration_list) + (state_set) + (state) + (block) + (member_decl) +] @indent.begin + +(block + "}" @indent.end) + +[ + "else" + "}" +] @indent.branch + +(call_expression) @indent.begin + +(call_expression + ")" @indent.end) + +(if_statement + condition: (_) @indent.begin) + +(if_statement + consequence: (_) @_consequence + (#not-kind-eq? @_consequence block)) @indent.begin + +(else_statement + consequence: (_) @_consequence + (#not-kind-eq? @_consequence block)) @indent.begin + +(while_statement + body: (statement + (_) @_body) + (#not-kind-eq? @_body block)) @indent.begin + +(for_statement + body: (statement + (_) @_body) + (#not-kind-eq? @_body block)) @indent.begin + +(init_declarator) @indent.begin + +(transition + condition: (_) @indent.begin) + +[ + "#define" + "#ifdef" + "#if" + "#else" + "#endif" +] @indent.zero + +[ + (preproc_arg) + (string_literal) +] @indent.ignore + +(comment) @indent.auto diff --git a/runtime/queries/snl/injections.scm b/runtime/queries/snl/injections.scm new file mode 100644 index 000000000..b595d8033 --- /dev/null +++ b/runtime/queries/snl/injections.scm @@ -0,0 +1,117 @@ +((comment) @injection.content + (#set! injection.language "comment")) + +((c_code) @injection.content + (#set! injection.language "c")) + +((preproc_arg) @injection.content + (#set! injection.self)) + +((call_expression + function: (identifier) @_function + (args + . + [ + (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 + (args + (_) + . + [ + (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 + (args + (_) + . + (_) + . + [ + (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 + (args + (_) + . + (_) + . + (_) + . + [ + (string_literal + (string_content) @injection.content) + (concatenated_string + (string_literal + (string_content) @injection.content)) + ])) + (#any-of? @_function "mvwprintw" "mvwscanw") + (#set! injection.language "printf")) diff --git a/runtime/queries/snl/locals.scm b/runtime/queries/snl/locals.scm new file mode 100644 index 000000000..35c8da5c9 --- /dev/null +++ b/runtime/queries/snl/locals.scm @@ -0,0 +1,65 @@ +; 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) + +((identifier) @local.definition.parameter + (#has-ancestor? @local.definition.parameter param_decl)) + +(init_declarator + (declarator + (identifier)) @local.definition.var) + +(array_declarator + (identifier) @local.definition.var) + +; Struct +(member_decl + (declarator + (identifier)) @local.definition.field) + +(structdef + name: (identifier) @local.definition.type) + +; References +((field_expression + field: (identifier) @local.reference) + (#set! reference.kind "field")) + +((call_expression + function: (identifier) @local.reference) + (#set! reference.kind "call")) + +((basetype + (identifier) @local.reference) + (#set! reference.kind "type")) + +; SNL specific +(state_set + name: (identifier) @local.definition) + +(state + name: (identifier) @local.definition) + +(state_statement + name: (identifier) @local.reference) + +(transition + name: (identifier) @local.reference) + +(identifier) @local.reference + +[ + (for_statement) + (if_statement) + (while_statement) + (source_file) + (block) + (state_set) + (state_block) +] @local.scope |
