{"id":13648736,"url":"https://github.com/jiegec/gll-pg","last_synced_at":"2025-04-21T23:31:36.022Z","repository":{"id":57633903,"uuid":"221171099","full_name":"jiegec/gll-pg","owner":"jiegec","description":"A GLL parser generator, inspired by MashPlant/lalr1.","archived":false,"fork":false,"pushed_at":"2023-11-11T15:28:52.000Z","size":89,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-28T23:04:17.126Z","etag":null,"topics":["parser-generator","rust","rust-macro"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/jiegec.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}},"created_at":"2019-11-12T08:47:20.000Z","updated_at":"2023-08-25T12:47:12.000Z","dependencies_parsed_at":"2024-01-14T10:59:35.362Z","dependency_job_id":"3e235386-1ba7-41f1-a665-d17440fb7616","html_url":"https://github.com/jiegec/gll-pg","commit_stats":{"total_commits":45,"total_committers":2,"mean_commits":22.5,"dds":0.1333333333333333,"last_synced_commit":"0b83b4df6afda05beb1cb23f53972026ed3b5778"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiegec%2Fgll-pg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiegec%2Fgll-pg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiegec%2Fgll-pg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiegec%2Fgll-pg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jiegec","download_url":"https://codeload.github.com/jiegec/gll-pg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223881649,"owners_count":17219268,"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":["parser-generator","rust","rust-macro"],"created_at":"2024-08-02T01:04:29.693Z","updated_at":"2024-11-09T21:02:22.678Z","avatar_url":"https://github.com/jiegec.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# gll-pg\n\nA Parser Generator for GLL parser. It uses Logos as lexer.\n\n## Usage\n\nAdd to Cargo.toml:\n\n```toml\n[dependencies]\ngll-pg-macros = \"0.2\"\ngll-pg-core = \"0.2\"\nlogos = \"0.9\"\n```\n\nWrite a lexer using Logos:\n\n```rust\nuse logos::Logos;\n\n#[derive(Logos, Debug, Eq, PartialEq, Clone)]\npub enum Token {\n    End, // must not change this\n    #[error]\n    Error,\n    #[token(\" \")]\n    _Eps, // must not change this, will be skipped\n    #[token(\"a\")]\n    Ta,\n}\n```\n\nUse gll-pg to generate parser:\n\n```rust\nstruct Parser {}\n\n#[gll(S, Token)]\nimpl Parser {\n    #[rule(S -\u003e S Ta)]\n    fn s1(s: \u0026usize, _a: \u0026LogosToken\u003cToken\u003e) -\u003e usize {\n        *s + 1\n    }\n    #[rule(S -\u003e)]\n    fn s2() -\u003e usize {\n        0\n    }\n}\n```\n\nRun it:\n\n```rust\nlet mut lexer = Token::lexer(\"aaa\");\nlet mut parser = Parser {};\nlet res = parser.parse(\u0026mut lexer).unwrap();\n// res is a StreamingIterator\nlet vec: Vec\u003cusize\u003e = res.cloned().collect();\nassert_eq!(res, vec![3]);\n```\n\n## Example\n\n### Ambiguous Calculator\n\nFor the grammar below:\n\n```\nE -\u003e E + E\nE -\u003e E * E\nE -\u003e - E\nE -\u003e ( E )\nE -\u003e int\n```\n\nFor input \"1 + 2 \\* 3\", it gives [7, 9].\nFor input \"1 + (2 \\* -3)\", it gives [-5].\n\nSee `tests/src/arith.rs` for detail.\n\n### Recursive\n\nIt can handle recursive grammars:\n\n```\nS -\u003e a\nS -\u003e S S\nS -\u003e S S S\n```\n\nCode snippet:\n\n```rust\n#[gll(S, Token)]\nimpl Parser {\n    #[rule(S -\u003e Ta)]\n    fn s1(_a: \u0026LogosToken\u003cToken\u003e) -\u003e usize {\n        1\n    }\n    #[rule(S -\u003e S S)]\n    fn s2(s1: \u0026usize, s2: \u0026usize) -\u003e usize {\n        s1 + s2\n    }\n    #[rule(S -\u003e S S S)]\n    fn s3(s1: \u0026usize, s2: \u0026usize, s3: \u0026usize) -\u003e usize {\n        s1 + s2 + s3\n    }\n}\n\n// \"\" gives []\n// \"a\" gives [1]\n// \"aa\" gives [2]\n// \"aaa\" gives [3,3,3]\n// \"aaaa\" gives [4, 4, 4, 4, 4, 4, 4, 4, 4]\n```\n\nSee `tests/src/crazy.rs` for detail.\n\n## Changelog\n\n### Release 0.4.0 2021-01-17\n\n1. Migrate to Logos v0.11.\n\n### Release 0.3.0 2019-11-15\n\n1. Return a struct that impls StreamingIterator to give derivations lazily.\n2. Implement memoization for shared structure of derivations.\n3. Turn all clone calls to reference to arena objects.\n4. Implement diagnostics to catch type mismatch errors.\n5. Make errors in user code reported with correct line numbers.\n\n### Release 0.2.1 2019-11-13\n\n1. Improve documentation.\n\n### Release 0.2.0 2019-11-13\n\n1. Allow access to struct fields.\n\n### Release 0.1.0 2019-11-12\n\n1. Initial working version.\n2. The parser recursively clone \u0026 collect all possible derivations.\n\n## References\n\n1. Code generation and template is learned from `MashPlant/lalr1`.\n2. Scott, E., \u0026 Johnstone, A. (2010). GLL parsing. Electronic Notes in Theoretical Computer Science, 253(7), 177-189.\n3. Scott, E., \u0026 Johnstone, A. (2013). GLL parse-tree generation. Science of Computer Programming, 78(10), 1828-1844.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiegec%2Fgll-pg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjiegec%2Fgll-pg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiegec%2Fgll-pg/lists"}