A Tree-sitter grammar for parsing EmmyLua documentation comments.
This project provides Tree-sitter grammar support for EmmyLua documentation comments. EmmyLua is an annotation format for documenting Lua code, widely used in Lua IDEs and editors.
- π― Complete Annotation Support - 25+ annotation types
- π Lua Comment Prefix Support - Supports
-,--and---prefixes - π Type Continuation - Supports multi-line union types with
--- | type - π¨ Syntax Highlighting - Complete query file support
- π‘οΈ Line-start Detection - Only parses annotations at the beginning of lines
- π Text Line Fallback - Non-annotation lines are captured as text_line nodes
- π¦ Multi-language Bindings - Node.js, Rust and Python
- β‘ High Performance - 3000+ bytes/ms parsing speed
- π ABI 15 Support - Uses the latest tree-sitter ABI version
This project includes a tree-sitter.json configuration file for:
- β Using ABI version 15 (latest version)
- β Automatic query file configuration
- β Defining project metadata
- β
Language injection support (
injection-regex) - β Better editor integration
See TREE_SITTER_JSON.md for details.
The injection-regex field allows EmmyLuaDoc grammar to be injected into Lua file comments:
-- In Lua files, these comments will automatically use EmmyLuaDoc syntax highlighting
---@class Person β Automatically detected and applies emmyluadoc grammar
---@field name string
---@field age numberThis requires configuring appropriate injection rules in the Lua grammar's injections.scm. See examples/lua_injections_example.scm.
---@class Person
---@field name string
---@field age number
---@param name string
---@param age number
---@return Person
function createPerson(name, age)
end---@type string
--- | number
--- | boolean
--- | nil
local value
---@param id string
--- | number
---@return Person
--- | nil
function findPerson(id)
end--- Triple dash (recommended)
---@class Person
-- Double dash
--@class Student
- Single dash
-@class Teacher
# No prefix (still supported)
@class Admin---@class Person β Parsed as annotation (starts with ---)
@class Student β Parsed as annotation (starts with @)
Some text @class β Parsed as text_line (@ not at line start)
Random comment β Parsed as text_line (doesn't start with - or @)This ensures that only actual annotations are highlighted, avoiding false positives in regular text that happens to contain @class or similar keywords.
@class- define a class@field- define a field@type- define a variable type@param- define a function parameter@return- define a return value@generic- define generic type parameters@vararg- define variadic parameters@overload- define function overloads@deprecated- mark as deprecated@see- reference@alias- type alias@enum- enum definition@module- module definition@private/@protected/@public/@package- access modifiers@async- async function marker@cast- type cast@nodiscard- non-discardable return value@meta- metadata marker@version- version information@diagnostic- diagnostic control@operator- operator overload
npm installnpm run buildnpm test---@class Person
---@field name string
---@field age number---@param name string The person's name
---@param age number The person's age
---@return Person The newly created person object
function createPerson(name, age)
end---@generic T
---@param list T[]
---@return T
function first(list)
end---@overload fun(name: string): Person
---@overload fun(name: string, age: number): Person
function createPerson(...)
end- Edit the
grammar.jsfile to update grammar rules - Run
tree-sitter generateto generate the parser - Run
tree-sitter testto run tests
MIT