{"id":29470108,"url":"https://github.com/unlomtrois/zlr","last_synced_at":"2025-07-14T12:02:36.951Z","repository":{"id":301235052,"uuid":"1008598774","full_name":"unLomTrois/zlr","owner":"unLomTrois","description":" LR parser generator for Zig","archived":false,"fork":false,"pushed_at":"2025-07-03T19:40:35.000Z","size":70,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-03T19:44:32.787Z","etag":null,"topics":["lr-parser","lr0","parser-generator","zig","zig-library"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/unLomTrois.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,"zenodo":null}},"created_at":"2025-06-25T19:49:33.000Z","updated_at":"2025-07-03T19:40:38.000Z","dependencies_parsed_at":"2025-06-25T21:20:18.711Z","dependency_job_id":null,"html_url":"https://github.com/unLomTrois/zlr","commit_stats":null,"previous_names":["unlomtrois/zlr"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/unLomTrois/zlr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unLomTrois%2Fzlr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unLomTrois%2Fzlr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unLomTrois%2Fzlr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unLomTrois%2Fzlr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unLomTrois","download_url":"https://codeload.github.com/unLomTrois/zlr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unLomTrois%2Fzlr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265288506,"owners_count":23741197,"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":["lr-parser","lr0","parser-generator","zig","zig-library"],"created_at":"2025-07-14T12:01:21.941Z","updated_at":"2025-07-14T12:02:36.937Z","avatar_url":"https://github.com/unLomTrois.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZLR - LR parser generator written in Zig\n\nThe goal is to build LR parsers generator like yacc or bison from scratch.\n\n## Intended Use\n\nZLR is designed around a clean separation between lexical analysis and parsing. The workflow is:\n\n1. **Define your grammar in Zig** - Grammars are defined as Zig data structures using `StaticGrammar.from()`\n2. **Write a custom lexer** - Your lexer emits terminal symbols from the grammar and implements a `nextToken()` method\n3. **Build a parser** - Use `Parser.init(grammar)` to create a parser from your grammar definition\n4. **Parse with your lexer** - The `parse()` method accepts any struct with `nextToken()` that returns lightweight tokens\n\nTokens are simple structs containing:\n- `type`: The terminal symbol from your grammar (converted to enums in generated code)\n- `loc`: Source location with `start` and `end` positions as `usize`\n\nYou can use the parser at runtime for development, or **codegen** it into a self-contained, zero-dependency file for production.\n\n```zig\nconst zlr = @import(\"zlr\");\nconst Symbol = zlr.Symbol;\nconst Rule = zlr.Rule;\nconst StaticGrammar = zlr.StaticGrammar;\nconst Token = zlr.Token;\n\n// Define grammar in Zig\nconst id = Symbol.from(\"id\");\nconst plus = Symbol.from(\"+\");\nconst lparen = Symbol.from(\"(\");\nconst rparen = Symbol.from(\")\");\nconst cycle = Symbol.from(\"cycle\");\nconst factor = Symbol.from(\"factor\");\n\nconst terminals = \u0026.{id, plus, lparen, rparen};\nconst non_terminals = \u0026.{cycle, factor};\n\nconst my_grammar = StaticGrammar.from(cycle, terminals, non_terminals, \u0026.{\n    Rule.from(cycle, \u0026.{id, plus, id}), // cycle -\u003e id + id\n    Rule.from(cycle, \u0026.{factor}), // cycle -\u003e factor\n    Rule.from(factor, \u0026.{lparen, cycle, rparen}), // factor -\u003e ( cycle )\n    Rule.from(factor, \u0026.{id}), // factor -\u003e id\n});\n\n// Your custom lexer\nconst MyLexer = struct {\n    pub fn nextToken(self: *MyLexer) Token { /* your tokenization logic */ }\n};\n\n// Pick your parser type:\nconst Parser = @import(\"zlr/x/parser.zig\").Parser; // x = lr0/slr/lr1/lalr\n\n// Build and use parser\nconst parser = Parser.init(my_grammar);\ntry parser.validate(); // the grammar may be ambiguous for some parsers, so validate it\ntry parser.build(); // build state machine, parse tables, etc\n\nconst input = \"((1 + 2) + 3)\";\n\nconst parse_result = try parser.parse(input, \u0026my_lexer);\n\nconst ast = parse_result.ast;\n\n// OR: Generate self-contained parser with pre-built state machine, tables, etc\ntry parser.codegen(\"my_parser.zig\");\n```\n\nTODO:\n- [x] Grammar primitives: symbols, rules, grammar\n- [x] LR(0) automata builder - build states from grammar\n- [x] Fix transitions\n- [x] Validate whether certain grammar is LR(0) grammar\n- [ ] AST primitieves: Nodes\n- [ ] LR(0) table parser\n- [ ] SLR automata parser\n- [ ] LR(1) automata \u0026 parser\n- [ ] LALR(1) automata \u0026 parser","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funlomtrois%2Fzlr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funlomtrois%2Fzlr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funlomtrois%2Fzlr/lists"}