Coder Social home page Coder Social logo

erinvanderveen / tree-sitter-typst-2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from seniormars/tree-sitter-typst

0.0 2.0 0.0 1.46 MB

A TreeSitter parser for the Typst File Format

License: MIT License

JavaScript 0.21% C++ 0.01% Python 0.01% C 99.74% Rust 0.03% Nix 0.01% Just 0.01%

tree-sitter-typst-2's Introduction

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

tree-sitter-typst-2's People

Contributors

seniormars avatar inetbowser avatar

Watchers

James Cloos avatar  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.