npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tree-sitter-supercollider

v0.2.2

Published

Tree sitter parser for the SuperCollider programming language

Downloads

1

Readme

tree-sitter-supercollider

SuperCollider grammar for tree-sitter.

SuperCollider is a programming language for sound. Tree-sitter is a really smart code parser.

This project defines a grammar (the "rules" of the language) for SuperCollider in a way that allows tree-sitter to do fast and very precise analysis of the code, while it is being typed.

Among other things, this allows for a very high level of precision in syntax highlighting (see below) and analyzing/traversing source code with equal precision.

Status: Experimental but almost fully implemented

Most of sclang is now implemented, except for a few of the more esoteric things (see issues/todolist) and generally works well. Yet, it is still early days and so expect bugs and changes to happen.

Features

  • Scoped syntax highlighting (tree-sitter can tell the difference between local variables, environment variables and arguments inside of code blocks / functions)
  • Very precise error messages (if a node fails, tree-sitter can tell pretty easily where it failed and why - for example if you are missing a semi colon in the middle of a function)
  • Editor agnostic - tree-sitter grammars can be implemented in any editor via tree-sitter's language bindings

Showcase:

Syntax highlighting

Syntax highlighting a supercollider document in the terminal using the command tree-sitter highlight <somedocument>.scd:

screenshot of grammar in action2

Get table of contents for all definitions using nvim-treesitter-refactor and navigate the document using those:

definitions

Rename all instances of a variable using nvim-treesitter-refactor:

smart rename

Using nvim-treesitter's playground to get a live view of the parser tree while writing code:

playground

TODO:

Most of the language has been implemented in the grammar, except for some of the more esoteric parts of the language:

  • Single expressions with no semicolon in a file
  • Syntax shortcuts / esoteric stuff: http://doc.sccode.org/Reference/Syntax-Shortcuts.html
    • selector (method name) as a binary operator
    • trailing-block arguments
    • selectors for binary operators
    • list comprehensions
    • Ref using the ` shorthand
    • be able to parse (:1..) select: _.isPrime nextN: 10; properly
    • multiple assignment
    • special partial operator situation: (a: _);

Try it out

See node tree parsing in action

tree-sitter generate && tree-sitter parse example-file.scd

See highlighting in action

tree-sitter generate && tree-sitter highlight example-file.scd

Development

I welcome everyone to commit pull requests to fix up things, add features or help out. If you just experience an issue and don't feel like making a pull request, feel free to open an issue and we will hopefully solve it ASAP.

Overview

The source code is divided up like this:

  • grammar.js - This is where the syntax and grammar is defined.
  • test/corpus/ - All unit tests sit here as .txt files
  • queries/*.scm - Syntax highlighting, code folding and indentation
  • src/scanner.c - A C file defining external scanners for more complex matching tasks

Resources

Here are some helpful resources for developers who want to contribute:

Tree-sitter resources:

SuperCollider language resources:

There is no official spec for he SuperCollider language (hehe), but these links are somewhat helpful:

Testing

Ideally, all rules in the grammar should be accompanied by at least one unit test.

These are found in test/corpus and named <subject>.txt. See this part of the tree-sitter docs on how to create tests.

Run them like this:

tree-sitter generate && tree-sitter test

Before pushing a pull request, make sure that it passes all tests.

Trying with nvim-treesitter

Install nvim-treesitter to use this grammar with NeoVim and follow their instructions for installing grammars.

Install locally in nvim

For development purposes it may be helpful to install your supercollider grammar locally:

Add this to your nvim config (change path in url to that of the tree sitter supercollider repo on your system if it you've downloaded it somewhere):

-- tree-sitter-supercollider
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.supercollider = {
	install_info = {
		-- url = "~/code/tree-sitter-supercollider",
		url = "https://github.com/madskjeldgaard/tree-sitter-supercollider",
		files = {"src/parser.c"},
		maintainer = "@madskjeldgaard"
	},
	filetype = "supercollider", -- if filetype does not agrees with parser name
}