Code Monkey home page Code Monkey logo

tree-sitter-clojure's Introduction

tree-sitter-clojure

Status

tree-sitter-clojure has been:

Prerequisites

Unfortunately, the short of it is that it may be a bit complicated depending on what you want to do.

  • If you don't use any of the wasm-related functionality (e.g. previewing parse results in your web browser or you want to build a .wasm file for use in a plugin or extension), you probably just need:

    • an appropriate version of node (I've tested with various versions >= 12, 14) and
    • other typical development-related bits (e.g. git, appropriate c compiler, etc.)
  • If you want wasm-related functionality, you get to have fun figuring out which version of emsdk currently works with tree-sitter. At the time of this writing, this file indicates a version that might be appropriate. That may depend on precisely what the versions of other bits (e.g. tree-sitter-cli, web-tree-sitter, etc.) might be though, so if something doesn't work right away, you might consider trying different versions that have been recorded.

Note that there may be an upside to using emsdk though -- it may figure out and arrange for an appropriate version of node, making a separate installation of node unnecessary. I don't use such a setup on a day-to-day basis, but it did work for me at least once.

Fine Print

  • The instructions below assume emsdk has been installed, but emcc (tool that can be used to compile to wasm) is not necessarily on one's PATH. If an appropriate emcc is on one's PATH (e.g. emscripten installed via homebrew), the emsdk steps (e.g. source ~/src/emsdk/emsdk_env.sh) below may be ignored.

  • node-gyp (tool for compiling native addon modules for Node.js) may fail on machines upgraded to macos Catalina. This document may help cope with such a situation.

Initial Setup

Suppose typical development sources are stored under ~/src.

Short Version

# clone repository
cd ~/src
git clone https://github.com/sogaiu/tree-sitter-clojure
cd tree-sitter-clojure

# install tree-sitter-cli and dependencies, then build
npm ci

Long Version

# clone repository
cd ~/src
git clone https://github.com/sogaiu/tree-sitter-clojure
cd tree-sitter-clojure

# ensure tree-sitter-cli is avaliable as a dev dependency
npm install --save-dev --save-exact tree-sitter-cli

# create `src` and populate with tree-sitter `.c` goodness
npx tree-sitter generate

# populate `node_modules` with dependencies
npm install

# create `build` and populate appropriately
npx node-gyp configure

# create `build/Release` and build `tree_sitter_clojure_binding.node`
npx node-gyp rebuild

Grammar Development

Hack on grammar.

# edit grammar.js using some editor

# rebuild tree-sitter stuff
npx tree-sitter generate && \
npx node-gyp rebuild

Parse individual files.

# create and populate sample code file for parsing named `sample.clj`

# parse sample file
npx tree-sitter parse sample.clj

# if output has errors, figure out what's wrong

Interactively test in the browser (requires emsdk).

# prepare emsdk (specifically emcc) for building .wasm
source ~/src/emsdk/emsdk_env.sh

# build .wasm bits and invoke web-ui for interactive testing
npx tree-sitter build-wasm && \
npx tree-sitter web-ui

# in appropriate browser window, paste code in left pane

# examine results in right pane -- can even click on nodes

# if output has errors, figure out what's wrong

Measure Performance

# single measurement
npx tree-sitter parse --time sample.clj

# mutliple measurements with `multitime`
multitime -n10 -s1 npx tree-sitter parse --time --quiet sample.clj

Build .wasm

Assuming emsdk is installed appropriately under ~/src/emsdk.

# prepare emsdk (specifically emcc) for use
source ~/src/emsdk/emsdk_env.sh

# create `tree-sitter-clojure.wasm`
npx tree-sitter build-wasm

Resources

Acknowledgments

Please see the credits.

tree-sitter-clojure's People

Contributors

borkdude avatar sogaiu avatar wilfred avatar

Watchers

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