-
Notifications
You must be signed in to change notification settings - Fork 27
Update to tree-sitter 0.23 #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
This file was deleted.
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("."))); | ||
}); |
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") |
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"); | ||
// 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"); | ||
} | ||
} |
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") | ||
} | ||
} |
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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", | ||
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
"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", | ||
|
@@ -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": { | ||
|
There was a problem hiding this comment.
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.