{"id":13338392,"url":"https://github.com/alextsao1999/ast-buffer","last_synced_at":"2025-03-11T09:30:58.610Z","repository":{"id":108048132,"uuid":"262050995","full_name":"alextsao1999/ast-buffer","owner":"alextsao1999","description":"Fast incremental parsing using piece table and tree-sitter to generate syntax tree","archived":false,"fork":false,"pushed_at":"2020-05-12T14:52:02.000Z","size":614,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-23T20:15:44.552Z","etag":null,"topics":["ast","buffer","data-structures","piece-table","text","text-buffer","text-editor","tree-sitter","tree-sitter-cpp"],"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/alextsao1999.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-05-07T12:59:40.000Z","updated_at":"2024-08-19T12:36:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"eee97a4a-8c08-4541-b777-a02005d0b769","html_url":"https://github.com/alextsao1999/ast-buffer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextsao1999%2Fast-buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextsao1999%2Fast-buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextsao1999%2Fast-buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextsao1999%2Fast-buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alextsao1999","download_url":"https://codeload.github.com/alextsao1999/ast-buffer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243007037,"owners_count":20220762,"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":["ast","buffer","data-structures","piece-table","text","text-buffer","text-editor","tree-sitter","tree-sitter-cpp"],"created_at":"2024-07-29T19:16:18.457Z","updated_at":"2025-03-11T09:30:58.535Z","avatar_url":"https://github.com/alextsao1999.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ASTBuffer\nFast incremental parsing using tree-sitter and piece table\n\n使用tree-sitter+piece-table实现快速增量解析 并生成ast\n\npiece-table 测试了一下300MB左右的文件5000行中插入数据需要48ms\n\n* 主要是给我的code editor改进一下储存结构 🤭\n* 如果喜欢的话或者可以给您的editor加成个 [LSP](https://github.com/alextsao1999/lsp-cpp) ~\n\n\n## Usage\n\n```c++\n#include \u003cast_buffer.h\u003e\n#include \u003corigin.h\u003e\nint main() {\n    ASTBuffer\u003cchar\u003e ast(ts::Language::cpp());\n    ast.parser().set_timeout(500);\n    //size_t position = 50000;\n    //ast.parser().set_cancel_position(\u0026position);\n    //Origin origin(\"your/file/path/xxxx.txt\");\n    //ast.append_origin((char *) origin.ptr(), origin.size());\n\n    ast.append(\"int main(int abc) {\\n\");\n    ast.append(\"    auto *str = \\\"asdf\\\";\\n\");\n    ast.append(\"    *str = test();\\n\");\n    ast.append(\"    return 0;\\n\");\n    ast.append(\"}\\n\");\n    ast.append(\"test(get(\\\"1234\\\"));\\n\");\n    //std::cout \u003c\u003c ast.tree().root().string();\n    ast.append(\"int add(int x, int y) {return x + y;}\\n\");\n    ast.dump();\n\n    auto query = ts::Language::cpp().query(\n            \"(number_literal) @number\"\n            \"(string_literal) @string\"\n            \"(call_expression function: (identifier) @fun-call)\"\n            \"(binary_expression left: (identifier) @left right: (identifier) @right)\");\n\n    auto cursor = query.exec(ast.tree().root());\n    uint32_t index;\n    while (cursor.next_capture(index)) {\n        auto node = cursor.capture_node(index);\n        auto name = cursor.capture_name(index);\n        std::cout \u003c\u003c\"capture:\" \u003c\u003c node.string() \u003c\u003c \" \" \u003c\u003c name \u003c\u003c \" -\u003e \" \u003c\u003c ast.node_string(node) \u003c\u003c std::endl;\n    }\n    return 0;\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falextsao1999%2Fast-buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falextsao1999%2Fast-buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falextsao1999%2Fast-buffer/lists"}