diff --git a/bindingsPython/.jvm/src/main/resources/darwin-aarch64/libtree-sitter-python.dylib b/bindingsPython/.jvm/src/main/resources/darwin-aarch64/libtree-sitter-python.dylib index 5e42345..f036493 100755 Binary files a/bindingsPython/.jvm/src/main/resources/darwin-aarch64/libtree-sitter-python.dylib and b/bindingsPython/.jvm/src/main/resources/darwin-aarch64/libtree-sitter-python.dylib differ diff --git a/bindingsPython/.jvm/src/main/resources/darwin-x86-64/libtree-sitter-python.dylib b/bindingsPython/.jvm/src/main/resources/darwin-x86-64/libtree-sitter-python.dylib index d9dbc80..33fc09a 100755 Binary files a/bindingsPython/.jvm/src/main/resources/darwin-x86-64/libtree-sitter-python.dylib and b/bindingsPython/.jvm/src/main/resources/darwin-x86-64/libtree-sitter-python.dylib differ diff --git a/bindingsPython/.jvm/src/main/resources/linux-aarch64/libtree-sitter-python.so b/bindingsPython/.jvm/src/main/resources/linux-aarch64/libtree-sitter-python.so index d25d0b4..847f271 100755 Binary files a/bindingsPython/.jvm/src/main/resources/linux-aarch64/libtree-sitter-python.so and b/bindingsPython/.jvm/src/main/resources/linux-aarch64/libtree-sitter-python.so differ diff --git a/bindingsPython/.jvm/src/main/resources/linux-x86-64/libtree-sitter-python.so b/bindingsPython/.jvm/src/main/resources/linux-x86-64/libtree-sitter-python.so index b284dde..1485259 100755 Binary files a/bindingsPython/.jvm/src/main/resources/linux-x86-64/libtree-sitter-python.so and b/bindingsPython/.jvm/src/main/resources/linux-x86-64/libtree-sitter-python.so differ diff --git a/core/.jvm/src/main/resources/darwin-aarch64/libtree-sitter.dylib b/core/.jvm/src/main/resources/darwin-aarch64/libtree-sitter.dylib index 2061b74..ef8b9ab 100755 Binary files a/core/.jvm/src/main/resources/darwin-aarch64/libtree-sitter.dylib and b/core/.jvm/src/main/resources/darwin-aarch64/libtree-sitter.dylib differ diff --git a/core/.jvm/src/main/resources/darwin-x86-64/libtree-sitter.dylib b/core/.jvm/src/main/resources/darwin-x86-64/libtree-sitter.dylib index 65d95ae..81a4dc0 100755 Binary files a/core/.jvm/src/main/resources/darwin-x86-64/libtree-sitter.dylib and b/core/.jvm/src/main/resources/darwin-x86-64/libtree-sitter.dylib differ diff --git a/core/.jvm/src/main/resources/linux-aarch64/libtree-sitter.so b/core/.jvm/src/main/resources/linux-aarch64/libtree-sitter.so index 76c3b36..52f6290 100755 Binary files a/core/.jvm/src/main/resources/linux-aarch64/libtree-sitter.so and b/core/.jvm/src/main/resources/linux-aarch64/libtree-sitter.so differ diff --git a/core/.jvm/src/main/resources/linux-x86-64/libtree-sitter.so b/core/.jvm/src/main/resources/linux-x86-64/libtree-sitter.so index 4355fea..e2d8155 100755 Binary files a/core/.jvm/src/main/resources/linux-x86-64/libtree-sitter.so and b/core/.jvm/src/main/resources/linux-x86-64/libtree-sitter.so differ diff --git a/flake.nix b/flake.nix index 48b877d..2bf18f0 100644 --- a/flake.nix +++ b/flake.nix @@ -2,12 +2,13 @@ inputs.nixpkgs.url = "github:NixOS/nixpkgs"; inputs.flake-utils.url = "github:numtide/flake-utils"; - outputs = { nixpkgs, flake-utils, ... }: + outputs = { self, nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; in { - devShells.default = - pkgs.mkShell { packages = [ pkgs.sbt pkgs.tree-sitter ]; }; + devShells.default = pkgs.mkShell { + packages = [ pkgs.sbt pkgs.tree-sitter pkgs.nodejs ]; + }; packages.tree-sitter = pkgs.stdenv.mkDerivation { name = "tree-sitter"; @@ -42,5 +43,29 @@ cp libtree-sitter-python.so $out ''; }; + + packages.tree-sitter-funlang = pkgs.stdenv.mkDerivation { + name = "tree-sitter-funlang"; + src = ./tree-sitter-funlang; + buildInputs = [ pkgs.tree-sitter pkgs.nodejs ]; + buildPhase = '' + tree-sitter generate + cc src/parser.c -shared -o $out + ''; + dontInstall = true; + }; + packages.tree-sitter-funlang-all = pkgs.stdenv.mkDerivation { + name = "tree-sitter-funlang-all"; + src = ./tree-sitter-funlang; + dontBuild = true; + installPhase = '' + mkdir $out + cd $out + mkdir darwin-aarch64 && cp ${self.packages.aarch64-darwin.tree-sitter-funlang} darwin-aarch64/libtree-sitter-funlang.dylib + mkdir darwin-x86-64 && cp ${self.packages.x86_64-darwin.tree-sitter-funlang} darwin-x86-64/libtree-sitter-funlang.dylib + mkdir linux-aarch64 && cp ${self.packages.aarch64-linux.tree-sitter-funlang} linux-aarch64/libtree-sitter-funlang.so + mkdir linux-x86-64 && cp ${self.packages.x86_64-linux.tree-sitter-funlang} linux-x86-64/libtree-sitter-funlang.so + ''; + }; }); } diff --git a/modules/treesitter/src/main/resources/darwin-aarch64/libtree-sitter-funlang.dylib b/modules/treesitter/src/main/resources/darwin-aarch64/libtree-sitter-funlang.dylib new file mode 100755 index 0000000..43b9bf1 Binary files /dev/null and b/modules/treesitter/src/main/resources/darwin-aarch64/libtree-sitter-funlang.dylib differ diff --git a/modules/treesitter/src/main/resources/darwin-x86-64/libtree-sitter-funlang.dylib b/modules/treesitter/src/main/resources/darwin-x86-64/libtree-sitter-funlang.dylib new file mode 100755 index 0000000..6ec01c3 Binary files /dev/null and b/modules/treesitter/src/main/resources/darwin-x86-64/libtree-sitter-funlang.dylib differ diff --git a/modules/treesitter/src/main/resources/linux-aarch64/libtree-sitter-funlang.so b/modules/treesitter/src/main/resources/linux-aarch64/libtree-sitter-funlang.so new file mode 100755 index 0000000..b1cc478 Binary files /dev/null and b/modules/treesitter/src/main/resources/linux-aarch64/libtree-sitter-funlang.so differ diff --git a/modules/treesitter/src/main/resources/linux-x86-64/libtree-sitter-funlang.so b/modules/treesitter/src/main/resources/linux-x86-64/libtree-sitter-funlang.so new file mode 100755 index 0000000..3ee3c93 Binary files /dev/null and b/modules/treesitter/src/main/resources/linux-x86-64/libtree-sitter-funlang.so differ diff --git a/tree-sitter-funlang/.gitattributes b/tree-sitter-funlang/.gitattributes new file mode 100644 index 0000000..7e2cae0 --- /dev/null +++ b/tree-sitter-funlang/.gitattributes @@ -0,0 +1,37 @@ +* text=auto eol=lf + +# Generated source files +src/*.json linguist-generated +src/parser.c linguist-generated +src/tree_sitter/* linguist-generated + +# C bindings +bindings/c/* linguist-generated +CMakeLists.txt linguist-generated +Makefile linguist-generated + +# Rust bindings +bindings/rust/* linguist-generated +Cargo.toml linguist-generated +Cargo.lock linguist-generated + +# Node.js bindings +bindings/node/* linguist-generated +binding.gyp linguist-generated +package.json linguist-generated +package-lock.json linguist-generated + +# Python bindings +bindings/python/** linguist-generated +setup.py linguist-generated +pyproject.toml linguist-generated + +# Go bindings +bindings/go/* linguist-generated +go.mod linguist-generated +go.sum linguist-generated + +# Swift bindings +bindings/swift/** linguist-generated +Package.swift linguist-generated +Package.resolved linguist-generated diff --git a/tree-sitter-funlang/.gitignore b/tree-sitter-funlang/.gitignore new file mode 100644 index 0000000..49852b9 --- /dev/null +++ b/tree-sitter-funlang/.gitignore @@ -0,0 +1,56 @@ +# Rust artifacts +target/ + +# Node artifacts +build/ +prebuilds/ +node_modules/ + +# Swift artifacts +.build/ + +# Go artifacts +_obj/ + +# Python artifacts +.venv/ +dist/ +*.egg-info +*.whl + +# C artifacts +*.a +*.so +*.so.* +*.dylib +*.dll +*.pc + +# Example dirs +/examples/*/ + +# Grammar volatiles +*.wasm +*.obj +*.o + +# Archives +*.tar.gz +*.tgz +*.zip + +src/ + +.editorconfig +Cargo.toml +Makefile +Package.swift +binding.gyp +bindings/ +go.mod +package.json +pyproject.toml +setup.py + +a.out.js + diff --git a/tree-sitter-funlang/CMakeLists.txt b/tree-sitter-funlang/CMakeLists.txt new file mode 100644 index 0000000..914816f --- /dev/null +++ b/tree-sitter-funlang/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 3.13) + +project(tree-sitter-funlang + VERSION "0.1.0" + DESCRIPTION "Funlang grammar for tree-sitter" + HOMEPAGE_URL "https://github.com/polyvariant/treesitter4s" + 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-funlang src/parser.c) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c) + target_sources(tree-sitter-funlang PRIVATE src/scanner.c) +endif() +target_include_directories(tree-sitter-funlang PRIVATE src) + +target_compile_definitions(tree-sitter-funlang PRIVATE + $<$:TREE_SITTER_REUSE_ALLOCATOR> + $<$:TREE_SITTER_DEBUG>) + +set_target_properties(tree-sitter-funlang + PROPERTIES + C_STANDARD 11 + POSITION_INDEPENDENT_CODE ON + SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}" + DEFINE_SYMBOL "") + +configure_file(bindings/c/tree-sitter-funlang.pc.in + "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-funlang.pc" @ONLY) + +include(GNUInstallDirs) + +install(FILES bindings/c/tree-sitter-funlang.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-funlang.pc" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig") +install(TARGETS tree-sitter-funlang + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + +add_custom_target(ts-test "${TREE_SITTER_CLI}" test + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMENT "tree-sitter test") diff --git a/tree-sitter-funlang/grammar.js b/tree-sitter-funlang/grammar.js new file mode 100644 index 0000000..7fd94d6 --- /dev/null +++ b/tree-sitter-funlang/grammar.js @@ -0,0 +1,17 @@ +/** + * @file Funlang grammar for tree-sitter + * @author Jakub Kozłowski + * @license MIT + */ + +/// +// @ts-check + +module.exports = grammar({ + name: "funlang", + + rules: { + // TODO: add the actual grammar rules + source_file: $ => "hello" + } +}); diff --git a/tree-sitter-funlang/tree-sitter.json b/tree-sitter-funlang/tree-sitter.json new file mode 100644 index 0000000..e6aba28 --- /dev/null +++ b/tree-sitter-funlang/tree-sitter.json @@ -0,0 +1,36 @@ +{ + "grammars": [ + { + "name": "funlang", + "camelcase": "Funlang", + "scope": "source.funlang", + "file-types": [ + ".fl" + ], + "injection-regex": "^funlang$" + } + ], + "metadata": { + "version": "0.1.0", + "license": "MIT", + "description": "Funlang grammar for tree-sitter", + "authors": [ + { + "name": "Jakub Kozłowski", + "email": "kubukoz@gmail.com", + "url": "https://github.com/kubukoz" + } + ], + "links": { + "repository": "https://github.com/polyvariant/treesitter4s" + } + }, + "bindings": { + "c": true, + "go": true, + "node": true, + "python": true, + "rust": true, + "swift": true + } +} \ No newline at end of file diff --git a/update-libs.sh b/update-libs.sh index 7d04d15..fe085c4 100755 --- a/update-libs.sh +++ b/update-libs.sh @@ -44,3 +44,10 @@ mkdir -p bindingsPython/.jvm/src/main/resources/linux-x86-64 BINARY_PATH=$(nix build .#packages.x86_64-linux.tree-sitter-python --no-link --print-out-paths --print-build-logs) cp $BINARY_PATH bindingsPython/.jvm/src/main/resources/linux-x86-64/libtree-sitter-python.so chmod 755 bindingsPython/.jvm/src/main/resources/linux-x86-64/libtree-sitter-python.so + +# bindingsFunlang + +LIBS_PATH=$(nix build .#tree-sitter-funlang-all --no-link --print-out-paths --print-build-logs) +mkdir -p modules/treesitter/src/main/resources +cp -R "$LIBS_PATH"/* modules/treesitter/src/main/resources +chmod -R 755 modules/treesitter/src/main/resources