Skip to content

A tree-sitter grammar for the typst typesetting language with a focus on correctness

License

Notifications You must be signed in to change notification settings

frozolotl/tree-sitter-typst

Repository files navigation

tree-sitter-typst

A tree-sitter grammar for the typst typesetting language with a focus on correctness.

Goals

  • This grammar will be kept as close as possible to the official parser. Visual inaccuracies should be considered a bug. It is however not a goal to produce the exact same syntax trees.
  • Everything should be tested.
  • I try to keep the grammar up-to-date. The future will show if I manage to keep that promise.

Missing Features

  • Code
  • Lists
  • Enums
  • Terms

Usage

Helix

First, clone this repository to a path to your liking.

Append the following configuration to your ~/.config/helix/languages.toml or %AppData%\helix\config.toml. Make sure you have replaced the path on the last line with the correct one.

[[language]]
name = "typst"
scope = "source.typst"
injection-regex = "^typ(st)?$"
file-types = ["typ"]
comment-token = "//"
indent = { tab-width = 2, unit = "  " }
roots = ["typst.toml"]

[language.auto-pairs]
'(' = ')'
'{' = '}'
'[' = ']'
'"' = '"'
'`' = '`'
'$' = '$'

[[grammar]]
name = "typst"
source = { path = "<path to tree-sitter-typst>" }

Now, symlink your query files. Alternatively, you can copy them to the correct folder, but that would make updating the grammar more difficult.

$ mkdir -p ~/.config/helix/runtime/queries/
$ ln -s <path to tree-sitter-typst>/queries/ ~/.config/helix/runtime/queries/typst

Run the following commands to fetch and build the grammar:

$ hx --grammar fetch
$ hx --grammar build

About

A tree-sitter grammar for the typst typesetting language with a focus on correctness

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages