• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    C
  • License
    MIT License
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A TreeSitter parser for the Typst File Format

A tree-sitter parser for the typst file format

This language is soooo hard to parseโ€ฆ whitespace, parenthesizes for everything, and Unicode :(

DONE:

  • [O] Code mode: # to enter code mode

    • any literal: 1, "hi", true, false, none, auto
    • raw and labels are literals
    • code block: { x = 1 }
    • content block: [ hello ]
    • parenthesized expression: (1 + 2)
    • array: (1, 2, 3)
    • dictionary: (a: "hi", b: 2)
    • unary operator: -x
    • binary operator: x + y
    • assignment: x = 1
    • variable access: x
    • field access: x.y
    • method call: x.flatten()
    • named function: let f(x) = 2 * x
    • unnamed function: (x, y) => x + y
    • function call: min(x, y)
    • let binding: let x = 1
    • set rule: set text(14pt)
    • set-if rule: set text(..) if ..
    • show-set rule: show par: set block(..)
    • show rule with function: show par: set block(..)
    • show-everything rule: show: set block(..)
    • conditional: if x < 0 {0} else {x}
    • for loop: for x in [1, 2, 3]
    • while loop: while x < 10 {}
    • loop control flow: break, continue
    • return from function: return x
    • include module: include "bar.typ"
    • import module: import "bar.typ"
    • import items from module: import "bar.typ": a, b, c
    • comment: // hi or /* hi */.
  • Math mode

    • Everything :)
  • Markup mode

    • Whitespace (Unicode)
    • paragraph break
    • text (Unicode)
    • emphasis
      • strong
      • italic
    • label
    • reference
    • raw text
      • inline
      • block
    • link
    • heading
    • bullet list
    • numbered list
    • term list
    • math
    • line break
    • smart quote
      • single quote
      • double quote
    • symbol shorthand
    • code expression
    • character escape
    • comment.

Outdated specification comes from: https://www.user.tu-berlin.de/laurmaedje/programmable-markup-language-for-typesetting.pdf

I'll be using the textmate grammar as inspiration: https://github.com/typst/typst/blob/main/tools/support/typst.tmLanguage.json

For myself, I'll paste it here:


Typst Grammar

Below is an approximate EBNF grammar for the Typst language that is based on our handwritten recursive descent parser. We follow these conventions:

โ€“ Production names are all lowercase.
โ€“ Text enclosed in single (') or double quotes (") defines a terminal.
โ€“ * for an arbitrary number of repetitions.
โ€“ + for at least one repetition.
โ€“ ? for zero or one repetitions.
โ€“ ! to negate a simple (character-class-like) production.
โ€“ . to match an arbitrary character.
โ€“ a - b to match anything that matches a but not b.
โ€“ unicode(Property) to match any character that has the given unicode property.

Note that comments and spaces are allowed almost everywhere within code constructs. For readability, this is omitted in the grammar. Moreover, the grammar omits the indentation rules for lists, as EBNF cannot handle context-sensitive constructs.

// Markup.
markup ::= markup-node*
markup-node ::=
space | nbsp | shy | endash | emdash | ellipsis | quote | 
strong | emph | raw | link | math | heading | list | enum | desc

// Markup nodes.
nbsp ::= '~'
shy ::= '-?'
endash ::= '--'
emdash = '---'
ellipsis ::= '...'
quote ::= "'" | '"'
strong ::= '*' markup '*'
raw ::= '`' (raw | .*) '`'
link ::= 'http' 's'? '://' (!space)*
math ::= ('$' .* '$') | ('$[' .* ']$')
heading ::= '='+ space markup
list ::= '-' space markup
enum ::= digit* '.' space markup
desc ::= '/' space markup ':' space markup

More Repositories

1

dotfiles

My Rice Setup
Shell
789
star
2

typst.nvim

WIP. Goals: Treesitter highlighting, snippets, and a smooth intergration with neovim.
Rust
106
star
3

links-i-find-interesting

A mirror for all the links I post on my personal discord server
17
star
4

render.nvim

I'm going to try to be working on the anticonceal feature of nvim for image support for typst. This is going to a proof of concept so I can properly figure out what I need to do to get everything working as I want it too.
Rust
6
star
5

taolp

The class website for "The Art Of Lazy Programming". Hopefully, I am able to serve it under the official rice.edu domain.
6
star
6

seniormars.github.io

Blogs...
HTML
5
star
7

pokemon-csv

A forked of a https://gist.github.com/armgilles/194bcff35001e7eb53a2a8b441e8b2c6, but improved.
Python
5
star
8

typst-raytracer

WIP... it's something i'm building to test my treesitter parser...
4
star
9

rvim

my init.lua in mostly rust. cuz why not
Rust
3
star
10

SeniorMars

3
star
11

EandF

2nd to last project for softdev first semester
HTML
2
star
12

risp

My implmentation of a lisp interperator but in rust
Rust
2
star
13

gartus

gartus
Rust
2
star
14

blazekirk

A blazing fast program made in rust that prints out "kirk" โšก๏ธโšก๏ธโšก๏ธโšก๏ธโšก๏ธโšก๏ธโšก๏ธ ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ super fastt
Rust
2
star
15

rush

Shell written in c
C
1
star
16

coc-typst

A WIP extension for coc.nvim for the WIP typst language server. That's a lot of WIPs...
TypeScript
1
star
17

week1-rust

Learning rust for real
Rust
1
star
18

WhatVimCanDoForYou

WIP Talk
1
star
19

rust-presentation

Rust
1
star