{"id":51550395,"url":"https://github.com/openpeeps/sweetsyntax","last_synced_at":"2026-07-09T23:30:45.656Z","repository":{"id":368422713,"uuid":"1235585439","full_name":"openpeeps/sweetsyntax","owner":"openpeeps","description":"SweetSyntax 🍭 A generic parser and AST explorer for analyzing programming languages","archived":false,"fork":false,"pushed_at":"2026-06-30T12:57:29.000Z","size":113,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-30T14:26:35.606Z","etag":null,"topics":["ast","nim","openpeeps","parser","pratt","syntax","syntax-highlighter"],"latest_commit_sha":null,"homepage":"","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openpeeps.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-11T13:15:31.000Z","updated_at":"2026-06-30T12:57:35.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/openpeeps/sweetsyntax","commit_stats":null,"previous_names":["openpeeps/sweetsyntax"],"tags_count":null,"template":false,"template_full_name":"openpeeps/pistachio","purl":"pkg:github/openpeeps/sweetsyntax","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openpeeps%2Fsweetsyntax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openpeeps%2Fsweetsyntax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openpeeps%2Fsweetsyntax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openpeeps%2Fsweetsyntax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openpeeps","download_url":"https://codeload.github.com/openpeeps/sweetsyntax/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openpeeps%2Fsweetsyntax/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35315892,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-09T02:00:07.329Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","nim","openpeeps","parser","pratt","syntax","syntax-highlighter"],"created_at":"2026-07-09T23:30:45.064Z","updated_at":"2026-07-09T23:30:45.648Z","avatar_url":"https://github.com/openpeeps.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  SweetSyntax 🍭 A generic parser and AST explorer\u003cbr\u003efor analyzing programming languages \n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ccode\u003enimble install sweetsyntax\u003c/code\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://openpeeps.github.io/sweetsyntax\"\u003eAPI reference\u003c/a\u003e\u003cbr\u003e\n  \u003cimg src=\"https://github.com/openpeeps/sweetsyntax/workflows/test/badge.svg\" alt=\"Github Actions\"\u003e  \u003cimg src=\"https://github.com/openpeeps/sweetsyntax/workflows/docs/badge.svg\" alt=\"Github Actions\"\u003e\n\u003c/p\u003e\n\n## 😍 Key Features\n- Fast, compiled and efficient ([check benchmarks section](#benchmarks))\n- Generic parser \u0026 AST explorer\n- **Embeddable in other languages** via FFI 👉 Lua, JavaScript (N-API), Ruby, Python, PHP\n- Easy-to-use API for integration into various applications\n- Built-in syntax support for: C, Crystal, D lang, Go, JavaScript, Nim, PHP, Python, Ruby, and Rust\n- Zero-copy parsing using MemFiles\n- **Context-aware error** reporting while parsing\n- Written in Nim\n\n## What's this for?\nSweetSyntax is a powerful and flexible generic parser and AST explorer for analyzing programming languages! It is designed to be integrated into other applications, such as code editors, documentation generators, linting tools and other sweet things!\n\nParse any language by defining its grammar in a YAML specification file: **tokens**, **operators** (prefix, infix, postfix, assignment), **statement keywords**, block delimiters, and **feature flags** (arrow functions, generators, async/await, template literals). The parser uses a **Pratt parsing** approach with a language-agnostic core and per-language statement handlers.\n\nKey capabilities:\n- **Lexer**: Generic tokenizer handling identifiers, literals (int, float, hex, octal, binary, bigint, string, regex), comments, and operators\n- **Parser**: Pratt (precedence-climbing) parser with configurable operator precedence and associativity\n- **AST**: Typed node tree with support for statements, expressions, infix/prefix/postfix operations, function declarations, and more\n- **YAML-driven**: Language syntaxes are pure YAML, allowing for custom statement handlers\n\n### Embeddable SweetSyntax\nSweetSyntax is written in Nim, and thanks to Nim's versatile compilation model, can be embedded natively into a wide range of host languages. This is WIP via https://github.com/openpeeps/clue toolkit\n\n| Language | Integration |\n|----------|------------|\n| **Lua** | Load the compiled `.so`/`.dll` via LuaJIT FFI or a lightweight C binding |\n| **JavaScript** | Use as a Node.js native addon via N-API |\n| **Ruby** | Bundle as a Ruby C extension |\n| **Python** | Call through Python's CFFI or `ctypes` |\n| **PHP** | Expose as a PHP extension written in C |\n\nThe Nim library compiles to a small, self-contained shared object that any FFI-capable language can load, making SweetSyntax a portable parsing engine for your polyglot projects.\n\n## Examples\n_todo_\n\n### Error Reporting\nSweetSyntax has built-in support for context-aware reporting. For example:\n```\n  return a == null || b == null ## NaN : a \u003c b ? -1 : a \u003e b ? 1 : a \u003e= b ? 0 : NaN;\n                                ^\nError (2:33) Unexpected prefix token: '#'\n```\n\n### Benchmarks\nSweetSyntax is built for speed. Below is a **hyperfine** benchmark parsing and validating a full copy of **d3.js** (v7.9.0, ~20k lines, unminified, [from cdnjs.com](https://cdnjs.com/libraries/d3)). The entire pipeline (**lexing**, **parsing**, and **AST generation**) completes in under 120ms on my 🔥 rastafarian Ryzen 5 with 6 cores/12 threads:\n```\nhyperfine --runs 4 './sweetsyntax_benc_d3'\nBenchmark 1: ./sweetsyntax_benc_d3\n  Time (mean ± σ):     116.5 ms ±   1.1 ms    [User: 107.5 ms, System: 7.1 ms]\n  Range (min … max):   115.9 ms … 118.2 ms    4 runs\n```\n\n### ❤ Contributions \u0026 Support\n- 🐛 Found a bug? [Create a new Issue](https://github.com/openpeeps/sweetsyntax/issues)\n- 👋 Wanna help? [Fork it!](https://github.com/openpeeps/sweetsyntax/fork)\n\n|  |  |\n|---|---|\n| \u003ca href=\"https://opencode.ai/go?ref=BHMEEK48QX\"\u003e\u003cimg src=\"https://github.com/openpeeps/pistachio/blob/main/.github/opencode.png\" alt=\"OpenCode\"\u003e\u003c/a\u003e | Switch to **Open-Source LLMs** via OpenCode GO, choosing from a variety of powerful models such as DeepSeek, Qwen, Kimi, GLM-5, MiniMax, MiMo. 🍕 [Use our referral link to get started!](https://opencode.ai/go?ref=BHMEEK48QX)|\n\n### 🎩 License\nLGPLv3 license. [Made by Humans from OpenPeeps](https://github.com/openpeeps).\u003cbr\u003e\nCopyright OpenPeeps \u0026 Contributors \u0026mdash; All rights reserved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenpeeps%2Fsweetsyntax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenpeeps%2Fsweetsyntax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenpeeps%2Fsweetsyntax/lists"}