Skip to content

jatkinson1000/tree-sitter-cdl

Repository files navigation

tree-sitter-cdl

GitHub Actions Workflow Status GitHub Actions Workflow Status

CDL (Common Data Language) grammar for tree-sitter.

CDL is used to represent data from NetCDF files in a text-based, human-readable format.

Setup and Use

Basic setup

  1. 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
    
  2. Clone this repository.

  3. Set up tree-sitter by running:

    tree-sitter init-config
    

    and edit the resulting configuration file to add the directory containing tree-sitter-cdl/ to the parser-directories array. Note: you must add the containing directory, not the directory itself!

  4. Build the CDL grammar
    Navigate to the tree-sitter-cdl directory that you cloned and run:

    tree-sitter generate
    

    You can test if this was successful by running tree-sitter dump-languages from somewhere else which should show information for the cdl language.

  5. Run
    You should now be able to run syntax highlighting on a .cdl file 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.

Highlighting for ncdump

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.

Highlighting in text editors

Many text editors have support for tree-sitter including Neovim and emacs. For specifics see instructions for text-editors.

License

Copyright © Jack Atkinson

tree-sitter-cdl is distributed under the MIT Licence.

Project Roadmap

Detailed plans for development of this project can be seen in the roadmap document.

These include future features and integration with other codes.

Contributions

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.

Code of Conduct

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.

Authors and Acknowledgment

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.

References

About

CDL grammar for tree-sitter | NetCDF

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published