TreeSitter.jl

Julia bindings for tree-sitter.
Author MichaelHatherly
Popularity
18 Stars
Updated Last
4 Months Ago
Started In
July 2020

TreeSitter

Julia bindings for tree-sitter — "An incremental parsing system for programming tools."

Build Status Codecov

Installation

This package is not registered yet and so can be installed using:

pkg> add https://github.com/MichaelHatherly/TreeSitter.jl

Usage

julia> using TreeSitter

julia> c = Parser(:c)
Parser(Language(:c))

julia> ast = parse(c, "int x;")
(translation_unit (declaration type: (primitive_type) declarator: (identifier)))

julia> json = Parser(:json)
Parser(Language(:json))

julia> ast = parse(json, "{1: [2]}")
(document (object (pair key: (number) value: (array (number)))))

julia> traverse(ast) do node, enter
           if enter
               @show node
           end
       end
node = (document (object (pair key: (number) value: (array (number)))))
node = (object (pair key: (number) value: (array (number))))
node = ("{")
node = (pair key: (number) value: (array (number)))
node = (number)
node = (":")
node = (array (number))
node = ("[")
node = (number)
node = ("]")
node = ("}")

julia> julia = Parser(:julia)
Parser(Language(:julia))

julia> ast = parse(julia, "f(x)")
(source_file (call_expression (identifier) (argument_list (identifier))))

julia> traverse(ast, named_children) do node, enter
           if !enter
               @show node
           end
       end
node = (identifier)
node = (identifier)
node = (argument_list (identifier))
node = (call_expression (identifier) (argument_list (identifier)))
node = (source_file (call_expression (identifier) (argument_list (identifier))))

Languages

  • :bash
  • :c
  • :cpp
  • :go
  • :html
  • :java
  • :javascript
  • :json
  • :julia
  • :php
  • :python
  • :ruby
  • :rust
  • :typescript

Additional languages can be added by writing new jll packages to wrap the upstream parsers: see Yggdrasil for details.

Required Packages

Used By Packages

No packages found.