Giter Site home page Giter Site logo

panekj / tree-sitter-typst Goto Github PK

View Code? Open in Web Editor NEW

This project forked from uben0/tree-sitter-typst

0.0 0.0 0.0 7.38 MB

Tree Sitter grammar for Typst

License: MIT License

JavaScript 0.27% C++ 0.21% Scheme 1.52% Python 0.04% C 97.86% Go 0.01% Rust 0.06% Swift 0.03% Makefile 0.01%

tree-sitter-typst's Introduction

A TreeSitter grammar for the Typst language

Typst official page https://typst.app

TreeSitter documentation page https://tree-sitter.github.io

Typst doesn't have yet an official TreeSitter grammar. This grammar is complete but may contains bug as it is very recent.

Get involved

Your help is welcome. You don't have to know anything about tree-sitter to help. We need you to find bugs!

Find a bug by using this grammar. If you find an incorrect highlighting of your Typst files, then you found a bug. You can open an issue or simply send me by mail the Typst code causing the bug. See below installation instructions for this grammar. Even if your not sure it is a bug, it doesn't hurt to repport it.

Any inconsistancy between this syntax and Typst's one is considered a bug. In Helix editor, the syntax tree of selected text can be displayed with :tree-sitter-subtree command.

Don't hesitate to contact me: [email protected]

The documentation of this implementation is available in DOC. Because parsing Typst is really tricky. It would also be great to have a competitor parser, to see if the other finds better ways, and for redunduncy, because as of today, only one person understand how this parser works (me), and if I'm out, this parser won't be maintained (I guess). If your interresting in implementing a competitor Typst tree-sitter parser, I'd be happy to help you.

TODO

  • Update 0.11
    • Hangul script doesn't form words
    • Context operator
    • No line comment inside block comment
  • More tests, objectif 1000, current 430
  • Installation
    • Helix
    • Emacs
    • NeoVim
  • Simplification
    • Implement a type 3/4 parser generator (work in progress)
    • Migrate all lexing to external scanner
    • Remove dependency on get_column

Features

  • Markup mode
  • Code mode
  • Math mode
  • Indentation
  • Foldable sections
  • Unicode characters

Installation

Having syntax highlighting is great but having syntax highlighting and the language server is even greater. If you have cargo installed (Rust's package manager), you can install Typst language server with the following command (you don't have to be in any particular directory):

cargo install --git https://github.com/nvarner/typst-lsp typst-lsp

Neovim

The https://github.com/nvim-treesitter/nvim-treesitter provides this grammar.

Emacs

Typst support for Emacs is available through the following package:

typst-ts-mode

(use-package typst-ts-mode
  :elpaca (:type git :host sourcehut :repo "meow_king/typst-ts-mode")
  :custom
  (typst-ts-mode-watch-options "--open"))

Helix

The next release of Helix will support Typst. Waiting until then, you can add support for Typst with the following instructions:

  1. Locate the configuration directory:
  • Global /usr/share/helix
  • Local ~/.config/helix
  1. Append the following configuration to the languages.toml file (create it if it doesn't exist).
[language-server.typst-lsp]
command = "typst-lsp"

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

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

[[grammar]]
name = "typst"
source.git = "https://github.com/uben0/tree-sitter-typst"
source.rev = "master"
  1. Copy the content of the queries directory (highlights.scm and injections.scm) inside your corresponding runtime/queries/typst directory. You should have the following structure:
config.toml
languages.toml
runtime
└── queries
    └── typst
        ├── highlights.scm
        └── injections.scm
  1. And finally execute (you don't have to be in any particular directory):
hx --grammar fetch
hx --grammar build

The fetch command will clone the git repository, and the build command will compile the grammar.

tree-sitter-typst's People

Contributors

uben0 avatar ziqi-yang avatar alexanderbrevig avatar nuke-web3 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.