{"id":21980477,"url":"https://github.com/profburke/cfg","last_synced_at":"2025-06-17T16:38:06.355Z","repository":{"id":151146371,"uuid":"268344717","full_name":"profburke/cfg","owner":"profburke","description":"Context-free Grammar library for Swift","archived":false,"fork":false,"pushed_at":"2020-05-31T19:14:21.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-28T04:28:25.200Z","etag":null,"topics":["context-free-grammar","generative-text","swift","swift-package"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/profburke.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}},"created_at":"2020-05-31T19:00:29.000Z","updated_at":"2020-05-31T19:14:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"1b136b96-c14c-49ac-bb07-c1d06f03a96e","html_url":"https://github.com/profburke/cfg","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profburke%2Fcfg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profburke%2Fcfg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profburke%2Fcfg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profburke%2Fcfg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/profburke","download_url":"https://codeload.github.com/profburke/cfg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245040690,"owners_count":20551308,"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":["context-free-grammar","generative-text","swift","swift-package"],"created_at":"2024-11-29T17:11:28.882Z","updated_at":"2025-03-23T01:15:00.209Z","avatar_url":"https://github.com/profburke.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"## CFG\n\nThis package is a simple implementation of library to use Context-free Grammars to generate text. It is\na re-incarnation of code I originally wrote in 2015 and is still in a very rough state. At this point, basically\nall that I have done is made changes so that it would compile under 5.x Swift.\n\nThere are a number of design decisions from the original code whose intent I no longer remember.\nI recently attended !!Con 2020 and through talks there learned about BlurML and Tracery. I may\ntry and incorporate some of the ideas from those projects; particularly Tracery's applicability to more\nthan just text generation. However, my primary motivation in resurrecting this code is that I plan to\nuse it in a couple of specific projects. This should hopefully help me pin down some of the design\nissues I'm struggling with and I'll back-port improvements from those projects to here.\n\n### Installation\n\nModify your Package.swift file to include CFG as a dependency:\n\n```swift\n.package(url: \"https://github.com/profburke/cfg.git\", from: \"0.1.0\")\n```\n*NOTE: Although I will try to keep this README file up to date, you may need to update the version number\nfrom the above. Check the tags on the github repo for the latest version.*\n\nYou need to also include \"CFG\" in your list of target dependencies.\n\n### Example\n\n```swift\nimport CFG\n\n// Define terminals and nonterminals:\n\nlet START: Nonterminal = \"START\"\nlet HOWNOW: Terminal = \"How now\"\nlet ADJECTIVES: Nonterminal = \"ADJECTIVES\"\nlet ADJECTIVE: Nonterminal = \"ADJECTIVE\"\nlet MAMMAL: Nonterminal = \"MAMMAL\"\n\n// Define production rules. Note the use of the `T` helper method for incidental terminals:\n\nlet rules = Set\u003cRule\u003e([\n    START --\u003e [HOWNOW, T(\", \"), ADJECTIVES, T(\" \"), MAMMAL, T(\".\")],\n\n    ADJECTIVES --\u003e [ADJECTIVES, T(\", \"), ADJECTIVE] ||| [ADJECTIVE],\n\n    ADJECTIVE --\u003e [T(\"brown\")] ||| [T(\"big\")] ||| [T(\"scary\")],\n\n    MAMMAL --\u003e [T(\"cow\")] ||| [T(\"wolf\")] ||| [T(\"bear\")]\n])\n\nlet grammar = Grammar(rules: rules, start: START)\n\nfor _ in 0..\u003c10 {\n    let derivation = Derivation(start: [START], grammar: grammar)\n\n    while !derivation.isComplete() {\n        derivation.step()\n    }\n\n    print(derivation.result ?? \"no result\")\n}\n```\n\n\n### Contributions\n\nContributions are welcome. And if you do contribute, thank you for your time and effort!\n\nThere are many ways to contribute in addition to submitting code. Bug reports, feature suggestions, a logo for the project, and improvements to documentation are all appreciated.\n\n##### Bug Reports and Feature Suggestions\n\nPlease submit bug reports and feature suggestions by creating a [new issue](https://github.com/profburke/cfg/issues/new). If possible, look for an existing [open issue](https://github.com/profburke/bgurt/issues) that is related and comment on it.\n\nWhen creating an issue, the more detail, the better. For bug reports in partciular, try to include at least the following information:\n\n* The application version\n* The operating system (macOS, Windows, etc) and version\n* The expected behavior\n* The observed behavior\n* Step-by-step instructions for reproducing the bug\n\n\n##### Pull Requests\n\nEnsure the PR description clearly describes the problem and solution. It should include the relevant issue number, if applicable.\n\n\n##### Documentation Improvements\n\nPreferably, submit documentation changes by pull request. However, feel free to post your changes to an [issue](https://github.com/profburke/cfg/issues/new) or send them to the project team.\n\nIt would be nice to have a site for this project that we could host on Github Pages. If you have an interest in helping build that, please let me know.\n\n\n### License\n\nThis project is licensed under the BSD 3-Clause License. For details, please read the [LICENSE](https://github.com/profburke/cfg/blob/master/LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofburke%2Fcfg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprofburke%2Fcfg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofburke%2Fcfg/lists"}