A Tree-Sitter grammar for Cylc's workflow configurations.
As a grammar, tree-sitter-cylc can be used to generate syntax highlighting for Cylc files in text
editors that support Tree-Sitter. /queries/highlights.scm
and
/queries/injections.scm
can be used as a template to write queries
for your target editor.
tree-sitter-cylc is available as a package on PyPi. You can install it through pip as follows:
pip install tree-sitter tree-sitter-cylc
You can then use the tree_sitter_cylc module to parse Cylc files from Python:
import tree_sitter_cylc as tscylc
from tree_sitter import Language, Parser
CYLC_LANGUAGE = Language(tscylc.language())
parser = Parser(CYLC_LANGUAGE)
source_code = str(
"""
[runtime]
[[task_1]]
script = echo "Hello, World!"
"""
)
tree = parser.parse(bytes(source_code, "utf8"))
root_node = tree.root_node
runtime_section = root_node.children[0]
task_section = runtime_section.children[3]
setting = task_section.children[3]
value = setting.child_by_field_name("value")
assert root_node.type == "workflow_configuration"
assert root_node.start_point == (0, 0)
assert root_node.end_point == (4, 0)
assert runtime_section.type == "runtime_section"
assert task_section.type == "task_section"
assert setting.type == "setting"
assert value.type == "unquoted_string"
See Tree-Sitter's Python bindings documentation for more information.
Contributions, bug reports, and suggestions are welcome! Please submit a pull request or file an issue on the GitHub repository.
This project is licensed under the MIT License. See LICENSE for details.