Skip to content
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

Upgrade to treesitter 0.24.2 #154

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1d94ac9
Expose null_literal as a node (#3)
afroozeh Jun 11, 2024
2c3fe13
Make the 'else' part explicit in parse trees (#4)
afroozeh Jun 11, 2024
55d686e
Add fields for property_declaration (#5)
afroozeh Aug 19, 2024
1928f0d
Make block visible (#6)
afroozeh Aug 20, 2024
a77051b
Introduce a field for a function's modifiers (#7)
ketkarameya Aug 21, 2024
7d5dfa7
Add more fields to the grammar (#8)
afroozeh Aug 21, 2024
1dd80dc
Expose 'function_value_parameter' (#9)
afroozeh Aug 21, 2024
4c956ce
Add fields for class_parameters (#10)
afroozeh Aug 22, 2024
238f7ba
Fields for class like constructs (#11)
afroozeh Aug 24, 2024
bbdfa90
Upgrade ts to 0.23.0
kageiit Aug 27, 2024
324df87
Make class parameters visible (#12)
afroozeh Aug 27, 2024
42fb582
Merge upstream main (#13)
afroozeh Aug 29, 2024
5c60d37
Upgreade to tree-sitter 0.23.0 and use --show-fields in tests (#15)
afroozeh Sep 15, 2024
0418b87
Make the 'else' part explicit in parse trees (#16)
afroozeh Sep 16, 2024
19426b5
Fix the priority of arguments (#17)
afroozeh Sep 16, 2024
f5e07ea
Add repos for parsing examples (#18)
afroozeh Sep 17, 2024
8104673
Add more fields (#19)
afroozeh Sep 17, 2024
8a1e542
Fields for lambda (#20)
afroozeh Sep 18, 2024
df8e4bc
Add fields to grammar (#21)
afroozeh Sep 25, 2024
32e9f5d
Support functional interfaces (#22)
afroozeh Sep 26, 2024
cfb5123
Update import rule (#23)
afroozeh Sep 28, 2024
d2cb0da
Add fields for prefix and postfix expressions (#25)
afroozeh Oct 6, 2024
eb00f7e
Add modifier fields
afroozeh Oct 8, 2024
2cc959f
Add fields for value_arguments
afroozeh Oct 9, 2024
9ec0def
Migrate to new tree-sitter.json format
afroozeh Oct 9, 2024
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
31 changes: 19 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,37 @@ on:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up tree-sitter
uses: tree-sitter/setup-action/cli@v1
- name: Generate parser
run: npm run generate
run: tree-sitter generate
- name: Verify that generated parser matches the repository
run: |
diff=`git diff HEAD -- src`
echo "$diff"
test -z "$diff"
- name: Output parser size
run: du -sh src/* | sort -h
- name: Run tests
run: npm test
run: tree-sitter test --show-fields
- name: Set up examples
run: |-
git clone https://github.com/square/okhttp.git examples/okhttp --single-branch --depth=1 --filter=blob:none
git clone https://github.com/ktorio/ktor.git examples/ktor --single-branch --depth=1 --filter=blob:none
git clone https://github.com/square/leakcanary.git examples/leakcanary --single-branch --depth=1 --filter=blob:none
git clone https://github.com/JetBrains/compose-multiplatform.git examples/compose-multiplatform --single-branch --depth=1 --filter=blob:none
git clone https://github.com/Kotlin/kotlinx.coroutines.git examples/kotlinx.coroutines --single-branch --depth=1 --filter=blob:none
- name: Parse examples
id: examples
continue-on-error: true
uses: tree-sitter/parse-action@v4
with:
files: examples/**/*.kt
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Build and test crate
Expand Down
60 changes: 60 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.13)

project(tree-sitter-kotlin
VERSION "0.3.9"
DESCRIPTION "Tree-sitter grammar for Kotlin"
HOMEPAGE_URL "git+https://github.com/fwcd/tree-sitter-kotlin.git"
LANGUAGES C)

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the library allocator" OFF)

set(TREE_SITTER_ABI_VERSION 14 CACHE STRING "Tree-sitter ABI version")
if(NOT ${TREE_SITTER_ABI_VERSION} MATCHES "^[0-9]+$")
unset(TREE_SITTER_ABI_VERSION CACHE)
message(FATAL_ERROR "TREE_SITTER_ABI_VERSION must be an integer")
endif()

find_program(TREE_SITTER_CLI tree-sitter DOC "Tree-sitter CLI")

add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json"
COMMAND "${TREE_SITTER_CLI}" generate src/grammar.json
--abi=${TREE_SITTER_ABI_VERSION}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Generating parser.c")

add_library(tree-sitter-kotlin src/parser.c)
if(EXISTS src/scanner.c)
target_sources(tree-sitter-kotlin PRIVATE src/scanner.c)
endif()
target_include_directories(tree-sitter-kotlin PRIVATE src)

target_compile_definitions(tree-sitter-kotlin PRIVATE
$<$<BOOL:${TREE_SITTER_REUSE_ALLOCATOR}>:TREE_SITTER_REUSE_ALLOCATOR>
$<$<CONFIG:Debug>:TREE_SITTER_DEBUG>)

set_target_properties(tree-sitter-kotlin
PROPERTIES
C_STANDARD 11
POSITION_INDEPENDENT_CODE ON
SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}"
DEFINE_SYMBOL "")

configure_file(bindings/c/tree-sitter-kotlin.pc.in
"${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-kotlin.pc" @ONLY)

include(GNUInstallDirs)

install(FILES bindings/c/tree-sitter-kotlin.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-kotlin.pc"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig")
install(TARGETS tree-sitter-kotlin
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")

add_custom_target(test "${TREE_SITTER_CLI}" test
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "tree-sitter test")

# vim:ft=cmake:
34 changes: 26 additions & 8 deletions Cargo.lock

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

12 changes: 5 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ license = "MIT"
readme = "bindings/rust/README.md"

build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"grammar.js",
"queries/*",
"src/*",
]
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]

[lib]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = ">= 0.21, < 0.23"
tree-sitter-language = "0.1.0"

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

[build-dependencies]
cc = "1.0"
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_kotlin_test
import (
"testing"

tree_sitter "github.com/smacker/go-tree-sitter"
"github.com/tree-sitter/tree-sitter-kotlin"
tree_sitter "github.com/tree-sitter/go-tree-sitter"
tree_sitter_kotlin "github.com/tree-sitter/tree-sitter-kotlin/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_kotlin


class TestLanguage(TestCase):
def test_can_load_grammar(self):
try:
tree_sitter.Language(tree_sitter_kotlin.language())
except Exception:
self.fail("Error loading Kotlin grammar")
4 changes: 2 additions & 2 deletions bindings/python/tree_sitter_kotlin/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_kotlin(void);

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

static PyMethodDef methods[] = {
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 kotlin language support for the [tree-sitter][] parsing library.
//! This crate provides Kotlin 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_kotlin::language()).expect("Error loading kotlin grammar");
//! let language = tree_sitter_kotlin::LANGUAGE;
//! parser
//! .set_language(&language.into())
//! .expect("Error loading Kotlin 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_kotlin() -> Language;
fn tree_sitter_kotlin() -> *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_kotlin() }
}
/// The tree-sitter [`LanguageFn`] for this grammar.
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_kotlin) };

/// 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 kotlin language");
.set_language(&super::LANGUAGE.into())
.expect("Error loading Kotlin parser");
}
}
12 changes: 12 additions & 0 deletions bindings/swift/TreeSitterKotlinTests/TreeSitterKotlinTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import XCTest
import SwiftTreeSitter
import TreeSitterKotlin

final class TreeSitterKotlinTests: XCTestCase {
func testCanLoadGrammar() throws {
let parser = Parser()
let language = Language(language: tree_sitter_kotlin())
XCTAssertNoThrow(try parser.setLanguage(language),
"Error loading Kotlin 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-kotlin

go 1.23

require github.com/tree-sitter/go-tree-sitter v0.23
Loading