Tree-sitter Java and Kotlin Bindings

website·Indexed 29 days ago

https://tree-sitter.github.io/tree-sitter/

API documentation for Tree-sitter parsing library bindings for Java (jtreesitter) and Kotlin (ktreesitter), including details on TreeCursor, QueryError, and QueryMatch.

Tokens
115.7K
Snippets
815
Records
1.1K
Agent score
71%

What's inside Tree-sitter

  1. Overview of Tree-sitter syntax highlighting requirements

    Tree-sitter provides syntax highlighting via the tree-sitter-highlight library or the tree-sitter highlight CLI command. To perform highlighting from the command line, three components are required:

    1. Per-user configuration: located at ~/.config/tree-sitter/config.json.
    2. Language configuration: defined in the grammar repository's tree-sitter.json file.
    3. Tree queries: located in the grammar repository's queries folder.
  2. Overview of io.github.treesitter.jtreesitter package classes

    The io.github.treesitter.jtreesitter package provides the Java bindings for Tree-sitter, enabling the parsing of source code into syntax trees and the execution of queries against those trees. Key components include the Parser for generating a Tree, the TreeCursor for navigating the tree, and the Query system for pattern matching nodes.
  3. Introduction to Tree-sitter Pattern Matching Queries

    Tree-sitter provides a specialized pattern-matching language designed for code analysis. It allows developers to search for specific source code structures and patterns within the syntax tree without needing to implement complex manual parsing logic. This language is similar to the one used in Tree-sitter's unit test system.
  4. Overview of Tree-sitter components

    Tree-sitter consists of two primary components:

    1. libtree-sitter: A C library designed to be embedded in applications. It uses generated parsers to produce and update syntax trees from source code. Its interface is defined in tree_sitter/api.h.
    2. tree-sitter CLI: A build tool written in Rust used to generate a language parser from a context-free grammar. Once the parser is generated, the CLI is no longer required for runtime operation.
  5. Overview of Tree-sitter

    Tree-sitter is a parser generator tool and an incremental parsing library. It builds a concrete syntax tree for a source file and efficiently updates it as the file is edited. Key characteristics include: being general enough for any programming language, fast enough for real-time editor updates, robust against syntax errors, and dependency-free (written in pure C11) for easy embedding.
  6. Overview of Tree-sitter

    Tree-sitter is a parser generator tool and an incremental parsing library. It builds a concrete syntax tree for a source file and can efficiently update that tree as the file is edited. It is designed to be general (parsing any programming language), fast (suitable for per-keystroke parsing in editors), robust (handling syntax errors), and dependency-free (the runtime library is written in pure C11 for easy embedding).
  7. Overview of io.github.treesitter.jtreesitter package components

    The io.github.treesitter.jtreesitter package provides the core Java API for interacting with Tree-sitter. Key components include:

    • Parsing & Trees: Parser, Tree, Node, and TreeCursor for generating and navigating syntax trees.
    • Queries: Query, QueryCursor, and QueryPredicate for searching and matching patterns within the tree.
    • Language Support: Language for defining the grammar of the language being parsed.
    • Resource Management: Many core classes (Parser, Tree, Query, QueryCursor, TreeCursor) implement java.lang.AutoCloseable and should be used with try-with-resources to prevent memory leaks.
    • Error Handling: QueryError and its specialized subclasses (e.g., QueryError.Syntax, QueryError.Predicate) provide detailed information when queries fail.
  8. Overview of Tree-sitter

    Tree-sitter is a parser generator tool and an incremental parsing library. It builds a concrete syntax tree (CST) for a source file and can efficiently update that tree as the file is edited. It is designed to be general enough for any programming language, fast enough for real-time editor updates (per keystroke), robust against syntax errors, and dependency-free (the runtime is written in pure C11) for easy embedding in applications.