{"id":28417,"library":"tree-sitter-swift","title":"tree-sitter-swift","description":"Swift grammar for tree-sitter, providing incremental parsing, syntax highlighting, and code analysis for the Swift programming language. Current version: 0.7.2. Released irregularly, with updates following Swift language evolution and tree-sitter releases.","status":"active","version":"0.7.2","language":"python","source_language":"en","source_url":"https://github.com/alex-pinkus/tree-sitter-swift","tags":["tree-sitter","swift","parser","grammar","synatx","highlighting"],"install":[{"cmd":"pip install tree-sitter-swift","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Required to load and use the grammar; tree-sitter-swift provides only the grammar definition.","package":"tree-sitter","optional":false}],"imports":[{"note":"The correct export is a function `language()`, not a class `Language`.","wrong":"from tree_sitter_swift import Language","symbol":"Language","correct":"from tree_sitter_swift import language"}],"quickstart":{"code":"import tree_sitter as ts\nfrom tree_sitter_swift import language\n\nparser = ts.Parser(language())\ntree = parser.parse(b\"let x = 42\")\nprint(tree.root_node.type)","lang":"python","description":"Create a parser with the Swift language and parse a simple Swift snippet."},"warnings":[{"fix":"Update tree-sitter to >=0.23.0: pip install 'tree-sitter>=0.23'","message":"In version 0.7.0, the grammar was updated to tree-sitter 0.23, introducing breaking changes in the tree-sitter API. Ensure you are using tree-sitter >= 0.23.0.","severity":"breaking","affected_versions":">=0.7.0, <0.8.0"},{"fix":"Replace `from tree_sitter_swift import Language` with `from tree_sitter_swift import language` and call `language()`.","message":"The import path from tree_sitter_swift import Language is deprecated. Use from tree_sitter_swift import language instead.","severity":"deprecated","affected_versions":">=0.5.0, <0.8.0"},{"fix":"Re-create the parser and load the grammar after deserialization instead of pickling the parser directly.","message":"Grammar functions may be pickled incorrectly if you try to serialize the parser object with the grammar loaded.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Change import to: from tree_sitter_swift import language","cause":"Importing a non-existent attribute `Language`; the correct import is the function `language` without capital L.","error":"AttributeError: module 'tree_sitter_swift' has no attribute 'Language'"},{"fix":"Use the newer API: parser = ts.Parser(language())","cause":"Passing the language object directly to `Parser()` in older tree-sitter versions (<0.23) or using the wrong API pattern.","error":"TypeError: Parser() takes no arguments"},{"fix":"Ensure you have Rust installed to compile from source, or use a version that supports your platform: pip install 'tree-sitter-swift>=0.7'","cause":"Attempting to install a version of `tree-sitter-swift` that does not have a prebuilt wheel for the current platform or Python version.","error":"tree_sitter_swift does not provide bindings for version x.y.z"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}