{"id":21731773,"url":"https://github.com/evref-bl/pharo-tree-sitter","last_synced_at":"2025-08-22T00:07:50.900Z","repository":{"id":253541832,"uuid":"843819305","full_name":"Evref-BL/Pharo-Tree-Sitter","owner":"Evref-BL","description":"A tree-sitter FFI binding for Pharo","archived":false,"fork":false,"pushed_at":"2024-12-20T13:07:34.000Z","size":76,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-14T01:15:05.175Z","etag":null,"topics":["pharo","tree-sitter"],"latest_commit_sha":null,"homepage":"","language":"Smalltalk","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Evref-BL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-17T14:14:33.000Z","updated_at":"2024-12-20T13:07:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"314f4867-fc9c-46eb-9b34-d03a294aecab","html_url":"https://github.com/Evref-BL/Pharo-Tree-Sitter","commit_stats":null,"previous_names":["badetitou/pharo-tree-sitter","evref-bl/pharo-tree-sitter"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evref-BL%2FPharo-Tree-Sitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evref-BL%2FPharo-Tree-Sitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evref-BL%2FPharo-Tree-Sitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evref-BL%2FPharo-Tree-Sitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Evref-BL","download_url":"https://codeload.github.com/Evref-BL/Pharo-Tree-Sitter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235631023,"owners_count":19021049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pharo","tree-sitter"],"created_at":"2024-11-26T04:27:21.478Z","updated_at":"2025-08-22T00:07:50.885Z","avatar_url":"https://github.com/Evref-BL.png","language":"Smalltalk","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pharo Tree-Sitter\n\n[![CI](https://github.com/Evref-BL/Pharo-Tree-Sitter/actions/workflows/ci.yml/badge.svg)](https://github.com/Evref-BL/Pharo-Tree-Sitter/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/Evref-BL/Pharo-Tree-Sitter/badge.svg?branch=main)](https://coveralls.io/github/Evref-BL/Pharo-Tree-Sitter?branch=main)\n[![DOI](https://zenodo.org/badge/843819305.svg)](https://doi.org/10.5281/zenodo.15089053)\n\nThis project provides **Pharo bindings to [Tree-sitter](https://tree-sitter.github.io/tree-sitter/)**.  \nIt allows you to analyze and highlight code using existing Tree-sitter parsers developed by the community.\n\nTo install it in **Pharo**, run the following script in a Playground:\n\n```smalltalk\nMetacello new\n  baseline: 'TreeSitter';\n  repository: 'github://Evref-BL/Pharo-Tree-Sitter:main/src';\n  load.\n```\n\n## Native Libraries Required\n\nTo function correctly, the following native libraries are required depending on your OS:\n\n- `libtree-sitter.{dll, so, dylib}`: the core Tree-sitter runtime.\n- `tree-sitter-\u003clanguage\u003e.{dll, so, dylib}`: the parser for the desired language.\n\nFor example, to use Tree-sitter with Python:\n\n- `libtree-sitter.dylib` (core)\n- `tree-sitter-python.dylib` (parser)\n\nYou can generate these manually or take advantage of our **automated setup** for some supported languages.\n\n## Automated Library Generation\n\nWe automated the generation and installation of libraries for a few selected languages (currently **Python** and **TypeScript**) to simplify the setup across platforms. The generated libraries are copied directly to the appropriate Pharo `vm` folders.\n\nThe automation covers:\n\n- [Tree-sitter core](https://github.com/tree-sitter/tree-sitter)\n- [tree-sitter-python](https://github.com/tree-sitter/tree-sitter-python)\n- [tree-sitter-typescript](https://github.com/tree-sitter/tree-sitter-typescript)\n\n### How It Works\n\nWhen a new parser or language is requested, the automation:\n\n1. Checks if the required native library exists in the VM folder.\n2. If not, looks in the local cloned repository.\n3. If the repo isn’t cloned, it clones it.\n4. Builds the required library using CMake + Ninja.\n5. Copies it to the correct `vm` location.\n\nThis ensures libraries are only built when needed.\n\n\u003e **Note:** Automation is only available for a limited set of languages for now.  \n\u003e Contributions are welcome! See the `TreeSitter-Libraries` package and create a new subclass like `TreeSitter-NewLanguage`.\n\n### Required Tools for MacOS and Linux\n\nTo make sure the automation process works, please ensure the following tools are installed on your system:\n\n| Tool   | Role                              | Check Command         |\n|--------|-----------------------------------|------------------------|\n| Git    | Repository cloning                | `git --version`        |\n| make  | Build configuration               | `make --version`      |\n\nThese are mandatory to clone the repos and generate the libraries on these operating systems.\nAlso this automated process allows the tests on piplines to succeed.\n\n**However**, it turns out that make command for TreeSitter is not supported on windows. \nBut do not worry, we found an alternative to make, but you need to make sure that you have the correspondant tools on your machine, so the automation procces can function properly.\nCheck the below section;\n\n### Required Tools for Windows\n\nTo make sure the automation process works, please ensure the following tools are installed on your system:\n\n| Tool   | Role                              | Check Command         |\n|--------|-----------------------------------|------------------------|\n| Git    | Repository cloning                | `git --version`        |\n| CMake  | Build configuration               | `cmake --version`      |\n| GCC    | C/C++ compiler                    | `gcc --version`        |\n| Ninja  | Build system                      | `ninja --version`      |\n\nIf any of these commands fail, install the corresponding tool before continuing.\n\n## Manual Installation\n\nYou can also manually install the required libraries and copy them to the appropriate Pharo VM path. Below is an example for macOS.\n\n### macOS\n\nWe recommand you to download the tree-sitter core library using HomeBrew.\n\n```sh\nbrew install tree-sitter\n``` \n\nThen, locate the `libtree-sitter.dylib` under the path `/opt/homebrew/Cellar/tree-sitter/0.x.x/lib/libtree-sitter.dylib`.\nFinally, check the possible lib location detected by Pharo using `FFIMacLibraryFinder new paths` in a playground. \nBoth the core library and the parser library should be under any of these paths. Please move them there.\nFor instance, move your `python.dylib` under `/Pharo/vms/110-x64/Pharo.app/Contents/Resources/lib/`\nPay attention !! Make sure that Pharo is closed when you move the libraries specially after modifications on the original project, for example adding a new api. \nNormally on Windows you cannot replace the existing dll (if you already generated it for the first time) unless Pharo is closed. But if you intend to make it on mac for example, you need to close it and reopen it so the new modifications are applied. \n\n### Building Tree-sitter Shared Library\n\nTo build the shared library for tree-sitter, you can follow the following script:\n\n```sh\n# assuming git, gcc, cmake, ninja installed via scoop\ngit clone https://github.com/tree-sitter/tree-sitter\ngit fetch origin v0.24.3\ngit checkout v0.24.3\ncd tree-sitter\ncd lib\nmkdir build\ncd build\ncmake -G Ninja ..\nninja\n```\n\nThen move the `libtree-sitter.dll` file under the **VM** folder of Pharo.\n\n### Archlinux\n\nThe tree-sitter libs are available in the extra repository.\nSo you only have to install tree-sitter and the grammar you wanna use with your package manager.\n\n```sh\nyay tree-sitter tree-sitter-grammars\n```\n\n## Pre-built Libraries (Temporary Solution)\n\nIf you face issues building the libraries, you can download pre-built libraries (for Windows and macOS) here:\nhttps://doi.org/10.5281/zenodo.15423234\n\n## Quick Example\n\nHere is a basic usage example in Pharo:\n```st\nparser := TSParser new.\npythonLanguage := TSLanguage python.\nparser language: pythonLanguage.\nstring := 'print(\"Hello, I''m Python!\") # comment'.\ntree := parser parseString: string.\ntree rootNode\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevref-bl%2Fpharo-tree-sitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevref-bl%2Fpharo-tree-sitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevref-bl%2Fpharo-tree-sitter/lists"}