Skip to content

Commit

Permalink
feat: add swift support. add tests for each tree-sitter-ng project.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfaller committed Nov 20, 2024
1 parent a2aff2f commit fa6d471
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 16 deletions.
31 changes: 16 additions & 15 deletions gen.treesitter-ng/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ description = 'GumTree tree generator for tree-sitter-ng.'

dependencies {
implementation("org.yaml:snakeyaml:2.0")
implementation("io.github.bonede:tree-sitter:0.22.2")
implementation("io.github.bonede:tree-sitter-c:0.20.5")
implementation("io.github.bonede:tree-sitter-cmake:0.4.1")
implementation("io.github.bonede:tree-sitter-c-sharp:0.20.0")
implementation("io.github.bonede:tree-sitter-go:0.20.0")
implementation("io.github.bonede:tree-sitter-javascript:0.20.1")
implementation("io.github.bonede:tree-sitter-kotlin:0.3.1")
implementation("io.github.bonede:tree-sitter-java:0.20.2")
implementation("io.github.bonede:tree-sitter-ocaml:0.20.4")
implementation("io.github.bonede:tree-sitter-php:0.20.0")
implementation("io.github.bonede:tree-sitter-python:0.20.4")
implementation("io.github.bonede:tree-sitter-r:main")
implementation("io.github.bonede:tree-sitter-ruby:0.19.0")
implementation("io.github.bonede:tree-sitter-rust:0.20.4")
implementation("io.github.bonede:tree-sitter-typescript:0.20.3")
implementation("io.github.bonede:tree-sitter:0.24.3")
implementation("io.github.bonede:tree-sitter-c:0.20.7a")
implementation("io.github.bonede:tree-sitter-cmake:0.4.1a")
implementation("io.github.bonede:tree-sitter-c-sharp:0.20.0a")
implementation("io.github.bonede:tree-sitter-go:0.21.0a")
implementation("io.github.bonede:tree-sitter-javascript:0.21.2")
implementation("io.github.bonede:tree-sitter-kotlin:0.3.8")
implementation("io.github.bonede:tree-sitter-java:0.21.0a")
implementation("io.github.bonede:tree-sitter-ocaml:0.22.0a")
implementation("io.github.bonede:tree-sitter-php:0.22.4")
implementation("io.github.bonede:tree-sitter-python:0.21.0a")
implementation("io.github.bonede:tree-sitter-r:main-a")
implementation("io.github.bonede:tree-sitter-ruby:0.21.0")
implementation("io.github.bonede:tree-sitter-rust:0.21.2")
implementation("io.github.bonede:tree-sitter-swift:0.5.0")
implementation("io.github.bonede:tree-sitter-typescript:0.21.1")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2021 Jean-Rémy Falleri <[email protected]>
*/

package com.github.gumtreediff.gen.treesitterng;

import com.github.gumtreediff.gen.Register;
import com.github.gumtreediff.utils.Registry;
import org.treesitter.TSLanguage;
import org.treesitter.TreeSitterSwift;

@Register(id = "swift-treesitter-ng", accept = "\\.swift$", priority = Registry.Priority.HIGH)
public final class SwiftTreeSitterNgTreeGenerator extends AbstractTreeSitterNgGenerator {
public static final TSLanguage SWIFT_TREE_SITTER_LANGUAGE = new TreeSitterSwift();
private static final String SWIFT_LANGUAGE_NAME = "swift";

@Override
protected TSLanguage getTreeSitterLanguage() {
return SWIFT_TREE_SITTER_LANGUAGE;
}

@Override
protected String getLanguageName() {
return SWIFT_LANGUAGE_NAME;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2024 Jean-Rémy Falleri <[email protected]>
*/
package com.github.gumtreediff.gen.treesitterng;

import com.github.gumtreediff.tree.TreeContext;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class CMakeTreeSitterNgTreeGeneratorTest {
private final CMakeTreeSitterNgTreeGenerator generator = new CMakeTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("project(HelloWorld)\n"
+ "cmake_minimum_required(VERSION 3.0)\n"
+ "add_executable(hello_world main.cpp)");
assertEquals(26, src.getRoot().getMetrics().size);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2024 Jean-Rémy Falleri <[email protected]>
*/
package com.github.gumtreediff.gen.treesitterng;

import com.github.gumtreediff.tree.TreeContext;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class CTreeSitterNgTreeGeneratorTest {
private final CTreeSitterNgTreeGenerator generator = new CTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("#include <stdio.h>\n"
+ "int main() {\n"
+ " printf(\"Hello, World!\");\n"
+ " return 0;\n"
+ "}");
assertEquals(29, src.getRoot().getMetrics().size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("fun main(args : Array<String>) {\n"
+ " println(\"Hello, World!\")\n"
+ "}");
assertEquals(21, src.getRoot().getMetrics().size);
assertEquals(22, src.getRoot().getMetrics().size);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2024 Jean-Rémy Falleri <[email protected]>
*/
package com.github.gumtreediff.gen.treesitterng;

import com.github.gumtreediff.tree.TreeContext;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class RTreeSitterNgTreeGeneratorTest {
private final RTreeSitterNgTreeGenerator generator = new RTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("print(\"Hello World!\")");
assertEquals(9, src.getRoot().getMetrics().size);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2024 Jean-Rémy Falleri <[email protected]>
*/
package com.github.gumtreediff.gen.treesitterng;

import com.github.gumtreediff.tree.TreeContext;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class SwiftTreeSitterNgTreeGeneratorTest {
private final SwiftTreeSitterNgTreeGenerator generator = new SwiftTreeSitterNgTreeGenerator();

@Test
public void testHelloWorld() throws IOException {
TreeContext src = generator.generateFrom().string("print(\"Hello, World!\")");
assertEquals(12, src.getRoot().getMetrics().size);
}
}

0 comments on commit fa6d471

Please sign in to comment.