Write a Language Pack
Everything Aember knows about a language comes from a language pack: which files are in it, how to highlight them, which language server to run, how to build and test a project, and which package manager it uses. Aember’s own languages are packs too. Anyone can write one, for a language Aember doesn’t know yet or to do more with one it does.
A pack is written in Swift with AemberLanguageKit, BitArts’ SDK for packs. It is free and open source under the MIT license. Its README is the specification: this page is the overview, and links to it for the details.
What a Pack Can Do
A pack gives Aember any of these. Only the first is required.
- A language: which files are in it, by extension, file name, or the interpreter in a
#!line, and its comment characters, for Toggle Comment and the like. - Highlighting: the language’s tree-sitter grammar and highlight queries, compiled into the pack.
- Code graph: which of the grammar’s nodes are functions, types, methods, imports and so on, so Aember’s code graph, its dead code search and the agents connected to Aember can find them.
- Language servers: the command Aember runs for completions, diagnostics, go to definition and renaming, and what to tell the user when it isn’t installed.
- Build systems: how to recognize a project’s build, and the commands for Build and Test.
- Build output: how to read the language’s tools, so their errors and test results show in the build results and go to the right line.
- Package managers: reading a project’s dependencies, adding, removing and updating them, and checking for newer versions.
The packs that come with Aember (Swift, C Family, Rust, Python, TypeScript and JavaScript, and PHP) are in the SDK’s repository, as complete examples of each. The Objective-C pack is a small one, made from the SDK’s template in a repository of its own, as yours would be.
What You Need
- A Mac with macOS 14 or later, and Xcode 16 or later.
- Aember, to try the pack in. You don’t need a license: packs work in the free editor.
- A clone of AemberLanguageKit, for its template and scripts.
AemberLanguageKit.xcframework, from the SDK’s releases, or built withScripts/build-xcframework.sh.
Start from the Template
The SDK’s Template/ folder is a pack that defines one language, ready to rename:
- Copy
Template/to a folder of your own, named for your language (ZigPack), and putAemberLanguageKit.xcframeworkin it. - In
Info.plistandSources/ExamplePack.swift, changeexampleto your pack’s identifier (zig), and the name, author, file extensions and comment characters to your language’s. - Fill in what your pack gives. The template’s comments say where each part goes, and which included pack to copy it from.
The pack is a class that adopts LanguagePack. Its manifest says who made it and its version; everything else is optional:
final class ZigPack: LanguagePack {
let manifest = LanguagePackManifest(id: "zig", name: "Zig", version: LanguagePackVersion(1, 0, 0), summary: "Zig files and zls", author: "You")
var languages: [LanguageDefinition] { [...] }
var languageServers: [LanguageServerDefinition] { [...] }
var buildSystems: [BuildSystemProvider] { [...] }
var packageBackends: [PackageBackend.Type] { [...] }
}
See The pack and Languages in the specification.
Add Highlighting
A pack compiles its tree-sitter grammar in, so it stays one file. With a clone of the grammar’s repository, the SDK’s scripts copy its C sources into the pack’s Grammar/ folder, with its license and the commit they came from, and turn its queries into Swift:
AemberLanguageKit/Scripts/vendor-grammar.py ~/dev/ZigPack ~/src/tree-sitter-zig tree_sitter_zig
AemberLanguageKit/Scripts/embed-queries.py ~/dev/ZigPack/Queries ~/dev/ZigPack/Sources/PackQueries.swift
Then give them to the language, with the grammar’s ABI version (Aember reads 13 to 15):
grammar: Grammar(tree_sitter_zig, abiVersion: 15),
queries: PackQueries.queries
Aember colours highlights by tree-sitter’s usual capture names, such as keyword, type, function, string and comment. A grammar that builds on another, as Objective-C’s builds on C’s, can use that language’s queries first with inheritsQueriesFrom. See Grammar and queries for the capture names Aember colours, and Code graph for telling the code graph which nodes are declarations.
Build, Check and Try It
In your pack’s folder:
swift test
path/to/AemberLanguageKit/Scripts/build-pack.sh .
path/to/AemberLanguageKit/Scripts/check-pack.sh build/zig.aemberpack
build-pack.sh builds build/zig.aemberpack for Apple silicon and Intel Macs. check-pack.sh loads it as Aember does, and lists what it gives or says why Aember wouldn’t load it.
To try it, open the .aemberpack file, or drop it on Settings ▸ Languages in Aember. Aember asks before it runs a pack BitArts didn’t sign, then loads it, and the pack’s languages work in every window. When you build it again, install the new file over it and restart Aember: a pack’s code stays loaded until Aember quits.
Sign and Share It
A pack runs inside Aember, with access to the user’s files and the commands Aember runs, so Aember is careful about which packs it runs:
- Packs that come with Aember, and packs signed by BitArts, run at once.
- Any other pack waits until the user allows it. Aember names who signed it, or says it isn’t signed.
- Aember remembers the user’s answer for that build of the pack. A new build asks again.
- A pack whose signature is broken isn’t loaded.
Sign your pack with your Developer ID, so Aember can name you when it asks:
path/to/AemberLanguageKit/Scripts/build-pack.sh . --sign "Developer ID Application: Your Name (TEAMID)"
To share the pack, give people the .aemberpack file, from your website or your repository’s releases. They install it as you did. The catalog Aember installs and updates packs from, under Available in Settings, has BitArts’ packs only.
Versions
A pack says which version of the SDK it was built for, and Aember loads it only if its own SDK is compatible. The SDK is at 0.x for now, and may change between minor versions until 1.0, so a pack built for 0.2 needs an Aember with SDK 0.2. When Aember moves to a newer SDK, build the pack again with it. Aember lists a pack it won’t load, and says why.
From 1.0, a pack will keep working in later Aember releases of the same major version. See Versions.
The Specification
The AemberLanguageKit README has the rest:
- The pack file: what’s in a
.aemberpack, and its Info.plist keys. - Language servers: the command, finding it, and servers that need more.
- Build systems: detecting a project’s build, and its commands.
- Build output and reports: parsers for a tool’s console output, and readers for its report files.
- Package managers: dependencies, and changing them.
- Text: translating the words a pack shows.
- How Aember uses packs: where packs live, which wins when two give the same thing, and turning them off.
For how users install and manage packs, see Languages Settings in the help. Questions about the SDK go to the repository’s issues.