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

parser.setLanguage() error #30

Open
gsalmh opened this issue Jun 9, 2023 · 1 comment
Open

parser.setLanguage() error #30

gsalmh opened this issue Jun 9, 2023 · 1 comment

Comments

@gsalmh
Copy link

gsalmh commented Jun 9, 2023

public class App {
    static {
       System.load("/code/java-tree-sitter/libjava-tree-sitter.so");
    }
    public String getGreeting() {
        return "Hello world.";
    }

    public static void main(String[] args) throws UnsupportedEncodingException {
        System.out.println(new App().getGreeting());

        try (Parser parser = new Parser()) {
            parser.setLanguage(Languages.python());
            try (Tree tree = parser.parseString("print(\"hi\")")) {
                System.out.println(tree.getRootNode().getNodeString());
            }
        }
    }
}

When i ran code above, the program can load "libjava-tree-sitter.so" successfully, but encountered the following exception.I tried to solve the problem according to the method in this link,but it didn't work.

Exception in thread "main" java.lang.UnsatisfiedLinkError: 'long ai.serenade.treesitter.Languages.javascript()'
        at ai.serenade.treesitter.Languages.javascript(Native Method)
        at demo.App.main(App.java:36)

program enviroment:
CentOS Linux release 7.9.2009
openjdk version "11.0.11" 2021-04-20
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)

So any idea what can i do ?

@sogaiu
Copy link

sogaiu commented Jun 9, 2023

The error message mentions tree-sitter-javascript. That particular grammar / parser does not use C++, but rather C-only: https://github.com/tree-sitter/tree-sitter-javascript/tree/master/src Note the lack of .cpp files there.

That matches a condition mentioned in this PR. Specifically the 3rd condition.

Even though that PR also mentions M1 and macos (the 1st condition), I believe the PR may be relevant to situations like the error message hints at as I also encountered a similar situation and things worked for me with changes similar to some of those in the PR.

I think it's possible that trying the code in the PR might help.

Alternatively, if you work with only grammars / parsers that have some C++ in them (look in the grammar's src directory for scanner.cpp), that might also get things working.

It would be nice if that PR or something similar got merged but unfortunately it looks like the maintainer(s) have not been around to attend to this situation for a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants