0.2.0-alpha.38 • Published 3 years ago

tree-sitter-tony v0.2.0-alpha.38

Weekly downloads
291
License
MIT
Repository
github
Last release
3 years ago

tree-sitter-tony

This repository is home to the parser and Tree-sitter grammar of the Tony programming language. It comes with automatically generated TypeScript type declarations.

Tony is a functional, strongly typed, high level, general purpose programming language. Tony employs refinement types, allowing its type checker to catch domain-specific bugs at compile time.

Other core components of Tony can be found through the following links:

Note of caution: New features of Tony are discussed in the repository housing the language spec. This repository merely implements the spec.

Examples for valid syntax can be found in test/corpus.

Philosophy

This project uses Tree-sitter as a parsing library. As such this repository includes a Tree-sitter grammar (at grammar.js). This grammar may be used for any purpose beyond simply parsing the code to compile it. These uses include syntax highlighting, deep integration with code editors and more.

Installation

Prerequisites: Building this parser will require the following tools:

  • Node.js (the version is specified by the engines entry in package.json); and
  • the node-gyp build tool.

Alternatively to building the parser yourself you can use prebuilt versions. If available, a prebuilt version will be used automatically when you install this project.

The tree-sitter-tony package is published on NPM.

You may install it

  • using Yarn (preferred)

    $ yarn add tree-sitter-tony
  • or using NPM

    $ npm install tree-sitter-tony
  • or from source

    $ git clone git@github.com:tony-lang/tree-sitter-tony.git
    $ yarn setup

Usage

The generated parser is in C. There exist bindings to use this parser with a huge variety of programming languages. Below you can find a couple of options of using the parser.

Some may require you to set up a development environment.

CLI (development)

To parse a file and emit a syntax tree run

$ yarn parse-tony file.tn

where file.tn is the relative path to the file you want to parse.

For a simple hello world use

io->print('hello world')

Use yarn parse-dtn file.dtn to parse a module declaration file.

TypeScript / JavaScript

Import the parser with

import Parser from 'tree-sitter'
import TreeSitterTony, { Tree } from 'tree-sitter-tony/tony'

Then you are able to create an instance of the parser as follows:

const parser = new Parser()
parser.setLanguage(TreeSitterTony)

Now you can parse any string into an abstract syntax tree:

const sourceCode: string = await readFile(file)

const tree = parser.parse(sourceCode) as Tree

tree and every child node including their properties are strongly typed.

Import from 'tree-sitter-tony/dtn' instead of 'tree-sitter-tony/tony' to load the declaration file parser.

Development

To start development you first have to fork this repository and locally clone your fork.

Then setup the project locally by running:

$ yarn setup

grammar.js houses the specification of the parser. You can generate a new parser from this specification by running:

$ yarn generate

You can generate type declarations by running:

$ yarn types

Testing

To run the tests:

$ yarn test

To let TypeScript check types:

$ yarn tsc

The linter can be run as follows:

$ yarn lint

We use Prettier for automated code formatting:

$ yarn prettier

You can find all commands run by the CI workflow in .github/workflows/ci.yml.

Contributing

We warmly welcome everyone who is intersted in contributing. Please reference our contributing guidelines and our Code of Conduct.

Releases

Here you can find details on all past releases. Unreleased breaking changes that are on the current master can be found here.

Tony follows Semantic Versioning 2.0 as defined at http://semver.org. Reference our security policy.

Publishing

  1. Review breaking changes and deprecations in CHANGELOG.md.
  2. Change the version in package.json.
  3. Reset CHANGELOG.md.
  4. Create a pull request to merge the changes into master.
  5. After the pull request was merged, create a new release listing the breaking changes, deprecations and commits on master since the last release.
  6. The release workflow will publish the package to NPM and GPR.
  7. The prebuild workflow will upload prebuilt packages to GitHub.
0.2.0-alpha.38

3 years ago

0.2.0-alpha.37

3 years ago

0.2.0-alpha.36

3 years ago

0.2.0-alpha.35

3 years ago

0.2.0-alpha.34

3 years ago

0.2.0-alpha.33

3 years ago

0.2.0-alpha.32

3 years ago

0.2.0-alpha.31

3 years ago

0.2.0-alpha.30

3 years ago

0.2.0-alpha.29

3 years ago

0.2.0-alpha.28

3 years ago

0.2.0-alpha.27

3 years ago

0.2.0-alpha.26

3 years ago

0.2.0-alpha.25

3 years ago

0.2.0-alpha.24

3 years ago

0.2.0-alpha.23

3 years ago

0.2.0-alpha.22

3 years ago

0.2.0-alpha.21

3 years ago

0.2.0-alpha.20

3 years ago

0.2.0-alpha.19

3 years ago

0.2.0-alpha.18

3 years ago

0.2.0-alpha.17

3 years ago

0.2.0-alpha.16

3 years ago

0.2.0-alpha.15

3 years ago

0.2.0-alpha.14

4 years ago

0.2.0-alpha.12

4 years ago

0.2.0-alpha.11

4 years ago

0.2.0-alpha.10

4 years ago

0.2.0-alpha.9

4 years ago

0.2.0-alpha.8

4 years ago

0.2.0-alpha.7

4 years ago

0.2.0-alpha.6

4 years ago

0.2.0-alpha.5

4 years ago

0.2.0-alpha.4

4 years ago

0.2.0-alpha.3

4 years ago

0.2.0-alpha.2

4 years ago

0.2.0-alpha.1

4 years ago

0.2.0-alpha

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago