feat(snl): add parser and queries

This commit is contained in:
Minijackson
2025-09-11 15:27:19 +02:00
committed by Christian Clason
parent 6ac9f2e512
commit 53819acac2
7 changed files with 520 additions and 0 deletions

View File

@@ -265,6 +265,7 @@ jsx (queries only)[^jsx] | unstable | `HFIJ ` | | @steelsojka
[smali](https://github.com/tree-sitter-grammars/tree-sitter-smali) | unstable | `HFIJL` | | @amaanq
[smithy](https://github.com/indoorvivants/tree-sitter-smithy) | unstable | `H  J ` | | @amaanq, @keynmol
[snakemake](https://github.com/osthomas/tree-sitter-snakemake) | unstable | `HFIJL` | | @osthomas
[snl](https://github.com/minijackson/tree-sitter-snl)[^snl] | unstable | `HFIJL` | | @minijackson
[solidity](https://github.com/JoranHonig/tree-sitter-solidity) | unstable | `HF J ` | | @amaanq
[soql](https://github.com/aheber/tree-sitter-sfapex) | unstable | `H    ` | | @aheber, @xixiafinland
[sosl](https://github.com/aheber/tree-sitter-sfapex) | unstable | `H    ` | | @aheber, @xixiafinland
@@ -359,4 +360,5 @@ jsx (queries only)[^jsx] | unstable | `HFIJ ` | | @steelsojka
[^query]: Tree-sitter query language
[^sflog]: Salesforce debug log
[^slang]: Shader Slang
[^snl]: EPICS Sequencer's SNL files
<!--parserinfo-->

View File

@@ -2081,6 +2081,15 @@ return {
maintainers = { '@osthomas' },
tier = 2,
},
snl = {
install_info = {
url = 'https://github.com/minijackson/tree-sitter-snl',
revision = '846e2d6809ac5863a15b5494f20fd267c21221c8',
},
maintainers = { '@minijackson' },
readme_note = "EPICS Sequencer's SNL files",
tier = 2,
},
solidity = {
install_info = {
revision = '4e938a46c7030dd001bc99e1ac0f0c750ac98254',

View File

@@ -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

View File

@@ -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"))

View File

@@ -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

View File

@@ -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"))

View File

@@ -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