{"id":18463905,"url":"https://github.com/vimpunk/degenerexp","last_synced_at":"2025-04-28T13:36:40.334Z","repository":{"id":117061844,"uuid":"139480647","full_name":"vimpunk/degenerexp","owner":"vimpunk","description":":sparkles: A toy regex engine built for enlightenment","archived":false,"fork":false,"pushed_at":"2018-09-09T09:09:00.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-16T16:58:06.692Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","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/vimpunk.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}},"created_at":"2018-07-02T18:38:27.000Z","updated_at":"2024-04-10T04:02:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"bac2b385-b893-40c5-89ab-130bce1f7ccc","html_url":"https://github.com/vimpunk/degenerexp","commit_stats":null,"previous_names":["vimpunk/degenerexp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimpunk%2Fdegenerexp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimpunk%2Fdegenerexp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimpunk%2Fdegenerexp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimpunk%2Fdegenerexp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vimpunk","download_url":"https://codeload.github.com/vimpunk/degenerexp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251320604,"owners_count":21570601,"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":[],"created_at":"2024-11-06T09:08:20.258Z","updated_at":"2025-04-28T13:36:40.298Z","avatar_url":"https://github.com/vimpunk.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# degenerexp\n\nSo this is a pretty lousy regex engine and the only thing special about it is that it's *mine* (incidentally, I believe that's exactly what my\nparents used to say about me, but I digress).\n\nIt has not been optimized at all, for the project's sole purpose was, from the outset, to attain\n*enlightenment*--which, I am delighted to report, was achieved. This means I will no longer spend any more time on GitHub (and no, not because Microsoft bought GitHub ~~and it will ruin it like all the other things it bought~~)\nfor I shall be sitting on top of a distant mountain reveling in the sheer overwhelming beauty of life. And all it took to arrive\nat this state was to write a shoddy regular expression engine!\n\nI trust it goes without saying that it should not be used in production.\n\n## Regex syntax\n\ndegenerexp may be somewhat, ah, *behind* its peers, but it still ~~deserves your love~~ supports a subset of modern regular\nexpression engines' syntax, which is the following:\n\n- `?` matches the preceding item at most once;\n- `*` matches the preceding item zero or more times;\n- `+` matches the previous item one or more times;\n- `|` two regular expressions may be joined by this infix operator and the resulting regular expression matches any string matching one of the expressions; \n- `()` parentheses may be used to deliniate regular expressions into a single item for the preceding operators to act on\n\nE.g.: `(ab|c)*de?` is a valid regular expression that even degenerexp can handle ~~given enough emotional support~~.\n\n## How it works\n\nIt uses Dijkstra's shunting-yard algorithm modified to handle regular expressions which in turn uses Thompson's construction\nto incrementally build a nondeterministic finite automaton (NFA). Then, subset construction is employed to turn the\nNFA into a deterministic finite automaton (DFA). Finally, input strings are matched against this DFA.\n\n```c++\nconst auto input = \"abababde\";\nconst auto regex = \"(ab|c)*de\";\nfsm::nfa nfa = parser::shunting_yard_nfa_parser(regex).parse();\nfsm::dfa dfa(nfa, fsm::derive_input_language(input));\nif(dfa.simulate(input) == fsm::result::accept) {\n    std::cout \u003c\u003c input \u003c\u003c \" matches the regex '\" \u003c\u003c regex \u003c\u003c \"'!\\n\";\n}\n```\n\nIt still needs a higher level wrapper that takes care of these steps, ~~but why bother once enlightenment has been reached?~~ so nominally it's still not finished.\n\n## Resources\n\nI used the following resources to build degenerexp:\n- https://www.gamedev.net/articles/programming/general-and-gameplay-programming/finite-state-machines-and-regular-expressions-r3176\n- https://en.wikipedia.org/wiki/Shunting-yard_algorithm\n- https://en.wikipedia.org/wiki/Thompson%27s_construction\n- http://www.cs.nuim.ie/~jpower/Courses/Previous/parsing/node9.html\n- http://condor.depaul.edu/glancast/444class/docs/nfa2dfa.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimpunk%2Fdegenerexp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvimpunk%2Fdegenerexp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimpunk%2Fdegenerexp/lists"}