Skip to content

parser.parseString - returns null #27

@hudara

Description

@hudara

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions