Skip to content

jwmatthews/treesitter_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

treesitter_example

Example of playing with TreeSitter for Java parsing

Setup

  1. python3 -m venv env
  2. source env/bin/activate
  3. pip install -r ./requirements.txt
  4. pip install git+https://github.com/konveyor/kai.git
  • TODO: Need to address conflict with treesitter and treesitter-langauges

Notes

Example to run

Example 1

$ python3 java_scope_finder.py ./data/Example.java 5
/Users/jmatthews/git/jwmatthews/treesitter_example/env/lib/python3.12/site-packages/tree_sitter/__init__.py:36: FutureWarning: Language(path, name) is deprecated. Use Language(ptr, name) instead.
  warn("{} is deprecated. Use {} instead.".format(old, new), FutureWarning)
Scope Type: class_declaration
Start Line: 1
End Line: 12

Code Snippet:
public class Example {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }

    public void methodOne() {
        // Some code here
        if (condition) {
            // More code
        }
    }
}

Example 2

$ python3 java_scope_finder.py ./data/Example.java 10
/Users/jmatthews/git/jwmatthews/treesitter_example/env/lib/python3.12/site-packages/tree_sitter/__init__.py:36: FutureWarning: Language(path, name) is deprecated. Use Language(ptr, name) instead.
  warn("{} is deprecated. Use {} instead.".format(old, new), FutureWarning)
Scope Type: expression_statement
Start Line: 10
End Line: 10

Code Snippet:
            System.out.println("Inside of if #1");

About

Example of playing with TreeSitter for Java parsing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published