A Tree-sitter grammar for Arizona Framework.
This Tree-sitter grammar provides:
- Syntax highlighting for
.herlArizona template files - HTML injection for static content (proper HTML syntax highlighting)
- Erlang injection for dynamic expressions inside
{...}blocks - Nested template support with proper brace matching
- Editor integration for Neovim, VSCode, and other Tree-sitter supported editors
- Erlang integration for highlighting Arizona templates within Erlang code
- Node.js
# Clone the repository
git clone https://github.com/arizona-framework/tree-sitter-arizona.git
cd tree-sitter-arizona
# Install dependencies
npm install
# Generate and build the parser
npm run buildFor system-wide installation of the parser library:
# Install parser system-wide (requires sudo)
sudo make installThis installs:
- Header file:
/usr/local/include/tree_sitter/tree-sitter-arizona.h - Static library:
/usr/local/lib/libtree-sitter-arizona.a - Shared library:
/usr/local/lib/libtree-sitter-arizona.so - pkg-config file:
/usr/local/lib/pkgconfig/tree-sitter-arizona.pc - Query files:
/usr/local/share/tree-sitter/queries/arizona/*.scm
This allows other applications to link against the Arizona parser library and use the queries globally.
For the best Arizona development experience with complete language support, syntax highlighting, LSP integration, and embedded language features, use the dedicated Neovim plugin:
arizona-framework/arizona.nvim
-
Configure nvim-treesitter in your
init.lua:require('nvim-treesitter.configs').setup({ -- ... other config ensure_installed = { "html", "erlang", "arizona" -- Add arizona }, }) -- Register Arizona parser local parser_config = require('nvim-treesitter.parsers').get_parser_configs() parser_config.arizona = { install_info = { url = "https://github.com/arizona-framework/tree-sitter-arizona", files = { "src/parser.c" }, branch = "main", }, filetype = "arizona", } -- Register filetype vim.filetype.add({ extension = { herl = "arizona" }, pattern = { [".*%.herl"] = "arizona" }, })
-
Set up query files:
# Create symlinks to keep queries in sync mkdir -p ~/.config/nvim/after/queries/arizona ln -sf "$(pwd)/queries/highlights.scm" ~/.config/nvim/after/queries/arizona/highlights.scm ln -sf "$(pwd)/queries/injections.scm" ~/.config/nvim/after/queries/arizona/injections.scm
-
Enable Erlang integration:
# Copy Erlang injection queries mkdir -p ~/.config/nvim/after/queries/erlang cp erlang-queries/injections.scm ~/.config/nvim/after/queries/erlang/injections.scm
The Arizona grammar recognizes two main elements:
- Static Content: HTML markup and text content
- Dynamic Content: Erlang expressions enclosed in
{...}braces
tree-sitter-arizona/
├── src/
│ ├── parser.c # Generated C parser
│ ├── grammar.json # Generated grammar JSON
│ └── node-types.json # Generated node types
├── queries/
│ ├── highlights.scm # Syntax highlighting rules
│ └── injections.scm # Language injection rules
├── erlang-queries/
│ └── injections.scm # Erlang-side injection queries
├── test/
│ ├── corpus/ # Tree-sitter test cases
│ │ ├── basic.txt # Basic parsing tests
│ │ ├── complex.txt # Complex template tests
│ │ └── tuples.txt # Erlang tuple tests
│ └── highlight/
│ └── basic.herl # Highlight test examples
├── grammar.js # Grammar definition
├── package.json # npm configuration and scripts
├── tree-sitter.json # Tree-sitter configuration
├── Makefile # Build configuration
└── README.md # This file
# Build the parser
npm run build
# Test parsing specific content
echo '<div>{arizona_template:get_binding(name, Bindings)}</div>' | npm run parse
# Parse files interactively
npm run parse test-file.herl
# Test queries
npm run query test-file.herl
# Run test suite
npm run test
# Update test expectations
npm run test:update
# Debug test failures
npm run test:debug
# Build WebAssembly version for web usage
npm run build:wasm
# Open tree-sitter playground
npm run playgroundIf you like this tool, please consider sponsoring me. I'm thankful for your never-ending support ❤️
I also accept coffees ☕
Copyright (c) 2025 William Fank Thomé
Arizona is 100% open-source and community-driven. All components are available under the Apache 2 License on GitHub.
See LICENSE.md for more information.
