Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-elixir"
description = "Elixir grammar for the tree-sitter parsing library"
version = "0.2.0"
version = "0.3.0"
keywords = ["incremental", "parsing", "elixir"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/elixir-lang/tree-sitter-elixir"
Expand All @@ -20,7 +20,10 @@ include = [
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = ">=0.21.0"
tree-sitter-language = "0.1.0"

[dev-dependencies]
tree-sitter = "0.23.0"

[build-dependencies]
cc = "1.0"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 0.2.0
VERSION := 0.3.0

# Repository
SRC_DIR := src
Expand Down
4 changes: 2 additions & 2 deletions bindings/go/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package tree_sitter_elixir_test
import (
"testing"

tree_sitter "github.com/smacker/go-tree-sitter"
"github.com/tree-sitter/tree-sitter-elixir"
tree_sitter "github.com/tree-sitter/go-tree-sitter"
tree_sitter_elixir "github.com/tree-sitter/tree-sitter-elixir/bindings/go"
)

func TestCanLoadGrammar(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions bindings/go/go.mod

This file was deleted.

9 changes: 9 additions & 0 deletions bindings/node/binding_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="node" />

const assert = require("node:assert");
const { test } = require("node:test");

test("can load grammar", () => {
const parser = new (require("tree-sitter"))();
assert.doesNotThrow(() => parser.setLanguage(require(".")));
});
11 changes: 11 additions & 0 deletions bindings/python/tests/test_binding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from unittest import TestCase

import tree_sitter, tree_sitter_elixir


class TestLanguage(TestCase):
def test_can_load_grammar(self):
try:
tree_sitter.Language(tree_sitter_elixir.language())
except Exception:
self.fail("Error loading Elixir grammar")
4 changes: 2 additions & 2 deletions bindings/python/tree_sitter_elixir/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ typedef struct TSLanguage TSLanguage;

TSLanguage *tree_sitter_elixir(void);

static PyObject* _binding_language(PyObject *self, PyObject *args) {
return PyLong_FromVoidPtr(tree_sitter_elixir());
static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) {
return PyCapsule_New(tree_sitter_elixir(), "tree_sitter.Language", NULL);
}

static PyMethodDef methods[] = {
Expand Down
3 changes: 3 additions & 0 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ fn main() {
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
#[cfg(target_env = "msvc")]
c_config.flag("-utf-8");

let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
Expand Down
39 changes: 20 additions & 19 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
//! This crate provides elixir language support for the [tree-sitter][] parsing library.
//! This crate provides Elixir language support for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] function to add this language to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//!
//! ```
//! let code = "";
//! let code = r#"
//! "#;
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(tree_sitter_elixir::language()).expect("Error loading elixir grammar");
//! let language = tree_sitter_elixir::LANGUAGE;
//! parser
//! .set_language(&language.into())
//! .expect("Error loading Elixir parser");
//! let tree = parser.parse(code, None).unwrap();
//! assert!(!tree.root_node().has_error());
//! ```
//!
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
//! [language func]: fn.language.html
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
//! [tree-sitter]: https://tree-sitter.github.io/
use tree_sitter::Language;
use tree_sitter_language::LanguageFn;

extern "C" {
fn tree_sitter_elixir() -> Language;
fn tree_sitter_elixir() -> *const ();
}

/// Get the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_elixir() }
}
/// The tree-sitter [`LanguageFn`] for this grammar.
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_elixir) };

/// The content of the [`node-types.json`][] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");

// Uncomment these to include any queries that this grammar contains
// NOTE: uncomment these to include any queries that this grammar contains:

pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I uncommented this because the injections file existed already in the repo.

// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");

#[cfg(test)]
mod tests {
#[test]
fn test_can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.expect("Error loading elixir language");
.set_language(&super::LANGUAGE.into())
.expect("Error loading Elixir parser");
}
}
12 changes: 12 additions & 0 deletions bindings/swift/TreeSitterElixirTests/TreeSitterElixirTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import XCTest
import SwiftTreeSitter
import TreeSitterElixir

final class TreeSitterElixirTests: XCTestCase {
func testCanLoadGrammar() throws {
let parser = Parser()
let language = Language(language: tree_sitter_elixir())
XCTAssertNoThrow(try parser.setLanguage(language),
"Error loading Elixir grammar")
}
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/tree-sitter/tree-sitter-elixir

go 1.23

require github.com/tree-sitter/go-tree-sitter v0.23
22 changes: 13 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"name": "tree-sitter-elixir",
"version": "0.2.0",
"version": "0.3.0",
"description": "Elixir grammar for the tree-sitter parsing library",
"main": "bindings/node",
"types": "bindings/node",
"keywords": ["parser", "lexer", "elixir", "tree-sitter"],
"keywords": [
"parser",
"lexer",
"elixir",
"tree-sitter"
],
"files": [
"grammar.js",
"binding.gyp",
Expand All @@ -19,7 +24,8 @@
"url": "https://github.com/elixir-lang/tree-sitter-elixir.git"
},
"scripts": {
"test": "tree-sitter test",
"build": "npx tree-sitter-cli generate --no-bindings",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to make the scripts less reliant on the system state. Running npx tree-sitter-cli instead of tree-sitter will ensure the version specified in the devDependencies is used.

"test": "npx tree-sitter-cli test",
"format": "prettier --trailing-comma es5 --write grammar.js && clang-format -i src/scanner.c",
"format-check": "prettier --trailing-comma es5 --check grammar.js && cat src/scanner.c | clang-format src/scanner.c | diff src/scanner.c -",
"install": "node-gyp-build",
Expand All @@ -32,7 +38,7 @@
"devDependencies": {
"clang-format": "^1.8.0",
"prettier": "^2.3.2",
"tree-sitter-cli": "^0.22.2",
"tree-sitter-cli": "^0.23.0",
"prebuildify": "^6.0.0"
},
"peerDependencies": {
Expand Down
Loading