{"id":15668313,"url":"https://github.com/devstopfix/regex_spec","last_synced_at":"2025-10-15T06:56:41.546Z","repository":{"id":57542746,"uuid":"327273503","full_name":"devstopfix/regex_spec","owner":"devstopfix","description":"Regular Expression specification compiler for Elixir","archived":false,"fork":false,"pushed_at":"2021-02-07T10:33:28.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T06:49:13.267Z","etag":null,"topics":["elixir-library","typespec"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/devstopfix.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}},"created_at":"2021-01-06T10:14:51.000Z","updated_at":"2021-02-10T10:43:33.000Z","dependencies_parsed_at":"2022-09-26T18:31:20.445Z","dependency_job_id":null,"html_url":"https://github.com/devstopfix/regex_spec","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/devstopfix%2Fregex_spec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devstopfix%2Fregex_spec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devstopfix%2Fregex_spec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devstopfix%2Fregex_spec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devstopfix","download_url":"https://codeload.github.com/devstopfix/regex_spec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246277352,"owners_count":20751548,"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":["elixir-library","typespec"],"created_at":"2024-10-03T14:08:01.856Z","updated_at":"2025-10-15T06:56:41.461Z","avatar_url":"https://github.com/devstopfix.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Regex.Spec\n\nGenerates [type specifications][1] for [Regular Expressions][2] at compile time allowing [Dialyzer][dialyzer] to detect type errors.\n\n[![Build Status](https://github.com/devstopfix/regex_spec/workflows/ci/badge.svg)](https://github.com/devstopfix/regex_spec/actions)\n[![Hex.pm](https://img.shields.io/hexpm/v/regex_spec.svg?style=flat-square)](https://hex.pm/packages/regex_spec)\n\nThis library is a **work in progress** that was inspired by [Stephanie Weirich][sweirich]'s talk [Dependent Types in Haskell at Strange Loop 2017][talk]. The design is evolving based on the constraints imposed by Elixir:\n\n1. we cannot specify a list of n elements, so we need to return a tuple\n2. we use `String.t() | nil` to represent a maybe type based on a `(...)?` pattern\n3. we generate a map of results with optional and required keys for named captures\n4. can we pass in a list of [parse][parsei] functions that can be applied to the matches and modify the return type e.g. from `String.t() -\u003e integer()`\n\nThis library generates the common [Regex][2] functions for your \nregular expression with a type spec. Create a module for your type\nand use:\n\n```elixir\ndefmodule MyApp do\n\n  defmodule MMYYDDDD do\n    use Regex.Spec, regex: ~r/(\\d{2})\\-(\\d{2})\\-(\\d{4})/\n  end\n\n  IO.inspect(MMYYDDDD.matches?(\"2020-12-31\")) # false\n  IO.inspect(MMYYDDDD.run(\"12-31-2020\")) # [\"12-31-2020\", \"12\", \"31\", \"2020\"]\n  IO.inspect(MMYYDDDD.runt(\"12-31-2020\")) # {\"12-31-2020\", \"12\", \"31\", \"2020\"}\n\nend\n```\n\nThe specification for [run/3][run] is a list of Strings, and we cannot specify a \n[dependent type such as a list of length 4][dep]. Therefore we implement the \nnormal `run` function and also `runt` which can be read as *run typed* or *run tuple*\nwhich returns a typed tuple.\n\n## Installation\n\nThis library is incomplete, but you can append to your mix.exs deps:\n\n```elixir\n    {:regex_spec, \"~\u003e 0.21\"}\n```\n\n## Design\n\nThis library uses [leex][leex] and [yecc][yecc] to compile your regular expression into a tree of capture groups and then into a Dialyzer tuple type specification.\n\nThe docs can be found at [https://hexdocs.pm/regex_spec](https://hexdocs.pm/regex_spec).\n\n[1]: https://hexdocs.pm/elixir/typespecs.html\n[2]: https://hexdocs.pm/elixir/Regex.html\n[leex]: https://erlang.org/doc/man/leex.html\n[yecc]: https://erlang.org/doc/man/yecc.html\n[run]: https://hexdocs.pm/elixir/Regex.html#run/3\n[dep]: https://en.wikipedia.org/wiki/Dependent_type\n[talk]: https://www.youtube.com/watch?v=wNa3MMbhwS4\n[dialyzer]: https://erlang.org/doc/man/dialyzer.html\n[sweirich]: https://github.com/sweirich\n[parsei]: https://hexdocs.pm/elixir/Integer.html#parse/2","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevstopfix%2Fregex_spec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevstopfix%2Fregex_spec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevstopfix%2Fregex_spec/lists"}