Skip to content

Repository files navigation

Tree-Sitter-Ink

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

Editor Support

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.toml and the *.scm files in your Helix user config (e.g. ~/.config/helix/).

    For details see the Helix guides.

  • VSCode

  • [… your editor here …]

Why?

Inkle themselves provide syntax files for Sublime 3, but tree-sitter is more powerful.

Semantic nesting of language elements

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.

Distinction between conditional text and alternative text

This grammar allows distinguishing between an expression in conditional text, and similar-looking normal text in alternatives:

This grammar makes the difference visible:

this grammar

Standard textmate grammar treats both cases as the same thing. It highlights the part before the : as an expression, although it isn't one:

standard textmate grammar

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) */

Highlight code inside tags an strings

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:

this grammar

while this is how the standard textmate grammar handles this:

standard textmate grammar

About

Tree-Sitter grammar for Inkle's Ink language

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages