{"id":9369,"library":"tree-sitter-kotlin","title":"tree-sitter-kotlin","description":"tree-sitter-kotlin provides a Kotlin grammar for the Tree-sitter parsing library. Tree-sitter is an incremental parsing system designed for text editors, enabling fast and robust syntax tree generation and updates. This Python package provides pre-compiled binaries of the Kotlin grammar, allowing developers to parse Kotlin code and build Abstract Syntax Trees (ASTs) in Python applications. The library maintains an active development status, with recent releases indicating a cadence of a few updates per year.","status":"active","version":"1.1.0","language":"python","source_language":"en","source_url":"https://github.com/tree-sitter-grammars/tree-sitter-kotlin","tags":["tree-sitter","kotlin","parsing","grammar","AST","compiler"],"install":[{"cmd":"pip install tree-sitter-kotlin","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required for the Python bindings to interact with Tree-sitter grammars.","package":"tree_sitter","optional":false}],"imports":[{"wrong":"import tree_sitter_kotlin as tskt\nfrom tree_sitter import Language\nKOTLIN_LANGUAGE = Language(tskt.language())","symbol":"Language","correct":"from tree_sitter_kotlin import language"}],"quickstart":{"code":"import tree_sitter_kotlin as tskt\nfrom tree_sitter import Language, Parser\n\n# Load the Kotlin grammar\nKOTLIN_LANGUAGE = Language(tskt.language())\n\n# Create a parser and set the language\nparser = Parser()\nparser.set_language(KOTLIN_LANGUAGE)\n\n# Sample Kotlin code to parse\nkotlin_code = b'''\nfun main() {\n    val greeting = \"Hello, Tree-sitter!\"\n    println(greeting)\n}\n'''\n\n# Parse the code\ntree = parser.parse(kotlin_code)\n\n# Get the root node of the AST\nroot_node = tree.root_node\n\nprint(f\"Root node type: {root_node.type}\")\nprint(f\"Root node children count: {len(root_node.children)}\")\n# Example: Find a function declaration\nfunction_node = root_node.children[0] # Assuming 'fun main()' is the first child\nif function_node.type == 'function_declaration':\n    print(f\"Found function: {function_node.text.decode('utf8').split('(')[0]}\")","lang":"python","description":"Demonstrates how to load the `tree-sitter-kotlin` grammar and use `tree_sitter.Parser` to parse a basic Kotlin code snippet, then access the root node of the generated Abstract Syntax Tree."},"warnings":[{"fix":"Instead of `Language.build_library()`, install pre-compiled language packages (e.g., `pip install tree-sitter-kotlin`). For custom grammars, external compilation tools or older `tree_sitter` versions (pre-0.22.0) are required.","message":"The `Language.build_library()` static method for compiling grammars was removed from the `tree_sitter` Python binding around versions 0.21.x/0.22. Direct compilation of local grammar sources is no longer supported via this API.","severity":"breaking","affected_versions":"tree_sitter >= 0.22.0"},{"fix":"When creating a `Parser`, consider setting a larger `bufferSize` in the `parse()` method's options if dealing with very large source files, or splitting files into smaller chunks before parsing. Consult `tree_sitter` documentation for `parse()` method options.","message":"Tree-sitter can fail to parse large files (e.g., >32KB) with a generic 'Invalid argument' error if the internal buffer size is not adequately configured.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you call `tree_sitter_kotlin.language()` (e.g., `Language(tskt.language())`) and do not treat `language` as a direct attribute or constant without the `()`.","message":"Grammar objects are loaded via a function call, not directly as attributes. For `tree-sitter-kotlin`, you must call `tskt.language()` to get the underlying C grammar object.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'abstract':61 'activ':72 'allow':53 'applic':67 'ast':64,93 'binari':48 'build':60 'cadenc':80 'code':58 'compil':47,94 'design':28 'develop':54,73 'editor':31 'enabl':32 'fast':33 'generat':38 'grammar':12,52,92 'increment':25 'indic':78 'kotlin':4,8,11,51,57,90 'librari':19,69 'maintain':70 'packag':43 'pars':18,26,56,91 'per':85 'pre':46 'pre-compil':45 'provid':9,44 'python':42,66 'recent':76 'releas':77 'robust':35 'sitter':3,7,17,22,89 'status':74 'syntax':36,62 'system':27 'text':30 'tree':2,6,16,21,37,63,88 'tree-sitt':15,20,87 'tree-sitter-kotlin':1,5 'updat':40,84 'year':86","created_at":"2026-04-16T18:49:51.693988+00:00","updated_at":"2026-04-16T18:49:51.693988+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.1.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://tree-sitter.github.io/tree-sitter/","github":"https://github.com/tree-sitter-grammars/tree-sitter-kotlin","docs":null,"changelog":null,"pypi":"https://pypi.org/project/tree-sitter-kotlin/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-06-30","next_check":"2026-07-30","install_tag":null}}