Tree-sitter grammar for the .native markup used by Native SDK.
Built for zed-native-sdk, but it's a plain grammar, so Neovim, Helix and web-tree-sitter can use it too.
bun install
./node_modules/.bin/tree-sitter generate
./node_modules/.bin/tree-sitter testsrc/parser.c is committed because Zed compiles it directly instead of running
tree-sitter generate. CI regenerates it and fails if the committed copy is out of date.
.native is XML-shaped. The parts a plain XML grammar would leave as one string get their own
nodes:
structure_tagfortemplate,for,if,else,use,import,slotinterpolationfor{b.is_code}and{percent(done / total)}, with expressions parsed at proper precedence (or<and< comparison <++<+ -<* /< unary)event_attributeforon-press="copy_code_block:{b.code_index}", splitting the message tag from its payloadargs_attributeforargs="gap=0 grow=0 label=", including empty defaultsnumber,booleanandattribute_textfor literal values
Element and attribute names are not enumerated. The set is closed at any given moment (the SDK's
language server offers 77 elements and 62 attributes) but it grows with each release, and a
grammar that lists them starts rejecting valid markup the moment it falls behind. Whether
<colunm> is real is a question for native markup check.
python3 scripts/extract-corpus.py pulls markup out of the SDK's own test suite. The Zig source
ships in the npm package, and ui_markup*tests.zig holds a few hundred snippets as multiline
strings. The script keeps the ones native markup check accepts and drops the rest, so the
fixtures follow whichever SDK version is installed. They're gitignored; the committed tests are in
test/corpus/.
MIT