0.1.6 • Published 9 months ago

type-sitter v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

type-sitter

The Industrial Parser Generator. If you can write a JSON Schema for it, this can generate a parser for it.

Generates Tree-Sitter Grammars From TypeScript Definitions. Inspired By Rust-Sitter.

usage

  1. Write a base grammar that supports TypeScript primitives:
    any, array, null, number, object, string, bool.
// use API of GrammarBuilder to define a base grammar with placeholders.
// placeholders in the returned base grammar is resolved by type-sitter.
export const baseGrammar: ($$: GrammarBuilder) => string;
  1. Express your DSL that goes on top of your base grammar with types.
    export interface Grammar {
      // ... grammar definition using TypeScript typings
    }
  2. Use type-sitter to generate a Tree-Sitter grammar.
    # outputs grammar.js and grammar.json
    type-sitter -i grammar.ts
  3. Use tree-sitter to make a Tree-Sitter parser.
    # outputs the actual parser
    tree-sitter generate
  4. Optionally use grammar.js to further modify the parser and grammar.json to validate ASTs sent over the wire.

See caveats for limitations.
See type-sitter --help for more information.
See examples directory for sample DSLs.

caveats

  • Not all TypeScript features are supported. See quicktype for details.
  • Duplicated pairs with the same keys but different values do not error out.
  • Generated parsers do not replace a data validation layer. Those are mutex.
  • This project currently focuses on declarative DSLs vs imperative grammars.
0.1.6

9 months ago

0.1.5

9 months ago

0.1.4

9 months ago

0.1.3

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.0

9 months ago

0.0.1

10 months ago