This is a Tree-sitter grammar for the Ink interactive fiction scripting language. It supports all syntax up to version 1.2.0.
showcase.webm
See the queries/editors directory. If your editor is supported,
the corresponding subfolder should contain everything you need.
Note
If you'd like to see your editor supported, feel free to open a PR.
-
Vim
-
Neovim
-
Emacs
-
Helix
Put
languages.tomland the*.scmfiles in your Helix user config (e.g.~/.config/helix/).For details see the Helix guides.
-
VSCode
-
[… your editor here …]
Inkle themselves provide syntax files for Sublime 3, but tree-sitter is more powerful.
In general, tree-sitter allows for not just highlighting, but also source code navigation, indenting, etc. For example, Helix uses tree-sitter to quickly select functions, comments, tests, …, based on syntax/semantics.
Knots, Stitches, Choices, and Gathers are all properly nested, so you can navigate ink “semantically”. The example video above showcases this.
This grammar allows distinguishing between an expression in conditional text, and similar-looking normal text in alternatives:
This grammar makes the difference visible:
Standard textmate grammar treats both cases as the same thing.
It highlights the part before the : as an expression, although it isn't one:
Details
The difference is subtle, so here's a "diagram" to explain the difference:
// Conditional text:
{blofeld and old: I saw that old git,|Dunno,} I said.
/* ^^^ `and` is an operator, therefore
|-------------| <- all this is an expression
|-------------------------------------------| <- and this is conditional text */
// Alternative text:
{blofeld is old: and that's a fact,|I already told you about his age,} I said.
/* ^^ `is` is *not* an operator, therefore
|--------------------------------| <- all this is just text
|--------------------------------------------------------------------| <- and this is a _sequence_ (a type of alternative text) */Ink supports code evaluation inside of tags and string (to create them dynamically based on game state). This grammar supports this. So the following ink is fully highlighted:
while this is how the standard textmate grammar handles this:



