Skip to content

Repository files navigation

tree-sitter-native

CI status tree-sitter grammar Latest release License

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.

Usage

bun install
./node_modules/.bin/tree-sitter generate
./node_modules/.bin/tree-sitter test

src/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.

Nodes

.native is XML-shaped. The parts a plain XML grammar would leave as one string get their own nodes:

  • structure_tag for template, for, if, else, use, import, slot
  • interpolation for {b.is_code} and {percent(done / total)}, with expressions parsed at proper precedence (or < and < comparison < ++ < + - < * / < unary)
  • event_attribute for on-press="copy_code_block:{b.code_index}", splitting the message tag from its payload
  • args_attribute for args="gap=0 grow=0 label=", including empty defaults
  • number, boolean and attribute_text for 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.

Fixtures

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/.

License

MIT

About

Tree-sitter grammar for Native SDK .native markup

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages