{"id":13748991,"url":"https://github.com/robbepop/cnf-parser","last_synced_at":"2025-12-27T01:40:33.770Z","repository":{"id":57606920,"uuid":"280921006","full_name":"Robbepop/cnf-parser","owner":"Robbepop","description":"Efficient and customizable CNF parser for SAT solving.","archived":false,"fork":false,"pushed_at":"2020-07-26T21:05:36.000Z","size":29,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-05T21:16:19.284Z","etag":null,"topics":["cnf-clauses","parser","sat-solver"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Robbepop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-19T17:56:24.000Z","updated_at":"2022-03-27T07:10:06.000Z","dependencies_parsed_at":"2022-08-30T00:00:51.667Z","dependency_job_id":null,"html_url":"https://github.com/Robbepop/cnf-parser","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/Robbepop%2Fcnf-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robbepop%2Fcnf-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robbepop%2Fcnf-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robbepop%2Fcnf-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Robbepop","download_url":"https://codeload.github.com/Robbepop/cnf-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253240350,"owners_count":21876593,"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":["cnf-clauses","parser","sat-solver"],"created_at":"2024-08-03T07:00:53.652Z","updated_at":"2025-12-27T01:40:33.742Z","avatar_url":"https://github.com/Robbepop.png","language":"Rust","funding_links":[],"categories":["Projects"],"sub_categories":["Libraries"],"readme":"# CNF Parser\n\n| Continuous Integration |  Documentation   |       Crates.io      |\n|:----------------------:|:----------------:|:--------------------:|\n| [![CI][1]][2]          | [![docs][3]][4] | [![crates][5]][6]  |\n\nAn efficient and customizable parser for the [`.cnf` (Conjunctive Normal Form)][cnf-format]\nfile format used by [SAT solvers][sat-solving].\n\n- No `unsafe` Rust!\n- No dependencies!\n- No heap allocations while parsing!\n- `no_std` compatible!\n\n## Usage\n\nFor parsing use the `parse_cnf` function.\nIt requires some input source that is expected to be `.cnf` encoded as well\nas a `\u0026mut` to a customizable output.\nThis output needs to implement the `Output` trait and is most probably your solver\nor something that initializes your solver from the given `.cnf` input.\n\n### Example\n\nIn order to use `parse_cnf` you first have to define your own `Output` type:\n\n```rust\n#[derive(Default)]\npub struct MyOutput {\n    head_clause: Vec\u003cLiteral\u003e,\n    clauses: Vec\u003cVec\u003cLiteral\u003e\u003e,\n}\n\nimpl Output for MyOutput {\n    type Error = \u0026'static str;\n\n    fn problem(\n        \u0026mut self, num_variables: u32, num_clauses: u32\n    ) -\u003e Result\u003c(), Self::Error\u003e {\n        Ok(())\n    }\n\n    fn literal(\u0026mut self, literal: Literal) -\u003e Result\u003c(), Self::Error\u003e {\n        self.head_clause.push(literal); Ok(())\n    }\n\n    fn finalize_clause(\u0026mut self) -\u003e Result\u003c(), Self::Error\u003e {\n        if self.head_clause.is_empty() {\n            return Err(\"encountered empty clause\")\n        }\n        self.clauses.push(\n            core::mem::replace(\u0026mut self.head_clause, Vec::new())\n        );\n        Ok(())\n    }\n\n    fn finish(\u0026mut self) -\u003e Result\u003c(), Self::Error\u003e {\n        if !self.head_clause.is_empty() {\n            self.finalize_clause()?\n        }\n        Ok(())\n    }\n}\n```\n\nThen use `parse_cnf` as follows:\n\n```rust\nlet my_input: \u0026[u8] = br\"\n    c This is my input .cnf file with 3 variables and 2 clauses.\n    p cnf 3 2\n    1 -2 3 0\n    1 -3 0\n\";\nlet mut my_output = MyOutput::default();\ncnf_parser::parse_cnf(\u0026mut my_input.as_ref(), \u0026mut my_output)\n    .expect(\"encountered invalid .cnf input\");\n```\n\n## License\n\nLicensed under either of\n\n * Apache license, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Dual licence: [![badge][license-mit-badge]](LICENSE-MIT) [![badge][license-apache-badge]](LICENSE-APACHE)\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any\nadditional terms or conditions.\n\n[1]: https://github.com/Robbepop/cnf-parser/workflows/Rust%20-%20Continuous%20Integration/badge.svg?branch=master\n[2]: https://github.com/Robbepop/cnf-parser/actions?query=workflow%3A%22Rust+-+Continuous+Integration%22+branch%3Amaster\n[3]: https://docs.rs/cnf-parser/badge.svg\n[4]: https://docs.rs/cnf-parser\n[5]: https://img.shields.io/crates/v/cnf-parser.svg\n[6]: https://crates.io/crates/cnf-parser\n\n[sat-solving]: https://en.wikipedia.org/wiki/Boolean_satisfiability_problem\n[cnf-format]: https://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/index-seo.php/SATLINK____DIMACS\n\n[license-mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[license-apache-badge]: https://img.shields.io/badge/license-APACHE-orange.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobbepop%2Fcnf-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobbepop%2Fcnf-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobbepop%2Fcnf-parser/lists"}