Skip to content

Commit

Permalink
Adding snakemake to language (#11858)
Browse files Browse the repository at this point in the history
* feat: snakemake language

* feat: snakemake syntax highlighting

* doc: xtask docgen - snakemake

* Addressed feedback: removed redundant grammar

* fixed indentation

* removed has-ancestor predicate

---------

Co-authored-by: “SebastianDall” <“[email protected]”>
  • Loading branch information
SebastianDall and “SebastianDall” authored Oct 18, 2024
1 parent 855a43a commit a145335
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
| smali || || |
| smithy || | | `cs` |
| sml || | | |
| snakemake || || `pylsp` |
| solidity ||| | `solc` |
| spicedb || | | |
| sql ||| | |
Expand Down
14 changes: 14 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3835,3 +3835,17 @@ language-servers = ["circom-lsp"]
[[grammar]]
name = "circom"
source = { git = "https://github.com/Decurity/tree-sitter-circom", rev = "02150524228b1e6afef96949f2d6b7cc0aaf999e" }

[[language]]
name = "snakemake"
scope = "source.snakemake"
roots = ["Snakefile", "config.yaml", "environment.yaml", "workflow/"]
file-types = ["smk", "Snakefile"]
comment-tokens = ["#", "##"]
indent = { tab-width = 2, unit = " " }
language-servers = ["pylsp" ]


[[grammar]]
name = "snakemake"
source = { git = "https://github.com/osthomas/tree-sitter-snakemake", rev = "e909815acdbe37e69440261ebb1091ed52e1dec6" }
20 changes: 20 additions & 0 deletions runtime/queries/snakemake/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2016 Max Brunsfeld
Copyright (c) 2023 Oliver Thomas

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions runtime/queries/snakemake/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; inherits: python

[
(rule_definition)
(rule_inheritance)
(module_definition)
(checkpoint_definition)
] @fold
76 changes: 76 additions & 0 deletions runtime/queries/snakemake/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
; inherits: python

; Compound directives
[
"rule"
"checkpoint"
"module"
] @keyword

; Top level directives (eg. configfile, include)
(module
(directive
name: _ @keyword))

; Subordinate directives (eg. input, output)
((_)
body: (_
(directive
name: _ @label)))

; rule/module/checkpoint names
(rule_definition
name: (identifier) @type)

(module_definition
name: (identifier) @type)

(checkpoint_definition
name: (identifier) @type)

; Rule imports
(rule_import
"use" @keyword.import
"rule" @keyword.import
"from" @keyword.import
"exclude"? @keyword.import
"as"? @keyword.import
"with"? @keyword.import)

; Rule inheritance
(rule_inheritance
"use" @keyword
"rule" @keyword
"with" @keyword)

; Wildcard names
(wildcard (identifier) @variable)
(wildcard (flag) @variable.parameter.builtin)

; builtin variables
((identifier) @variable.builtin
(#any-of? @variable.builtin "checkpoints" "config" "gather" "rules" "scatter" "workflow"))

; References to directive labels in wildcard interpolations
; the #any-of? queries are moved above the #has-ancestor? queries to
; short-circuit the potentially expensive tree traversal, if possible
; see:
; https://github.com/nvim-treesitter/nvim-treesitter/pull/4302#issuecomment-1685789790
; directive labels in wildcard context
((wildcard
(identifier) @label)
(#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards"))

((wildcard
(attribute
object: (identifier) @label))
(#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards"))

((wildcard
(subscript
value: (identifier) @label))
(#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards"))

; directive labels in block context (eg. within 'run:')
((identifier) @label
(#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards"))
27 changes: 27 additions & 0 deletions runtime/queries/snakemake/indents.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; inherits: python


[
(rule_definition)
(checkpoint_definition)
(rule_inheritance)
(module_definition)
] @indent

[
(rule_definition)
(checkpoint_definition)
(rule_inheritance)
(module_definition)
] @extend


(directive) @indent
(directive) @extend

(rule_import
"with"
":") @indent
(rule_import
"with"
":") @extend
5 changes: 5 additions & 0 deletions runtime/queries/snakemake/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
; inherits: python

(wildcard
(constraint) @injection.content
(#set! injection.language "regex"))
1 change: 1 addition & 0 deletions runtime/queries/snakemake/locals.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; inherits: python

0 comments on commit a145335

Please sign in to comment.