Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hedyhli/tree-sitter-cognate
TS grammar for the Cognate language
https://github.com/hedyhli/tree-sitter-cognate
tree-sitter
Last synced: about 1 month ago
JSON representation
TS grammar for the Cognate language
- Host: GitHub
- URL: https://github.com/hedyhli/tree-sitter-cognate
- Owner: hedyhli
- License: mit
- Created: 2024-07-01T07:11:07.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-16T08:32:59.000Z (about 2 months ago)
- Last Synced: 2024-09-27T10:22:52.697Z (about 2 months ago)
- Topics: tree-sitter
- Language: Emacs Lisp
- Homepage:
- Size: 722 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# tree-sitter-cognate
[![Checks](https://github.com/hedyhli/tree-sitter-cognate/actions/workflows/checks.yml/badge.svg)](https://github.com/hedyhli/tree-sitter-cognate/actions/workflows/checks.yml)
[What is Cognate?](https://cognate-lang.github.io)
The official regex-based highlighting plugins are great, but for a wider
reach of editor support a tree-sitter grammar is needed which gives way to
a more unified approach to supporting indents and code-folding rules.## Editor setup
### Nvim
Note that the built-in tree-sitter support requires Nvim 0.9+.
- [X] Highlights
- [X] Identifiers fallback as variables
- [X] Function name after `Def`
- [X] Field name after `.`
- [X] Toggle line comments
- [X] Toggle block comments (for `Comment.nvim` and `kommentary`)
- [X] Injection language for comments
- [X] Indents
- [X] Folds
- [X] Locals
- [X] [Text objects](https://github.com/nvim-treesitter/nvim-treesitter-textobjects)
- [X] Function
- [X] Block
- [X] Assignment
- [X] Statement
- [X] Comment
- [X] Number
- [X] [Context](https://github.com/nvim-treesitter/nvim-treesitter-context)Ensure `nvim-treesitter` is installed, then install this repo as a plugin using
your favorite plugin manager (`hedyhli/tree-sitter-cognate`);Lazy.nvim example:
```lua
{
"hedyhli/tree-sitter-cognate",
dependencies = { "nvim-treesitter/nvim-treesitter" },
enabled = vim.fn.has('nvim-0.9') == 1,
},
```If you use `Comment.nvim` or `kommentary`, they will automatically be set up to
be usable for commenting for both line and blocks in Cognate in addition to
`commentstring`.Parsers and queries will be automatically set up. Finally either put `cognate`
into your `ensure_installed`, or run `:TSInstall cognate`.### Emacs
- [X] Highlights
- [ ] Identifiers fallback as variables
- [ ] Function name after `Def`
- [ ] Field name after `.`
- [X] Toggle line comments
- [ ] Toggle block comments
- [X] Indents
- [ ] ImenuA library for `cognate-ts-mode` is included in this repository, it supports the
built-in tree-sitter feature for Emacs 29 and above. The major mode supports
a few other features using tree-sitter in addition to highlighting, as listed
above.For other versions, consider using the official cognate-mode package for emacs
(which uses regex-based syntax highlighting), or consult the documentation on
how to add a new grammar for the tree-sitter package you are using.Details on how to set up tree-sitter-cognate for Emacs 29+ is as follows.
### Step 1
Install the grammar using `M-x treesit-install-language-grammar`, enter
`cognate`, the URL `https://github.com/hedyhli/tree-sitter-cognate`, and
accept default options.### Step 2
Install this repository as a package using your package manager.
Elpaca example:
```elisp
(use-package cognate-ts-mode
:ensure (:host "github" :repo "hedyhli/tree-sitter-cognate"))
```Note that this package is not currently published on ELPA/MELPA.
### Step 3
A restart of emacs might be required after installation. Finally, test
the syntax highlighting on a Cognate file. All `*.cog` files are set
up to automatically use `cognate-ts-mode`.### Helix
- [X] Highlights
- [X] Identifiers fallback as variables
- [X] Function name after `Def`
- [X] Field name after `.`
- [X] Toggle line comments
- [X] Toggle block comments
- [X] Injection language for comments
- [X] Indents
- [X] Text objects
- [X] Functions
- [X] Comments
- [ ] Blocks (note that you can simply use `mi)` to select parenthesis)Add a new language by appending the contents of `helix/language.toml` in this
repository.Next, download and install the grammar:
```
hx -g fetch
hx -g build
```Then copy (or link) queries files from `helix/` into the correct
runtime directory. For instance, `helix/queries/cognate` (of this repo) to
`~/.config/helix/runtime/queries/cognate`. Note that Helix should use queries
under the **`helix/`** directory in this repository.### VSCode
- [X] Highlights
First, ensure the [tree-sitter extension for VS
Code](https://github.com/AlecGhost/tree-sitter-vscode) is installed.Next download the
`tree-sitter-cognate.vsix` file from this repository to add support for
detecting Cognate files, and install it as an extension.Clone this repository locally somewhere, then add these lines to your
`settings.json`:```json
"tree-sitter-vscode.languageConfigs": [{
"lang": "cognate",
"parser": "[PATH_TO_THIS_REPOSITORY]/tree-sitter-cognate.wasm",
"highlights": "[PATH_TO_THIS_REPOSITORY]/queries/cognate/highlights.scm"
}]
```### Vim
Consider using the official vim plugin for vim's regex-based syntax
highlighting: .## TODO
- [x] Support symbols.
- [x] Support block comments.
- [x] Don't enforce "function" statements -- there's no such thing.
- [x] Floating point numbers.
- [x] String escapes.
- [ ] Case insensitivity for indentifiers (booleans in grammar, keywords
everywhere else)
- [x] Use cognac's `builtins.c` rather than hardcoding builtins
- [x] Support functions and fields for emacs## References
-
-