Skip to content

Commit

Permalink
Migrate to new tree-sitter.json format
Browse files Browse the repository at this point in the history
  • Loading branch information
afroozeh committed Oct 9, 2024
1 parent 2cc959f commit 9ec0def
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 11 deletions.
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:
13 changes: 2 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,5 @@
"devDependencies": {
"tree-sitter-cli": "^0.23.0",
"prebuildify": "^6.0.0"
},
"tree-sitter": [
{
"scope": "source.kotlin",
"file-types": [
"kt",
"kts"
]
}
]
}
}
}
35 changes: 35 additions & 0 deletions tree-sitter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"grammars": [
{
"name": "kotlin",
"camelcase": "Kotlin",
"scope": "source.kotlin",
"path": ".",
"file-types": [
"kt",
"kts"
]
}
],
"metadata": {
"version": "0.3.9",
"license": "MIT",
"description": "Tree-sitter grammar for Kotlin",
"authors": [
{
"name": "fwcd"
}
],
"links": {
"repository": "git+https://github.com/fwcd/tree-sitter-kotlin.git"
}
},
"bindings": {
"c": true,
"go": true,
"node": true,
"python": true,
"rust": true,
"swift": true
}
}

0 comments on commit 9ec0def

Please sign in to comment.