CDL (Common Data Language) grammar for tree-sitter.
CDL is used to represent data from NetCDF files in a text-based, human-readable format.
-
Install the tree-sitter CLI.
There are several ways of doing this. The easiest, assuming you have Rust on your system, is using cargo:cargo install tree-sitter-cli --locked -
Clone this repository.
-
Set up tree-sitter by running:
tree-sitter init-configand edit the resulting configuration file to add the directory containing
tree-sitter-cdl/to theparser-directoriesarray. Note: you must add the containing directory, not the directory itself! -
Build the CDL grammar
Navigate to thetree-sitter-cdldirectory that you cloned and run:tree-sitter generateYou can test if this was successful by running
tree-sitter dump-languagesfrom somewhere else which should show information for the cdl language. -
Run
You should now be able to run syntax highlighting on a.cdlfile from the command line by running:tree-sitter highlight myfile.cdl
For the many ways in which you can use a tree-sitter grammar and parser see the official tree-sitter documentation.
To get syntax highlighting on the results of the ncdump command we need to pipe
the output to the tree-sitter highlight query.
Since we cannot detect the file type from the extension (.cdl) we need to tell
tree-sitter which scope to use.
ncdump myfile.nc | tree-sitter highlight --scope source.cdl
If you want this to be the default behaviour for ncdump then add the following to
your .bashrc or .zshrc file:
ncdump() {
command ncdump "$@" | tree-sitter highlight --scope source.cdl
}This will create a function that automatically replaces ncdump to pipe through
tree-sitter whilst preserving options like -h or -v var etc.
If you want to preserve ncdump you could instead name it nccolordump or similar.
Many text editors have support for tree-sitter including Neovim and emacs. For specifics see instructions for text-editors.
Copyright © Jack Atkinson
tree-sitter-cdl is distributed under the MIT Licence.
Detailed plans for development of this project can be seen in the roadmap document.
These include future features and integration with other codes.
Contributions and collaborations are welcome.
For bugs, feature requests, and clear suggestions for improvement please open an issue.
If you have built something upon tree-sitter-cdl that would be useful to others, or can address an open issue, please fork the repository and open a pull request.
Further details of the development process are available in the developer guidelines.
Everyone participating in the tree-sitter-cdl project, in particular in issues and pull requests, is expected to treat other people with respect and, more generally, to follow the guidelines articulated in the Python Community Code of Conduct.
tree-sitter-cdl is currently a hobby project by Jack Atkinson maintained in spare time.
If you make use of this please do let me know so that I can feature your work here.