{"id":17922632,"url":"https://github.com/rreverser/derex","last_synced_at":"2025-09-21T03:31:08.460Z","repository":{"id":66153391,"uuid":"104873383","full_name":"RReverser/derex","owner":"RReverser","description":"Derivatives-based regexp to DFA compiler","archived":false,"fork":false,"pushed_at":"2018-05-10T11:52:05.000Z","size":24,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T20:09:28.899Z","etag":null,"topics":["dfa","dfa-regex","parser-generator","parsing","regex","regex-engine","regexp"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/RReverser.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":"2017-09-26T10:56:15.000Z","updated_at":"2024-05-31T16:53:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"753cfe8f-a30e-4ba2-9ea3-70ad1006a8cc","html_url":"https://github.com/RReverser/derex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RReverser/derex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fderex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fderex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fderex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fderex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RReverser","download_url":"https://codeload.github.com/RReverser/derex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fderex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276189890,"owners_count":25600281,"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","status":"online","status_checked_at":"2025-09-21T02:00:07.055Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["dfa","dfa-regex","parser-generator","parsing","regex","regex-engine","regexp"],"created_at":"2024-10-28T20:40:04.055Z","updated_at":"2025-09-21T03:31:08.234Z","avatar_url":"https://github.com/RReverser.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# derex\n\u003e Derivatives-based regexp to DFA compiler\n\nThis is a toy project to learn and investigate the alternative approach to building DFA from regular expressions that uses regular expression derivatives instead of NFA as an intermediate representation.\n\nIt uses Immutable.js to easily maintain certain invariants required by the approach (see https://www.cs.kent.ac.uk/people/staff/sao/documents/jfp09.pdf for more details).\n\nContents:\n\n - `re.ts`: factory functions for actual regular expressions (with some optimizations required by the approach and a bit more)\n - `derivatives.ts`: takes a regular expression and returns a `Derivatives` object with regexp =\u003e character classes mappings.\n - `dfa.ts`: takes a regular expression and recursively takes derivatives over all possible character classes to obtain a DFA.\n - `codegen.ts`: takes a DFA and generates a pure function that can return the next state based on previous one and a char code.\n - `tests.ts`: simple tests (incomplete)\n - `index.ts`: reexports everything from `re`, `dfa` and `codegen` modules\n\n------\n\nFor example, the following regular expression:\n\n```js\nlet sampleRe = or(\n\tconcat(chars('a'), chars('c'), chars('1')),\n\tconcat(chars('a'), chars('d'), chars('1')),\n\tconcat(kleene(chars('b')), chars('1'))\n);\n```\n\nproduces a following function:\n\n```js\nfunction nextState(state, char) {\n    switch (state) {\n    case 2:\n        switch (char) {\n        case 49    /* \"1\" */:\n            return -2;    // success\n        default:\n            return -1;    // error\n        }\n    case 1:\n        switch (char) {\n        case 100    /* \"d\" */:\n        case 99    /* \"c\" */:\n            return 2;\n        default:\n            return -1;    // error\n        }\n    case 3:\n        switch (char) {\n        case 98    /* \"b\" */:\n            return 3;\n        case 49    /* \"1\" */:\n            return -2;    // success\n        default:\n            return -1;    // error\n        }\n    case 0:\n        switch (char) {\n        case 97    /* \"a\" */:\n            return 1;\n        case 98    /* \"b\" */:\n            return 3;\n        case 49    /* \"1\" */:\n            return -2;    // success\n        default:\n            return -1;    // error\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frreverser%2Fderex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frreverser%2Fderex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frreverser%2Fderex/lists"}