{"id":13577857,"url":"https://github.com/euclidianAce/ltreesitter","last_synced_at":"2025-04-05T15:31:32.002Z","repository":{"id":50541412,"uuid":"300464041","full_name":"euclidianAce/ltreesitter","owner":"euclidianAce","description":"Standalone tree sitter bindings for the Lua language","archived":false,"fork":false,"pushed_at":"2024-12-16T22:55:45.000Z","size":291,"stargazers_count":94,"open_issues_count":5,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-30T12:07:49.201Z","etag":null,"topics":["lua","parsing","teal","tree-sitter"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/euclidianAce.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-10-02T00:54:48.000Z","updated_at":"2025-03-09T12:47:50.000Z","dependencies_parsed_at":"2023-12-07T09:32:33.466Z","dependency_job_id":"da1c1ac9-26c6-42cf-8f7f-89d2ea42c2a3","html_url":"https://github.com/euclidianAce/ltreesitter","commit_stats":{"total_commits":189,"total_committers":5,"mean_commits":37.8,"dds":0.05820105820105825,"last_synced_commit":"b00c402f60cbba2cefaa91c86fd901d786baeb0e"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euclidianAce%2Fltreesitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euclidianAce%2Fltreesitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euclidianAce%2Fltreesitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euclidianAce%2Fltreesitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/euclidianAce","download_url":"https://codeload.github.com/euclidianAce/ltreesitter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247358763,"owners_count":20926283,"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":["lua","parsing","teal","tree-sitter"],"created_at":"2024-08-01T15:01:24.944Z","updated_at":"2025-04-05T15:31:31.995Z","avatar_url":"https://github.com/euclidianAce.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# ltreesitter\n\n![test](https://github.com/euclidianAce/ltreesitter/workflows/test/badge.svg)\n\nTree sitter bindings for Lua\n\nCurrent tree-sitter version: v0.24.5\n\n# Documentation\n\nDocumentation can be found at [this repo's github pages](https://euclidianace.github.io/ltreesitter/)\n(Which are autogenerated using the [Teal](https://github.com/teal-language/tl) script `scripts/gen.tl`)\n\n# Installation\n\n`ltreesitter` is avaliable on luarocks\n\n```\nluarocks install ltreesitter\n```\n\nor the latest main branch\n```\nluarocks install --dev ltreesitter\n```\n\n# Examples\n\nLooking for a quick start? These snippets should be descriptive enough to get you started. If you need more detail, take a look at the documentation\n\n## Setup\n\n### Loading parsers you have installed on your system\n```lua\nlocal ltreesitter = require(\"ltreesitter\")\n```\n\n#### `ltreesitter.require`\nAssuming you have a compiled c parser named `c.so` (or `c.dll` on windows) in `~/.tree-sitter/bin/` or `package.cpath`\n```lua\nlocal c_parser = ltreesitter.require(\"c\")\n```\n\nYou have a `parser.so` (or `.dll`) with the symbol `tree_sitter_lua` to load the language\n```lua\nlocal lua_parser = ltreesitter.require(\"parser\", \"lua\")\n```\n\n#### `ltreesitter.load`\n`load` will just directly load from the filename given.\n```lua\nlocal local_c_parser = ltreesitter.load(\"./c-parser.so\", \"c\")\n```\nUsing a path without a path separator may have unintended consequences, so when in doubt, include a leading `./` or use an absolute path.\n\nFor more information, look into how `dlopen` and `LoadLibrary` find paths.\n\n## Basic parsing and usage of trees and nodes\n```lua\nlocal source_code = [[\n#include \u003cstdio.h\u003e\n\n// a function that does stuff\nstatic void stuff_doer(void) {\n    printf(\"I'm doing stuff! :D\\n\");\n}\n\nint main(int argc, char **argv) {\n    stuff_doer();\n    return 0;\n}\n]]\n\nlocal tree = c_parser:parse_string(source_code)\nprint(tree) -- tostring (which print calls automatically) will return the string of s-expressions of trees and nodes\n\nfor child in tree:root():named_children() do -- some iterators over nodes' children are provided\n   print(child)\nend\n```\n\n## Queries\nUsing the above `c_parser` and `tree`\n```lua\n-- Grab the names of all functions\nlocal my_query = c_parser:query[[\n    (translation_unit\n      (function_definition\n        declarator: (function_declarator\n                      declarator: (identifier) @name))) ]]\n\nfor capture, capture_name in my_query:capture(tree:root()) do -- iterate over captured nodes without caring about order\n   -- Node:source() gives the source code that the node comes from\n   print(capture:source(), capture_name) -- =\u003e \"stuff_doer\", \"name\" and \"main\", \"name\"\nend\n\nfor match in my_query:match(tree:root()) do\n   print(match.captures[\"name\"]:source()) -- =\u003e \"stuff_doer\" and \"main\"\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FeuclidianAce%2Fltreesitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FeuclidianAce%2Fltreesitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FeuclidianAce%2Fltreesitter/lists"}