Skip to content

Commit

Permalink
feat: Add support for cylc configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotfontaine committed Oct 4, 2024
1 parent 162028d commit c8e5ad7
Show file tree
Hide file tree
Showing 6 changed files with 176 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 @@ -29,6 +29,7 @@
| crystal ||| | `crystalline` |
| css || || `vscode-css-language-server` |
| cue || | | `cuelsp` |
| cylc |||| |
| d |||| `serve-d` |
| dart |||| `dart` |
| dbml || | | |
Expand Down
12 changes: 12 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3810,3 +3810,15 @@ language-servers = ["circom-lsp"]
[[grammar]]
name = "circom"
source = { git = "https://github.com/Decurity/tree-sitter-circom", rev = "02150524228b1e6afef96949f2d6b7cc0aaf999e" }

[[language]]
name = "cylc"
scope = "source.cylc"
injection-regex = "cylc"
file-types = ["cylc", { glob = "suite.rc" }]
comment-tokens = "#"
indent = { tab-width = 4, unit = " " }

[[grammar]]
name = "cylc"
source = { git = "https://github.com/elliotfontaine/tree-sitter-cylc", rev = "30dd40d9bf23912e4aefa93eeb4c7090bda3d0f6" }
101 changes: 101 additions & 0 deletions runtime/queries/cylc/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
(ERROR) @markup.bold

[
(jinja2_expression)
(jinja2_statement)
(jinja2_comment)
(jinja2_shebang)
] @special

(include_statement
directive: _ @keyword.directive
path: _ @string.path)

(comment) @comment.line

(graph_section
name: _? @label)

(task_section
name: (_
(task_name) @namespace))

(top_section
brackets_open: _ @ponctuation.bracket
name: _? @label
brackets_close: _ @ponctuation.bracket)

(sub_section_1
brackets_open: _ @ponctuation.bracket
name: _? @label
brackets_close: _ @ponctuation.bracket)

(sub_section_2
brackets_open: _ @ponctuation.bracket
name: _? @label
brackets_close: _ @ponctuation.bracket)

(runtime_section
brackets_open: _ @ponctuation.bracket
name: _? @label
brackets_close: _ @ponctuation.bracket)

(graph_setting
key: (_) @constant.numeric.integer
operator: (_)? @operator)

(quoted_graph_string
quotes_open: _ @string
quotes_close: _ @string)

(multiline_graph_string
quotes_open: _ @string
quotes_close: _ @string)

[
(graph_logical)
(graph_arrow)
(graph_parenthesis)
] @operator

(intercycle_annotation
(recurrence) @constant.numeric.integer)

(graph_task
xtrigger: _? @operator
suicide: _? @operator
name: _ @namespace)

(task_parameter
"<" @tag
name: (_)? @special
","? @tag
"="? @tag
selection: (_)? @special
">" @tag)

(intercycle_annotation
"[" @tag
(recurrence)? @constant.numeric.integer
"]" @tag)

(task_output
":" @tag
(nametag) @variable.other)

(task_output
"?"? @tag)

(setting
key: (key) @variable
operator: (_)? @operator
value: [
(unquoted_string) @string
(quoted_string) @string
(multiline_string) @string
(boolean) @constant.builtin.boolean
(integer) @constant.numeric.integer
]?)

(datetime) @constant.numeric.float

24 changes: 24 additions & 0 deletions runtime/queries/cylc/indents.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
(top_section)
(sub_section_1)
(sub_section_2)
(graph_section)
(runtime_section)
(task_section)
] @indent

[
(top_section)
(sub_section_1)
(sub_section_2)
(graph_section)
(runtime_section)
(task_section)
] @extend

; Doesn't work ?
; (unquoted_string
; (string_content) @anchor) @align

(line_continuation) @indent.always

18 changes: 18 additions & 0 deletions runtime/queries/cylc/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
((setting
key: (key) @key (#match? @key "^script$|\-script$|^script\-")
value: (_
(string_content) @injection.content))
(#set! "injection.language" "bash"))

; Requires no spacing around "=" in environment settings for proper highlighting.
; Could be improved if Tree-sitter allowed to specify the target node of the injected
; language, instead of always using the root node.
; See this proposal:
; https://github.com/tree-sitter/tree-sitter/issues/3625
((task_section
(sub_section_2
name: (_) @section_name (#match? @section_name "environment")
(setting) @injection.content))
(#set! "injection.language" "bash")
(#set! injection.combined)
(#set! injection.include-children))
20 changes: 20 additions & 0 deletions runtime/queries/cylc/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(comment) @comment.inside
(comment)+ @comment.around

(_
brackets_open: _
name: _?
brackets_close: _
_* @class.inside) @class.around

(setting
value: _? @function.inside) @function.around

(graph_setting
value: _? @function.inside) @function.around

(graph_string_content
((graph_task) @entry.inside))

(task_parameter
((_) @parameter.inside . ","? @parameter.around) @parameter.around)

0 comments on commit c8e5ad7

Please sign in to comment.