{"id":15882909,"url":"https://github.com/tcr/parser-c","last_synced_at":"2025-09-07T12:33:45.355Z","repository":{"id":57653134,"uuid":"95401952","full_name":"tcr/parser-c","owner":"tcr","description":"Haskell's language-c ported to Rust.","archived":false,"fork":false,"pushed_at":"2018-04-04T12:36:46.000Z","size":4166,"stargazers_count":31,"open_issues_count":8,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-24T06:40:01.182Z","etag":null,"topics":["c","haskell-language","parse","rust"],"latest_commit_sha":null,"homepage":"http://docs.rs/parser-c","language":"Rust","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/tcr.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}},"created_at":"2017-06-26T02:48:00.000Z","updated_at":"2024-10-28T09:01:37.000Z","dependencies_parsed_at":"2022-08-31T23:02:23.189Z","dependency_job_id":null,"html_url":"https://github.com/tcr/parser-c","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/tcr%2Fparser-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcr%2Fparser-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcr%2Fparser-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcr%2Fparser-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tcr","download_url":"https://codeload.github.com/tcr/parser-c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232213530,"owners_count":18489550,"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":["c","haskell-language","parse","rust"],"created_at":"2024-10-06T04:07:41.269Z","updated_at":"2025-01-02T15:16:25.303Z","avatar_url":"https://github.com/tcr.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parser-c\n\n[![Gitter](https://img.shields.io/gitter/room/tcr/parser-c.svg)](http://gitter.im/parser-c/Lobby) [![https://img.shields.io/crates/v/parser-c.svg](https://img.shields.io/crates/v/parser-c.svg)](http://crates.io/crates/parser-c/)\n\nRust module for parsing C code. Port of Haskell's [language-c](https://github.com/visq/language-c), semi-automatically translated using [Corollary](https://github.com/tcr/corrode-but-in-rust).\n\n**This port is a work in progress.** A lot of work remains to parse anything but very simple C files; while most source code has been translated from Haskell, errors in translation prevent it from matching language-c's functionality yet. Here are the next steps for achieving parity, in order:\n\n1. Building up an equivalent test bed to language-c's, then automatically cross-check\n1. Fix errors in the ported code to support those test cases\n1. Converting portions of the code into Rust idioms without breaking tests\n1. Figure out a porting story for the alex/happy generated parser output\n\n`parser-c` requires nightly (for now). See `tests/` for some working examples, or try this example:\n\n```rust\nextern crate parser_c;\n\nuse parser_c::parse;\n\nconst INPUT: \u0026'static str = r#\"\n\nint main() {\n    printf(\"hello world!\\n\");\n    return 0;\n}\n\n\"#;\n\nfn main() {\n    match parse(INPUT, \"simple.c\") {\n        Err(err) =\u003e {\n            panic!(\"error: {}\", err);\n        }\n        Ok(ast) =\u003e {\n            println!(\"success: {:#?}\", ast);\n        }\n    }\n}\n```\n\nResult is:\n\n```\nsuccess: Right(\n    CTranslationUnit(\n        [\n            CFDefExt(\n                CFunctionDef(\n                    [\n                        CTypeSpec(\n                            CIntType(\n                                ..\n                            )\n                        )\n                    ],\n                    CDeclarator(\n                        Some(\n                            Ident(\n                                \"main\",\n                                124382170,\n                                ..\n                            )\n                        ),\n                        ...\n```\n\n## Development\n\nClone this crate:\n\n```\ngit clone https://github.com/tcr/parser-c --init --recursive\n```\n\nHacking on the lexer and parser requires to build and run the Haskell\ndependencies using:\n\n```\n./regen.sh\n```\n\nThe test suite is being ported at the moment.  It is in a separate crate,\nbecause it requires a build script with prerequisites, so to run it, use\nthis script:\n\n```\n./test.sh\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcr%2Fparser-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftcr%2Fparser-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcr%2Fparser-c/lists"}