This repository contains a Tree-sitter grammar for the Chicory programming language. Tree-sitter is an incremental parsing system that can build a syntax tree for source files and efficiently update the syntax tree as the source file is edited.
- Add this to your Helix
languages.toml
:
[[language]]
name="chicory"
scope="source.chic"
file-types=["chic"]
[[grammar]]
name = "chicory"
source = {git = "https://github.com/chicory-lang/tree-sitter-chicory" , rev="CHANGE ME: target commit hash, probably latest for now"}
- Run
hx -g fetch
to update the grammar - Run
hx -g build
to build the grammar - Copy the
queries
into~/.config/helix/runtime/queries/chicory
-
Add
chicory
to the list ofensure_installed
languages in yourrequire('nvim-treesitter.configs').setup
block. -
Associate
.chic
files withchicory
:
vim.filetype.add({
extension = {
chic = "chicory", -- Map `.chic` files to the `chicory` filetype
},
})
- Tell neovim where to find the Chicory parser:
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.chicory = {
install_info = {
url = "https://github.com/chicory-lang/tree-sitter-chicory.git", -- Replace with your grammar repository
files = { "src/parser.c" }, -- Add other files like `src/scanner.c` if needed
branch = "main", -- Replace with the appropriate branch
generate_requires_npm = false, -- Set to true if your grammar requires npm
requires_generate_from_grammar = false, -- Set to true if you need to generate the parser
},
filetype = "chicory", -- Associate the parser with your language's filetype
}
- Put/link the queries in the right place (I used a symlink):
$ ln -s .config/nvim/queries/chicory $TREE_SITTER_CHICORY/queries
Note: You can also point the parser to a local copy of the tree-sitter-chicory
repo instead of the github url.
For more information, see https://github.com/nvim-treesitter/nvim-treesitter/#adding-parsers
This section tracks the implementation of major language features from the ANTLR grammar.
- Primitive types (number, string, boolean)
- Tuple types (e.g.,
[number, string]
) - Record types (e.g.,
{ x: number, y: number }
) - Algebraic Data Types (ADTs)
- Simple variants (e.g.,
type Shape = Circle | Square
) - Variants with primitive types (e.g.,
type Option = None | Some(number)
) - Variants with record fields (e.g.,
type Result = Ok(string) | Error({ message: string })
)
- Simple variants (e.g.,
- Type references (uppercase identifiers)
- Match expressions (e.g.,
match (value) { Some(x) => x + 1, None => 0 }
)- Pattern matching on variants
- Pattern matching with literals
- Pattern matching with identifiers
- Binary operations
- Function calls
- Literals (number, string, boolean)
- Identifiers
- Parenthesized expressions
- JSX expressions
- Self-closing elements (e.g.,
<Div />
) - Elements with children (e.g.,
<Div>Hello world</Div>
) - Elements with attributes (e.g.,
<Div className="container" count={5} />
) - Nested elements
- Expression children (e.g.,
<Div>{count}</Div>
)
- Self-closing elements (e.g.,
- Let assignments (e.g.,
let x = 42
) - Const declarations (e.g.,
const PI = 3.14
) - Assignment statements
- Import statements
- Export statements
- Comments (single-line and multi-line)