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.parseString - returns null #27

Open
hudara opened this issue May 18, 2023 · 2 comments
Open

parser.parseString - returns null #27

hudara opened this issue May 18, 2023 · 2 comments

Comments

@hudara
Copy link

hudara commented May 18, 2023

I am trying to create a Java parser which parse Javascript files. Here is what I have done:

  1. Build libjava-tree-sitter.dylib file
  2. Created a simple java command line application
  3. Tried to execute the following code:
        try (Parser parser = new Parser()) {
            parser.setLanguage(Languages.javascript());
            try (Tree tree = parser.parseString("function foo(){return 8;}")) {
                Node root = tree.getRootNode();
                Node function = root.getChild(0);
            }
            catch (Exception e){
                System.out.println("Error: " + e.getMessage());
                e.printStackTrace();
            }
        }

    }

The problem is that the returned "tree" object contains pointer "0" (zero) - I guess this is equivalent to "null"
Executing the next line (tree.getRootNode) throws an exception:

My questions are:

  1. Any idea what can go wrong?
  2. How can I debug the code in the parser level?
# C  [libjava-tree-sitter.dylib+0x292d4]  ts_tree_root_node+0x0
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
Disconnected from the target VM, address: '127.0.0.1:57533', transport: 'socket'
# An error report file with more information is saved as:
# ********/tree-sitter/test-tree-sitter/hs_err_pid41900.log
#
# If you would like to submit a bug report, please visit:
#   https://github.com/Homebrew/homebrew-core/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

OS: MacOS 13.3.1

@sogaiu
Copy link

sogaiu commented May 19, 2023

If you're using an Apple Silicon mac and/or the grammar in question has an external parser that is written in C (not C++; check the files in the src directory of the grammar's repository) [1], you might find this PR worth trying.


[1] More about that here.

@rondales
Copy link

I am trying to create a Java parser which parse Javascript files. Here is what I have done:

  1. Build libjava-tree-sitter.dylib file
  2. Created a simple java command line application
  3. Tried to execute the following code:
        try (Parser parser = new Parser()) {
            parser.setLanguage(Languages.javascript());
            try (Tree tree = parser.parseString("function foo(){return 8;}")) {
                Node root = tree.getRootNode();
                Node function = root.getChild(0);
            }
            catch (Exception e){
                System.out.println("Error: " + e.getMessage());
                e.printStackTrace();
            }
        }

    }

The problem is that the returned "tree" object contains pointer "0" (zero) - I guess this is equivalent to "null" Executing the next line (tree.getRootNode) throws an exception:

My questions are:

  1. Any idea what can go wrong?
  2. How can I debug the code in the parser level?
# C  [libjava-tree-sitter.dylib+0x292d4]  ts_tree_root_node+0x0
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
Disconnected from the target VM, address: '127.0.0.1:57533', transport: 'socket'
# An error report file with more information is saved as:
# ********/tree-sitter/test-tree-sitter/hs_err_pid41900.log
#
# If you would like to submit a bug report, please visit:
#   https://github.com/Homebrew/homebrew-core/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

OS: MacOS 13.3.1

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

3 participants