Skip to content

Commit

Permalink
new age of treesitter4s
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Oct 30, 2024
1 parent 7cc3713 commit 3b5af71
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 72 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ jobs:
- name: Show extension test logs
if: job.status == 'failure'
run: cat vscode-extension/fixture/smithyql-log.txt | tail --lines 1000

build-parser:
name: "Build parser"
strategy:
matrix:
os: [ubuntu-latest, macos-latest, macos-13]
runs-on: ${{matrix.os}}
timeout-minutes: 10
steps:
- uses: actions/[email protected]
- name: Parser tests
# intentionally not setting up nix
run: sbt parser/run
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ lazy val parser = module("parser")
"io.circe" %% "circe-generic" % "0.14.10" % Test,
"io.circe" %% "circe-parser" % "0.14.10" % Test,
"co.fs2" %% "fs2-io" % "3.11.0" % Test,
"org.polyvariant.treesitter4s" %% "core" % "0.3-8c8ea67-SNAPSHOT",
"org.polyvariant.treesitter4s" %% "core" % "0.3-1ab76c4-SNAPSHOT",
)
)
.dependsOn(
Expand Down
39 changes: 7 additions & 32 deletions flake.lock

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

45 changes: 12 additions & 33 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
treesitter4s.url = "github:polyvariant/treesitter4s/native";
treesitter4s.inputs.nixpkgs.follows = "nixpkgs";
treesitter4s.inputs.flake-utils.follows = "flake-utils";
};

outputs = { self, nixpkgs, flake-utils, treesitter4s, ... }:
let
ts-lib = treesitter4s.lib; in
outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (
system:
let
Expand All @@ -28,39 +23,23 @@
pkgs.coursier
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.xvfb-run ];
};
packages.grammar =
let base = pkgs.stdenv.mkDerivation {
pname = "tree-sitter-smithyql-generated";
version = "0.0.0";
packages.tree-sitter-smithyql =
pkgs.stdenv.mkDerivation {
name = "tree-sitter-smithyql";
src = ./tree-sitter-smithyql;
buildInputs = [ pkgs.tree-sitter pkgs.nodejs ];
buildInputs = [pkgs.tree-sitter pkgs.nodejs];
buildPhase = ''
ls -ll
tree-sitter generate
make
ls -ll
'';
installPhase = ''
cp -r . $out
installPhase = if system == "x86_64-darwin" || system == "aarch64-darwin" then ''
cp libtree-sitter-smithyql.dylib $out
'' else ''
cp libtree-sitter-smithyql.so $out
'';
}; in
pkgs.callPackage "${nixpkgs}/pkgs/development/tools/parsing/tree-sitter/grammar.nix" { } {
language = "tree-sitter-smithyql";
inherit (base) version;
source = base;
};
packages.grammar-all =
pkgs.linkFarm "grammar-all" [
{
name = "modules/parser/src/main/resources";
path = pkgs.callPackage ts-lib.make-grammar-resources {
package = system:
let pkgs = import nixpkgs { inherit system; }; in
pkgs.callPackage ts-lib.rename-grammar {
pname = "tree-sitter-smithyql";
grammar = self.packages.${system}.grammar;
rename-dependencies = true;
};
};
}
];
}
);
}
Binary file modified modules/parser/src/main/resources/darwin-aarch64/libtree-sitter-smithyql.dylib
100644 → 100755
Binary file not shown.
Binary file modified modules/parser/src/main/resources/darwin-x86-64/libtree-sitter-smithyql.dylib
100644 → 100755
Binary file not shown.
Binary file modified modules/parser/src/main/resources/linux-aarch64/libtree-sitter-smithyql.so
100644 → 100755
Binary file not shown.
Binary file modified modules/parser/src/main/resources/linux-x86-64/libtree-sitter-smithyql.so
100644 → 100755
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package playground.smithyql

import org.polyvariant.treesitter4s.TreeSitter
import org.polyvariant.treesitter4s.TreeSitterAPI

object ParserTreeSitterDemo extends App {

def parse(s: String) = {
val p = TreeSitter.make(SmithyQLLanguageBindings.SmithyQL)
val p = TreeSitterAPI.make(_.Language(SmithyQLLanguageBindings.SmithyQL))
val tree = p.parse(s)
println(tree.rootNode.get.fields.keySet)
}
Expand Down
24 changes: 20 additions & 4 deletions update-libs.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

RESULT=$(nix build ".#grammar-all" --no-link --print-out-paths --print-build-logs)
# copy, flattening links
cp --no-preserve=mode,ownership -Lr "$RESULT"/* .
mkdir -p modules/parser/src/main/resources/darwin-aarch64
BINARY_PATH=$(nix build .#packages.aarch64-darwin.tree-sitter-smithyql --no-link --print-out-paths --print-build-logs)
cp $BINARY_PATH modules/parser/src/main/resources/darwin-aarch64/libtree-sitter-smithyql.dylib
chmod 755 modules/parser/src/main/resources/darwin-aarch64/libtree-sitter-smithyql.dylib
mkdir -p modules/parser/src/main/resources/darwin-x86-64
BINARY_PATH=$(nix build .#packages.x86_64-darwin.tree-sitter-smithyql --no-link --print-out-paths --print-build-logs)
cp $BINARY_PATH modules/parser/src/main/resources/darwin-x86-64/libtree-sitter-smithyql.dylib
chmod 755 modules/parser/src/main/resources/darwin-x86-64/libtree-sitter-smithyql.dylib
mkdir -p modules/parser/src/main/resources/linux-aarch64
BINARY_PATH=$(nix build .#packages.aarch64-linux.tree-sitter-smithyql --no-link --print-out-paths --print-build-logs)
cp $BINARY_PATH modules/parser/src/main/resources/linux-aarch64/libtree-sitter-smithyql.so
chmod 755 modules/parser/src/main/resources/linux-aarch64/libtree-sitter-smithyql.so
mkdir -p modules/parser/src/main/resources/linux-x86-64
BINARY_PATH=$(nix build .#packages.x86_64-linux.tree-sitter-smithyql --no-link --print-out-paths --print-build-logs)
cp $BINARY_PATH modules/parser/src/main/resources/linux-x86-64/libtree-sitter-smithyql.so
chmod 755 modules/parser/src/main/resources/linux-x86-64/libtree-sitter-smithyql.so

0 comments on commit 3b5af71

Please sign in to comment.