add readme

This commit is contained in:
2025-10-06 16:51:08 -06:00
parent 6b3300744d
commit 51698afe89

View File

@@ -1,39 +1,40 @@
# tree-sitter-hcl HCL and Terraform parsers that treat `{%` as comment lines for... reasons. iykyk 🤷
tree-sitter grammar for the [HCL](https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md) language # Neovim usage with the `nvim-treesitter` plugin
## Try It Out ```lua
local configs = require("nvim-treesitter.configs")
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
Try the parser in the [playground](https://tree-sitter-grammars.github.io/tree-sitter-hcl/) local jhcl_repo = "https://code.buildbetter.boats/jenterkin/tree-sitter-jhcl"
## Example parser_config.hcl = {
install_info = {
url = jhcl_repo,
files = { "src/parser.c", "src/scanner.c" },
}
}
Highlighting `example/example.hcl`: parser_config.terraform = {
install_info = {
url = jhcl_repo,
files = { "src/parser.c", "src/scanner.c" },
location = "dialects/terraform",
}
}
![Highlighting Example](https://i.imgur.com/yUJ0ybK.png) configs.setup({
-- ...
## Developing -- We overwrote the default `nvim-treesitter` configs for `hcl` and
-- `terraform` above, so we can include them in `ensure_installed` normally
ensure_installed = {
-- ...
"hcl",
"terraform",
-- ...
},
It is recommended to use `nix` to fulfill all development dependencies. To activate the development environment simply run `nix-shell` in the project root. -- ...
})
## Running Tests
To run tests simply run `nix-shell --run 'tree-sitter test'`.
## Compliance
The directory `example/real_world_stuff` contains a corpus of hcl files that I found with the github query `language:HCL` for users `coreos`, `hashicorp`, `oracle` and `terraform-community-modules`.
```bash
tree-sitter parse --quiet --stat example/real_world_stuff/*/*
Total parses: 1892; successful parses: 1892; failed parses: 0; success percentage: 100.00%
``` ```
## Fuzzing
See the [fuzzing repo for this parser](https://github.com/MichaHoffmann/tree-sitter-hcl-fuzz)
## Attributions
Pages were copied from https://github.com/m-novikov/tree-sitter-sql