- JavaScript 100%
| bindings | ||
| src | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| binding.gyp | ||
| Cargo.toml | ||
| CMakeLists.txt | ||
| go.mod | ||
| grammar.js | ||
| Makefile | ||
| package-lock.json | ||
| package.json | ||
| Package.swift | ||
| pyproject.toml | ||
| README.md | ||
| setup.py | ||
| tree-sitter.json | ||
tree-sitter-hml
A Tree-sitter grammar for HML, a small markup language that looks a bit like HTML but uses block syntax with curly braces.
Overview
This grammar parses HML documents with:
- uppercase element names like
Document,Body,Box, andParagraph - optional attribute lists in square brackets
- inline string content
- nested block content
- inline style declarations using CSS-like property syntax
- comments using
// ...and/* ... */
Example HML:
Document {
Body {
Box[class: "page"] {
background-color: #f8fafc
padding: 32px
Paragraph {
color: #475569
font-size: 16px
"Hello from HML"
}
}
}
}
Grammar shape
The parser currently recognizes core node types such as:
source_fileelementattribute_listattributeblockstyle_declarationtextinline_textvaluetag_nameidentifierstringnumbercolorkeyword_valuecomment
Important distinction
Element names and style properties are intentionally separated:
- element names use
tag_name - style properties use
identifier
That allows input like this to parse correctly:
Box {
background-color: #ffffff
}
without incorrectly treating background-color as another element.
Supported value forms
The grammar supports values such as:
- strings:
"Hello" - colors:
#4f46e5 - numbers:
12,1.5,100% - dimensions:
16px,0.08em,100vh - multi-part numeric values:
0 40px 40px 40px - identifiers:
serif - keyword values:
flex,grid,auto,center,pointer
Project structure
Typical important files in this repository:
grammar.js— source grammar definitionsrc/parser.c— generated parsersrc/grammar.json— generated grammar JSONsrc/node-types.json— generated node type definitionsexamples/— example.hmlfiles used for validationbindings/— generated and maintained language bindingstree-sitter.json— Tree-sitter package metadata
Development
Install dependencies
npm install
Regenerate the parser
Whenever you update grammar.js, regenerate the generated artifacts:
npx tree-sitter generate
This updates files such as:
src/parser.csrc/grammar.jsonsrc/node-types.json
Test parsing against examples
You can validate the grammar against the example documents:
for f in examples/*.hml; do
echo "=== $f ==="
npx tree-sitter parse "$f"
done
A healthy grammar should parse these files without ERROR nodes.
Build the WebAssembly parser
If you want a WASM artifact for editor integration or testing:
npx tree-sitter build --wasm
This should produce a .wasm build artifact in the repository.
Run Rust tests
This repository also includes Rust bindings:
cargo test
Query authoring notes
If you are writing editor queries for this grammar, make sure they match the actual node names.
For example:
- use
tag_namefor element names - use
identifierfor attribute names - use
style_declarationfor CSS-like property/value lines - do not query nonexistent nodes such as
property,line_comment, orblock_comment
A correct pattern for element highlighting looks like:
(element
name: (tag_name) @tag)
A correct pattern for style declarations looks like:
(style_declaration
property: (identifier) @property)
Zed extension workflow
If you are using this grammar from a local Zed extension during development:
- point the extension grammar entry at the local repository using a
file://URL - use
HEADfor the development revision - install the extension from the extension root, not from the grammar repository root
- ensure your query files match the current node types from
src/node-types.json
Notes on comments
The grammar supports:
// line comments/* block comments */
If you configure editor comment behavior, use // as the line comment prefix.